1

I have a jsp form that takes different inputs from user. How can I print the submitted data on another jsp page?

Jack Flamp
  • 1,223
  • 1
  • 16
  • 32
Marium
  • 13
  • 3

2 Answers2

0

In your first JSP page:

<form method="post" action="otherPage.jsp">
   <input type="text" name="firstName">
   <input type="submit" value="Submit">
</form>

then on the otherPage.jsp you can get the value of the input:

<%
    String name = request.getParameter("firstName");
    out.println("Firstname: " + name);
%>

..although using scriptlets is normally discouraged.

If you want to use e.g. Spring MVC you post the form to a Controller which handles the request and there you can pass the parameters forward.

Jack Flamp
  • 1,223
  • 1
  • 16
  • 32
0

The use of scriptlets in JSP is strongly discouraged:

How to avoid Java code in JSP files?

You can achieve the same using JSP Expression Language (JSP EL):

<p>First name was ${param.firstName}</p>
Alan Hay
  • 22,665
  • 4
  • 56
  • 110