Use request.getParameter() when you are planning to fetch values from a html/jsp page, and use request.getAttribute() when you want to fetch attribute values which are set using request.setAttribute() IN A SERVLET.
In your case, in page1.jsp are you trying to retrieve the firstName,lastName, etc from html/jsp?? If so you need to use request.getParameter() but not request.getAttribute();
Joined: Jul 17, 2007
Thanks. In page1.jsp the attributes (firstName, lastName,....) these attributes are set by a servelet (e.g. previousServelet). SO I guess using "request.getAttribute();" to retrieve the values, in such case, is OK.
Then again, I want the attribute values should be alive or available to the forwarded servelet (someservelet).
Mohammad [ May 14, 2008: Message edited by: Mohammad Akon ]
K Kiran Kumar
Joined: Jan 04, 2006
It is better to store the values(firstname, lastname,etc.) in session instead of setting them again and again using request.setAttribute() in each page. You can use the following:
The concept here is the scope of the attribute. Your code shows that you are getting some values from your previous servlet and setting them again in to the same attribute (which is not necessary).
No matter how many times you set the attributes, they have to be available for someServlet. Only then you will be able to retrieve them in the someServlet.
In your case, the atttibutes are of request scope and they will be available until your request is alive.
All that made difference in your case is the following snippet of code
<c:redirect> is nothing but you are redirecting it to some other servlet. That means, you are making a new request to some other servlet. In this case you request will be dead and new request will be sent.
So, obviously the value should be null.
instead of redirect, why dont you use reqeustDispatcher to redirect the to your someServlet... That will solve your problem.
Also, you don't need to set the attributes again. Just dispatch the request, the container will take care of making your attributes available to someServlet.
Otherwise, as kiran said, you can set your attributes at the session level to make them available through out the user session.
Hope this helps..... [ May 17, 2008: Message edited by: Prasad Tamirisa ]