This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JSP and the fly likes send values from 1 jsp to another Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "send values from 1 jsp to another" Watch "send values from 1 jsp to another" New topic
Author

send values from 1 jsp to another

Sachin Kadian
Ranch Hand

Joined: Jan 24, 2012
Posts: 33
i am trying to send some values from 1 jsp to another jsp but i am not able to do that. please help me . my code is as



on test.jsp i am trying to get the value by



but everytime i am getting a null. please tell me where i am wrong.
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
As soon as response for your first jsp is sent to browser , request is complete and whatever data you set in request will also be lost. If you want some data to be available in next jsp , you should put it in session.
Sachin Kadian
Ranch Hand

Joined: Jan 24, 2012
Posts: 33
is there not any another method to send data than session??
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
You can send data using form parameter i.e (hidden parameter) if using post.
Sachin Kadian
Ranch Hand

Joined: Jan 24, 2012
Posts: 33
but i thing request.getParameter is also not working here and returning null.
Amit Goda
Ranch Hand

Joined: Jan 21, 2012
Posts: 37

String item1="this is an item";
request.setAttribute("item1",item);


Ok. What i feel is the value you're setting in setAttribute() has to be
item1
whereas you're setting it as
item
. So i guess when you're trying to access it through getAttribute("item1"), the jsp is getting the variable but not getting its value because item does not exist!!!

Ok one more thing the getAttribute() method accepts the variable name as string o it should be getAttribute("item1") instead of getAttribute(item1)



Cheers :)


AMiT
Sachin Kadian
Ranch Hand

Joined: Jan 24, 2012
Posts: 33
there both are written by mistake. i used the correct code in my program and its not running.
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Amit Goda wrote:
String item1="this is an item";
request.setAttribute("item1",item);


Ok. What i feel is the value you're setting in setAttribute() has to be
item1
whereas you're setting it as
item
. So i guess when you're trying to access it through getAttribute("item1"), the jsp is getting the variable but not getting its value because item does not exist!!!

Ok one more thing the getAttribute() method accepts the variable name as string o it should be getAttribute("item1") instead of getAttribute(item1)



Cheers :)


request.setAttribute() lasts only till request is complete. So there is no way you can get data in another request.

Hi Sachin ,Did you try with the following code?



Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

That hidden field needs a name.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: send values from 1 jsp to another
 
Similar Threads
Not able to retrive the Value sent through JavaScript function
null pointer exception in spring with hibernate
Retaining jsp form data when accessing a separate menu item
Recursive program help
url is changing by requestdispatcher