File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes JSTL Conditional Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "JSTL Conditional" Watch "JSTL Conditional" New topic
Author

JSTL Conditional

Alan Hermin
Ranch Hand

Joined: Feb 16, 2006
Posts: 290
Hi all........
i am working with JSP 1.2
i have request attribute that get either "0" or "1" as Strings...
and i have JSTL c:when like this:




Then...how can i make the test attribute if when tag works successfully..???
remember:i am working with JSP 1.2..


Thnx
[ July 18, 2006: Message edited by: Ala'a Hendi ]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1004
Ok, couple of things.
Request attributes are always objects.
You say it is a string, so you need to do a string comparision: use the .equals() method.

<c:when test='<%= request.getAttribute("myAtt").equals("1) %>'>
...
</c:when>

Second thing - why are you using <%= expr %> with JSTL tags?
YOu are losing the power of the expression language.
Using an EL expression, it becomes much simpler:

<c:when test="${requestScope.myAtt == 1}">
...
</c:when>

Much easier to read don't you think?
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

He's using expressions because he is using JSP 1.2 and not 2.0.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56185
    
  13

Originally posted by Gregg Bolinger:
He's using expressions because he is using JSP 1.2 and not 2.0.


Still not necessary. The EL was introduced with the JSTL 1.0 for JSP 1.2. There's no reason to be using scriplets as attributes to the JSTL tags for this type of access.

Of course, in JSP 1.2 the EL is confined to the JSTL actions.
[ July 18, 2006: Message edited by: Bear Bibeault ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: JSTL Conditional
 
Similar Threads
Nesting JSTL Tags
jsp does not display messages
JSTL c:when
Dependant drop down list boxes in JSP page
jsp: include not working...