Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

value pass from one servlet to another

 
rakhi sinha
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can we pass a value from one servlet to another without using session variable?
 
Eshwin Sukhdeve
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use RequestDispatcher to forward to another servlet.if the data exist in request object
 
rakhi sinha
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eshwin Sukhdeve wrote:you can use RequestDispatcher to forward to another servlet.if the data exist in request object

but i have to pass a value(to another servlet) which i got from another servlet using session object.......

i have to pass this value of n to another servlet so that i can use it in another servlet....
i am using Request dispatcher through following code but null value is retrieved that is following error is showed.
anull.pdf is not found as pdf or resource
 
Anurag Verma
Ranch Hand
Posts: 168
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set the data into request attributes & fetch it back into next servlet. ie on first servlet, write -

request.setAttribute("key", valueObject);

& in second servlet, write -

Object valueObject = request.getAttribute("key");
 
rakhi sinha
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anurag Verma wrote:set the data into request attributes & fetch it back into next servlet. ie on first servlet, write -

request.setAttribute("key", valueObject);

& in second servlet, write -

Object valueObject = request.getAttribute("key");

i have done it but null value is being passed...
 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why are you setting it again in the session. it is already in session so get it where ever you require it.
 
rakhi sinha
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mallikarjun dontamsetti wrote:why are you setting it again in the session. it is already in session so get it where ever you require it.

we can use this session object in any servlet ...... but in another servlet it is taking null value
 
Anurag Verma
Ranch Hand
Posts: 168
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
attributes in a servlet remains only till the instance of request (in which we have put the attribute) is alive. once the response is sent, it wont be available (even on further requests by same client.). what exactly are you doing & what exactly do you want??
 
rakhi sinha
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anurag Verma wrote:attributes in a servlet remains only till the instance of request (in which we have put the attribute) is alive. once the response is sent, it wont be available (even on further requests by same client.). what exactly are you doing & what exactly do you want??


i was doing some mistake now it is running
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic