• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Retrieving Session variables into another JSP

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
tnx mark tnx a lot
 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic