It's not a secret anymore!*
The moose likes JSP and the fly likes Scriptlet  vs JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Scriptlet  vs JSTL" Watch "Scriptlet  vs JSTL" New topic
Author

Scriptlet vs JSTL

Tom Henricksen
Ranch Hand

Joined: Mar 23, 2004
Posts: 136

I have set this up on Tomcat 5.0.28 with JSTL 1.0. I have a servlet that puts a List into session then calls a JSP


The JSP pulls it out and iterates through it.
If I run this JSTL JSP it works good:


But if I use JSP with a scriptlet this doesn't find the List


You make ask why am I doing this. I am trying to debug something else. Am I doing something wrong with scope?
Thanks in advance,
Tom

[ December 14, 2005: Message edited by: Tom Henricksen ]
[ December 14, 2005: Message edited by: Tom Henricksen ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

With Tomcat 5 you should be using JSTL 1.1.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
In your scriptlet, you are trying to get the list from the request. But, in your servlet, you added the list to the session.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
>Am I doing something wrong with scope?
you put the attribute into session scope:
request.getSession().setAttribute("list",list);

and then try to retrieve it from request scope:
List list = (List)request.getAttribute("list");

Do you think that should be reason enough?

The reason JSTL works is that it uses the method pageContext.findAttribute("list") to search through page, request, session then application scopes (in that order) to find the appropriate attribute.

That is also why you were able to use ${list} as the name of both your "list" AND the temp variable you were using to iterate over the list.
Their fully qualified names would be ${pageScope.list} and ${sessionScope.list}. The first time you use ${list} it matched the list in session scope. After that it used the variable in the page scope.

Normally I would recommend that you you use different names for var and items - just to save confusion.
Tom Henricksen
Ranch Hand

Joined: Mar 23, 2004
Posts: 136

Thank you all very much! I appreciate your help with this.

Tom
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Scriptlet vs JSTL
 
Similar Threads
Iterating through local List using JSTL
Server Name issue
Keep HTML tag in String
JSTL not working
Expressions problem