File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes JSTL -  collection in request vs. session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "JSTL -  collection in request vs. session" Watch "JSTL -  collection in request vs. session" New topic
Author

JSTL - collection in request vs. session

Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
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" >
<cut 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 ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60048
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60048
    
  65

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.
Julia Reynolds
Ranch Hand

Joined: May 31, 2001
Posts: 123
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
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
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.
 
subject: JSTL - collection in request vs. session
 
Similar Threads
Getting results to the forwarded page
What is wrong in th code
Displaying simple read-only tabular data
Iterator in Struts 1
ArrayList in <HTML:SELECT> tag