Meaningless Drivel is fun!*
The moose likes Struts and the fly likes How to set request attribute on JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to set request attribute on JSP page" Watch "How to set request attribute on JSP page" New topic
Author

How to set request attribute on JSP page

Kanchan Singh
Ranch Hand

Joined: Dec 27, 2007
Posts: 38
Hi All

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
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
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
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
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
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').

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set request attribute on JSP page