File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Retrieving Session variables into another JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Retrieving Session variables into another JSP" Watch "Retrieving Session variables into another JSP" New topic
Author

Retrieving Session variables into another JSP

Ramu Kandada
Greenhorn

Joined: Aug 05, 2008
Posts: 4
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

Joined: Jun 20, 2008
Posts: 15
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

Joined: Jan 10, 2002
Posts: 61610
    
  67

For an explanation of the fundamentals of how JSPs operate, perhaps this article may be helpful.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ramu Kandada
Greenhorn

Joined: Aug 05, 2008
Posts: 4
tnx mark tnx a lot
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61610
    
  67

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieving Session variables into another JSP