niren
niren

Reputation: 2731

How to forward the parameters from one page to another jsp page?

Am New to jsp I had to forward the name from one file to another. After a lot of dig I found the below code to be worked but it wasn't work. I have three jsp files like oneMain.jsp, twoMain.jsp and threeMain.jsp. I forward the name threeMain from oneMain.jsp to twoMain.jsp. So that I can display the content of the threeMain.jsp page

oneMain.jsp code is

<jsp:forward page="twoMain.jsp">
<jsp:param name="visualName" value="threeMain.jsp"/>
</jsp:forward>

twoMain.jsp code is

<jsp:forward page="<%= request.getParameter("visualName")%>"/>

Finally I want threeMain.jsp content to be displayed.

Upvotes: 4

Views: 36093

Answers (1)

MaVRoSCy
MaVRoSCy

Reputation: 17839

Consider the code below on how you can pass parameters between jsp pages. You can use the <jsp:forward ... > to forward a request using this code:

<jsp:forward page="newjsp1.jsp">
  <jsp:param name="par1" value="111" ></jsp:param>
</jsp:forward>

This will forward the response to newjsp1.jsp with a parameter par1 and its value is 111.

Now in newjsp1.jsp you can read this parameter using:

<jsp:scriptlet>
  out.append(request.getParameter("par1"));
</jsp:scriptlet>

You can also share attributes between pages using the session implicit Object... Possibilities are limitless...

Maybe you would like to check these pages out:

  1. http://www.tutorialspoint.com/jsp/jsp_implicit_objects.htm
  2. http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/

Upvotes: 5

Related Questions