I am facing a strange problem.I am not able to set a value in a request using request.setAttribute() method on a jsp page so I am not able to get it on the action class .I tried and it gives null pointer exception.
I need argent help...
Thanks in advance
Regards Kanchan
Shahnawaz Shakil
Ranch Hand
Joined: Aug 04, 2008
Posts: 57
posted
0
Please put the code snippet here...otherwise how anyone can really tell, what mistake you are making.
Kanchan Singh
Ranch Hand
Joined: Dec 27, 2007
Posts: 38
posted
0
My code is as flow in Action class
List list1=new Arraylist(); request.setAttribute("Test", list1);
in JSP psge <% List l1=new Arraylist(); l1=(List)request.getAttribute("Test"); request.setAttribute("Test",l1); %>
in action class List l2=new Arraylist(); List l2=request.getAttribute("Test");
at last line here it gives me null pointer exception......
Regards Kanchan
Shahnawaz Shakil
Ranch Hand
Joined: Aug 04, 2008
Posts: 57
posted
0
One question before i take thorough look. You are using Arraylist instead of ArrayList. Is it typo error here or the same way you are using in your prog?
Karthik Janagiraman
Greenhorn
Joined: Mar 01, 2007
Posts: 3
posted
0
Your request object in the JSP is the object forwarded from the action , but that request will end and a new request object will be created when you submit your jsp with form elements as the request attributes.
sriram varadharajan
Greenhorn
Joined: Jan 03, 2007
Posts: 9
posted
0
i agree to what karthik says but to me it looks like you are setting it in the request object when the page is rendered . if this is a form submit it should definitely be available in the action class . i would ensure you do a form submit . if it still a problem put a hidden field on the page and store the value during load . in that way i think you can use request.getParameter('hidden variable name').