I have been trying to use request.setAttribute() to pass values from one jsp page to another.It does not work.I keep getting a null pointer exception.
When i use a session and the store the attribute it works fine. I get that the attribute becomes associated with the entire session and thus is available to any part of the current session.
Why am i unable to use request.setAttribute() to do the same.
Am attaching the three forms i am using
List a = (List)request.getAttribute("shirts");//trying to get attribute. gives a null value //List a = (List)session.getAttribute("shirts");
String pants =request.getParameterValues("pant");
First of all: do not use scriptlets. This is not 1998 anymore. Immediately stop using scriptlets and switch to taglibs and EL, starting with JSTL. For the part which isn't solveable with taglibs or EL, you should be using a Java class, for example a servlet or javabean.
Regarding to your actual problem: a request lives from the time that the client sent it to the server until the time that the response is sent from server to client. At the moment that the response is displayed in the webbrowser, the request is already garbaged for long time, including all of its attributes. When you submit the form or invoke a new request, a brand new request object will be created. The previous will not be reused.
There are several ways to transfer data from request to request:
1) Pass it as hidden input value.
2) Store it in session scope.
Joined: Mar 19, 2009
I was thinking along the same lines but could not get a definite hit on it.
As for using the scriptlet Code I have just started JSP some time back and am finding my way.
Thanks for the advice .Will try to implement what you wrote.