This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes jstl variable handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jstl variable handling " Watch "jstl variable handling " New topic

jstl variable handling

Khushwinder Chahal
Ranch Hand

Joined: Oct 03, 2007
Posts: 128
Hi All
I want to compare a jstl variable like ${StoneAKAForm.code}
with a jsp integer variable..
Anybody have any idea .
Thanks in advance.


Ben Souther

Joined: Dec 11, 2004
Posts: 13410

The need to do this is usually an indicator that JSTL isn't being used properly. JSTL is meant for scriptless JSPs where all of the heavy lifting is done with Java objects before context is ever forwarded to the JSP for markup.

If you were comparing objects, you could simply bind your scriptlet variable to request scope with request.setAttribute("name", value) and then compare the two using EL. However, in this case, you're scriptlet variable is an int which is a native type and can't be bound directly to scope without being wrapped in the Integer type.

If you really have to do this, you might be better off dereferencing ${StoneAKAForm.code} from within your scriptlet and doing the comparison there.

Maybe if you tell us why you need to compare these, someone can suggest a better strategy.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Khushwinder Chahal
Ranch Hand

Joined: Oct 03, 2007
Posts: 128
Thanks a lot for your reply.
But my problem is that i have to do this because of some constraints.
There is no other option.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

From within your scriptlet, you could use PageContext.findAttribute to locate
the StoneAKAForm object, then call its getCode method and do the comparison there.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60755

"khushwinder khushwinder", please check your private messages immediately.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
It is sorta covered in the JavaRanch Style Guide.
subject: jstl variable handling
Similar Threads
request AND requestScope
how to access jstl variable in scriplet?
JSTL not showing results
Security Remediation in My current application
[ JSTL ] form bean var