Approaches to Referencing Static Variables in JSP2.0

J

Jason

Hey all, just wondering what approaches people are taking for
referencing static variables in JSP 2.0 / EL. It seems that the only
straight forward way to do this is through the use of a scriptlet,
i.e., <%=MyClass.myStaticVariable%>. This, of course, is an
undesirable approach if your goal is to eliminate the use of
scriptlets from your JSP code.
 
C

Chris Smith

Jason said:
Hey all, just wondering what approaches people are taking for
referencing static variables in JSP 2.0 / EL. It seems that the only
straight forward way to do this is through the use of a scriptlet,
i.e., <%=MyClass.myStaticVariable%>. This, of course, is an
undesirable approach if your goal is to eliminate the use of
scriptlets from your JSP code.

As long as you're thinking of the problem as one of accessing a static
variable from a JSP, you aren't going to reach a satisfactory solution.
It's, in fact, somewhat contradictory in motive to claim to want to
eliminate scriptlets from a JSP, and then ask how to directly reference
a concept from the Java programming language in that page.

Instead, you could ask two questions: first how you might choose to
access some piece of information in a JSP (for example, EL expression,
or custom tag), and second, how you could implement that access method
in JSP to get the value from a static variable in Java. That might
involve placing the value in an application attribute prior to
forwarding to the page (so that it can be accessed through the EL), or
writing a custom tag to retrieve the value. It may also involve
implementing an EL function with a tag library, so that the value could
be accessed that way through the EL.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top