• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot set attribute in request in jsp

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello to all,

I am trying to send an object from one jsp to another jsp through request object, I donot want to use hidden parameters. I tried "request.setAttribute(name,object)" in jsp but unable to get the same value on second page.
Also I have tried a simple example similar as shown below

first.jsp


second.jsp


but I get output as

but from servlet it works fine. I thing we cannot set attribute in jsp page. So suggest me how can I pass the parameter to next page after clicking on the submit button?

Thanks in advance.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The fact that you're calling request.setAttribute should tell you something. Whatever attributes are set in a request, are lost when the request is finished - which it will be right after the JSP page has been generated. (That's long before second.jsp is accessed.)

If you want to set attributes that exist for longer than a request/response cycle, use session attributes (for a particular user) or application attributes (which are visible to all users).

Alternatively, you could use a hidden parameter in the form. That's likely a better solution than using attributes, assuming that it's OK for the user to see the value of the attribute.
 
A berm makes a great wind break. And we all like to break wind once in a while. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic