• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL Conditional

 
Alan Hermin
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1784
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
He's using expressions because he is using JSP 1.2 and not 2.0.
 
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
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic