• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to set request attribute on JSP page

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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').

 
reply
    Bookmark Topic Watch Topic
  • New Topic