• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

setting an attribute on the httprequest within a jsp

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,

Thanks, the using a session worked.

John
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic