| Author |
problem with request.setAttribute in jsp
|
roger james
Greenhorn
Joined: Jul 27, 2008
Posts: 2
|
|
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.
|
 |
Dawn Charangat
Ranch Hand
Joined: Apr 26, 2007
Posts: 249
|
|
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.
|
 |
Ramkumar Subburaj
Ranch Hand
Joined: Sep 07, 2007
Posts: 83
|
|
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.
|
SCJP 1.5, SCWCD 1.4.
Hanging between Web Services and EJB
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56529
|
|
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,.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
roger james
Greenhorn
Joined: Jul 27, 2008
Posts: 2
|
|
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 ...
|
 |
 |
|
|
subject: problem with request.setAttribute in jsp
|
|
|