• 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

problem with request.setAttribute in jsp

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am having two jsp pages.

One.jsp and two.jsp.

I am using scriplet code in the One.jsp to set attribute like this :

request.setAttribute(“Name”,”Java”);

In the form action of one.jsp I am giving the value as “two.jsp”.

And after submitting , when I am trying to get the attribute using request.getAttribute(“Name”) in the second jsp , it is printing null.

I checked if the request objects are different , but when I printed the request object in one and two jsps they both gave same value ,i.e same request object is passed from one.jsp to two.jsp.

Then why am I not able to get the attribute in the second jsp page if the request object that is passed is same.

Anybody help me understanding , how and when the request object is created.
 
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

roger james wrote:

Request.setAttribute(“Name”,”Java”);




you might want to change the 'Request' to 'request'. The latter is an implicit object in JSP, but the former one is an unknown entity.
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you submit a form or go to a another jsp page, a new request object is created. I think

When you one.jsp is loaded, a request object is created and you are setting the value in that object.



When you submit the form a new JSP page(two.jsp) is rendered and a new request object is created.

Hope this helps and I can be pretty sure that same request object cannot be transferred when you submit the form.

I think the only chance where the request object can be forwarded is when you forward the request.
 
Sheriff
Posts: 67746
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

roger james wrote:i.e same request object is passed from one.jsp to two.jsp.


Your conclusion is incorrect. The two requests are different,.
 
roger james
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

roger james wrote:i.e same request object is passed from one.jsp to two.jsp.


Your conclusion is incorrect. The two requests are different,.



Hi Bear Bibeault,
I printed the request object in both one.jsp and two.jsp. I got same object ...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic