File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

send values from 1 jsp to another

 
Sachin Kadian
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 196
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there not any another method to send data than session??
 
Piyush Mangal
Ranch Hand
Posts: 196
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can send data using form parameter i.e (hidden parameter) if using post.
 
Sachin Kadian
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i thing request.getParameter is also not working here and returning null.
 
Amit Goda
Ranch Hand
Posts: 37
Eclipse IDE Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :)
 
Sachin Kadian
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there both are written by mistake. i used the correct code in my program and its not running.
 
Piyush Mangal
Ranch Hand
Posts: 196
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That hidden field needs a name.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic