A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
request attribute set in the jsp cannot be retrieved in the servlet
Joined: May 25, 2010
May 25, 2010 07:42:24
For a POC purpose i was trying to set an attribute in the request and application scope in a
page. The JSP code is:-
<% ArrayList al = new ArrayList(); al.add("1"); al.add("2"); request.setAttribute("List", al); application.setAttribute("List", al); %>
When i submit the JSP in the respective
i get the request attribute as null but the context attribute is retrieved properly.
The servlet code is :-
ArrayList al1 = (ArrayList) request.getAttribute("List"); System.out.println(al1); // prints null ArrayList al2 =(ArrayList)getServletContext().getAttribute("List"); System.out.println(al2); // prints [1, 2]
Please let me know why the request attribute is coming as null in the servlet while the context attribute is coming properly.
Thanks in advance.
Author and ninkuma
Joined: Jan 10, 2002
May 25, 2010 09:55:26
Welcome to the ranch.
Please edit your post to remove the unreadable blue code and replace it to
. If people cannot read your code, how can they help you?
Asking smart questions
Books by Bear
Author and all-around good cowpoke
Joined: Mar 22, 2000
May 25, 2010 12:19:51
When i submit the JSP in the respective Servlet
What does that mean exactly?
You do realize that a request object only has the lifetime of a single request, right?
Java Resources at
I agree. Here's the link:
subject: request attribute set in the jsp cannot be retrieved in the servlet
Show HashMap in Datatable. UIColumn with embedded Datatable. Help Needed
sending a Collection from JSP to Servlet
Remove duplicates in arraylist
Using of nested Datatables
Eliminating Duplicate in Arraylist and moving the dups to another arraylist.
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013