• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving Session variables into another JSP

 
Ramu Kandada
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends I have just started learning JSP.I created 3 jsp's namely 1.jsp,2.jsp and 3.jsp as below:

1.jsp:
<html>
<BODY>
<FORM name="form1" method="post" action="2.jsp">
A:<INPUT type="text" name="a" id="a">
B:<INPUT type="text" name="b" id="b">
<INPUT type="submit" value="Go">
</FORM>
<%
String a = request.getParameter("a");
String b = request.getParameter("b");
session.setAttribute("a",a);
session.setAttribute("b",b);
%>
</BODY>
</HTML>

2.jsp:
<html>
<BODY>
<form name="form2" action="3.jsp" method="post">
C:<INPUT type="text" name="c">
D:<INPUT type="text" name="d">

<INPUT type="submit" value="Go">
</form>
</BODY>
</HTML>

3.jsp:

<html>
<BODY>
<P>

A:<INPUT type="text" value="<%=session.getAttribute("a")%>">
B:<INPUT type="text" value="<%=session.getAttribute("b")%>">
C:<INPUT type="text" value="<%=request.getParameter("c")%>">
D:<INPUT type="text" value="<%=request.getParameter("d")%>">

</P>
</BODY>
</HTML>

I want to print the values of text fields of 1.jsp and 2.jsp in 3.jsp I put the values of "a" and "b" in a session but I am able to retrieve those values into 3.jsp please help me in this regard
thanks in advance
 
mark walter
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramu,
The form in 1.jsp needs to be submitted before you can access the request.getParameter(). You need to move the block of code into 2.jsp and set the session values there. So 2.jsp would look like this:

2.jsp:
<html>
<BODY>
<%
String a = request.getParameter("a");
String b = request.getParameter("b");
session.setAttribute("a",a);
session.setAttribute("b",b);
%>
<form name="form2" action="3.jsp" method="post">
C:<INPUT type="text" name="c">
D:<INPUT type="text" name="d">

<INPUT type="submit" value="Go">
</form>
</BODY>
</HTML>

Hope this helps
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For an explanation of the fundamentals of how JSPs operate, perhaps this article may be helpful.
 
Ramu Kandada
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tnx mark tnx a lot
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ramu Kandada:
tnx mark tnx a lot


Please use real words when posting to the forums. Abbreviations such as "tnx" in place of "thanks" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

thanks,
bear
JavaRanch sheriff
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic