• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

JSTL - collection in request vs. session

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey All,

THis is a very simple question, i guess.

I have a collection of objects set to request scope.

request.setAttribute("myList",(List)myList);

In my JSP, i am trying to access the list by the following code

***********************************
<c:forEach items="${myList}" var="list" varStatus="x" >
<c:out value="${list.id}" />
</c:forEach>

************************************
For some reason, the id never gets printed.

I tried to set the collection to session instead of request

************************************
request.getSession.setAttribute("myList",(List)myList);
************************************

Now, the id gets printed.

I was under the impression that the tag looks into request and if not, checks the session for the variable.

I really dont want to set the collection to session and then add logic to remove from session again.

Any help will be appreciated.
[ May 04, 2007: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you getting from the resource (servlet?) that sets the list into the request to the JSP?

If it is via a forward, the scoped variable should be available in the JSP. If it's a redirect, the browser issues a new request and the scoped variable goes by-by along with the old request.

By the way:

request.setAttribute("myList",(List)myList);

The cast to (List) is superfluous.
 
Vicky Mohan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We are using struts framework and there is no value provided for the attribute "redirect".

This implies forward should be used as redirect is false by default.
 
Bear Bibeault
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then it should be working just fine. Since you are saddled with Struts, I'll move this off to the Struts forum for further diagnosis.
 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raj,

Maybe explicitly set redirect="false" in the struts-config.xml and get your list this way in the jsp before accessing it:

<c:set var="myList" value="${requestScope['myList']"/>

Julia
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems like what you have there should work. Could you post your mapping from struts-config and any relevant pieces of your action code?

- Brent
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic