tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Helios Alonso <>
Subject Re: How to access java object method from JSTL expression
Date Wed, 08 Sep 2004 16:32:29 GMT
If you have a "normal" class with standard-named methods it's alright.  In 
fact, a JavaBean means an object with it's properties declared with a 
defined naming convention (an Enterprise Java Bean is another story).

If you have a class with

String getTheValue()
// you can read the property "theValue".

void setTheValue(String x)
// you can set the property "theValue"

If it's an array or a java.util.List you can access it using myobject[i]

If it's a java.util.Map you can access the values using myobject[key]
And you also can access the pairs name-value using it as a collection with 
the forEach tag:

<c:forEach items="myMap" var="pair">
<!-- here pair is a java.util.Map.Entry and you can use pair.key and 
pair.value -->

It it's NOT a Map you can access properties using ['propertyname'], so you 
can access:

myobject['theValue'] for the first example in this mail (note this gives 
you the capability to access dinamically the properties of a Bean).

At last, you can instantiate the objects in your JSP stating their scope.

You can:

<jsp:useBean name="x" class="org.myproject.MyClass" scope="page"/>
<!-- for creating an object for each page --->

<jsp:useBean name="x" class="org.myproject.MyClass" scope="session"/>
<!-- for creating an object for each session --->

(check the useBean sintaxis, I'm not sure of it right now)

Good luck.

At 11:35 08/09/2004 -0400, you wrote:
>I saw some examples to access standard java bean properties from JSTL
>expression language on JSP page. I am wondering is there any way to access
>regular java class methods from JSTL expression?
>Now in the JSP, I am trying to access a Java class, which has a business
>method return a string value. That java class is not a java bean class. Can
>someone tell me how to do that?
>This e-mail, including attachments, may include confidential and/or
>proprietary information, and may be used only by the person or entity to
>which it is addressed. If the reader of this e-mail is not the intended
>recipient or his or her authorized agent, the reader is hereby notified
>that any dissemination, distribution or copying of this e-mail is
>prohibited. If you have received this e-mail in error, please notify the
>sender by replying to this message and delete this e-mail immediately.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message