Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set request attribute on JSP page

 
Kanchan Singh
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please put the code snippet here...otherwise how anyone can really tell, what mistake you are making.
 
Kanchan Singh
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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').

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic