Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

setting an attribute on the httprequest within a jsp  RSS feed

 
John Gregory
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet that looks up a user and sets an attribute on the request.
Next, it's forwarded to a jsp via a requestdispatcher.

In the ensuing jsp, I get the object I set in the servlet and display various
attributes of that object. On this jsp, there are 2 forms and 2 corresponding
buttons to process this user, depending on which button is depressed.

The question is, how can I get that user forwarded to a follow-on servlet?
I've tried using a hidden variable, no luck. I tried doing
in a scriptlet, but that didn't work. I'm getting a big fat null pointer exception...which I eventually
found in the HFJSP book...

Any ideas??

Thanks,

John
 
Ochi Elty
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Instead of using request.setAttribute("user", user), you must use session.setAttribute("user", user) and on your next jsps and servlets, get the object via session.getAttribute("user").

Hope this helps.



 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once the response is sent to the browser, the old request is gone and with it your scoped variables (the correct term for what you are calling "attributes").

You will either need to use the session (be sure to clean up after yourself), or cause the value to be submitted as a request parameter with the form to the next request.
 
John Gregory
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear,

Thanks, the using a session worked.

John
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!