i was jus trying to crete a form and if i submit the form the values should be displayed in the browser.
code is:
html file-

[/U]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="firstjsp.jsp" method="get">

<table>
<tr><td><b>Name</b>
    <td><input type="text" name="name">

<tr><td><b>age</b>
    <td><input type="text" name="color">
</table>

<tr><td><b>address</b>
    <td><input type="text" name="address">
</table>

<input type="submit" value="Send">

</form>



</body>
</html>

jsp file-

<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="CSS/style.css" rel="stylesheet" type="text/css" />
<link href="CSS/tableStyle.css" rel="stylesheet" type="text/css" />
</head>

<body>



<table width="200" border="2" cellspacing="1">
  <tr>
    <td>Name:</td>
    <td><%= request.getParameter("name") %></td>
  </tr>
  <tr>
    <td>age:</td>
    <td><%= request.getParameter("color") %></td>
  </tr>
  <tr>
    <td>adds:</td>
    <td><%=request.getParameter("address") %></td>
  </tr>
</table>
</body>
</html>

code above would do that.

now the question is:
i want the form and the display of the entries should come one the same page?
wat should i use?
will ter b a role of scriplets for this?

Dani AI

Generated

wanted the form and the results to appear on the same page; correctly suggested a self-posting approach and checking for submitted parameters. That will work, but the original markup has a few practical problems (mismatched field names and malformed table tags) and the thread uses scriptlets — a pattern worth replacing with simpler, safer techniques.

A concise, modern quick-fix (single JSP, no scriptlets) is to use JSP Expression Language and JSTL to detect submission and safely print parameters. Example pattern:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<form action="" method="post">
  <!-- form fields (ensure each input has the correct name, e.g. name="age") -->
  <input type="submit" name="submitted" value="Send">
</form>

<c:if test="${not empty param.submitted}">
  <table>
    <tr><td>Name:</td><td><c:out value="${param.name}"/></td></tr>
    <tr><td>Age:</td><td><c:out value="${param.age}"/></td></tr>
    <tr><td>Address:</td><td><c:out value="${param.address}"/></td></tr>
  </table>
</c:if>

Longer-term best practice is to separate controller logic from the view: post to a servlet that validates input, sets request attributes, then forwards to a JSP for rendering. This keeps JSPs free of Java code and makes validation, error handling, and testing easier. Example controller sketch:

// inside doPost(...)
String name = /* read and validate params */;
req.setAttribute("name", name);
req.getRequestDispatcher("/form.jsp").forward(req, resp);

Housekeeping notes drawn from the original posts: make sure each input's name matches the key read on the server (the "age" field was named "color" in the sample), fix malformed table/tr tags, prefer POST for submissions that change state or include personal data, and always escape output (shown above with <c:out>) to avoid XSS.

You can have the action of the form be the same page. Like: <form action="" method="get"> The submit tag should be like this: <input type="submit" value="Send" name="submitTag" > Then at the same page; you can write that code wherever you want:

String name = request.getParameter("name");
....
String submit = request.getParameter("submitTag");

And at the place that you want to display your data:

<%
if (submitTag!=null) {
%>

<tr>
    <td>Name:</td>
    <td><%= name %></td>
  </tr>
  <tr>
    <td>age:</td>
    <td><%= color %></td>
  </tr>
  <tr>
    <td>adds:</td>
    <td><%= address %></td>
  </tr>

<%
}
%>

The first time the page loads the "request" is empty. Nothing has been submitted. So everything there is the request is null: request.getParameter

But when you submit to the same page the "request" now has data and they are not null. So you can use that check:
if (submitTag!=null)
In order to determine if the page has been submitted or not and display the data.

If nothing has been submitted everything that you get from the request would be null. So:
If the check with the submit doesn't work, you can use something else.
if (name!=null) {

....
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.