• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL - collection in request vs. session

 
Vicky Mohan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • 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" >
<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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Julia Reynolds
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • 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
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic