How to call java method in JSTL?

Sachin J picture Sachin J · Aug 8, 2014 · Viewed 25.9k times · Source

This might be duplicate question.

I just want to call method which is not getter or setter method eg. makeCall(someObj,"stringvalue") of xyz class.

Java Class

Class XYZ{

    public String makeCall(Object objValue, String stringValue){

    //some logic here

    }
}

JSTL

<jsp:userBean id="xyz" class="com.XYZ"/>
${xyz.makeCall("hello","Friend")}

Answer

Braj picture Braj · Aug 8, 2014

Simply create an object of the class using <jsp:useBean> and call the method using JavaServer Pages Standard Tag Library or Expression Language that is more easy to use and less error prone.

sample code:

<jsp:useBean id="test" class="com.x.y.z.XYZ"/>

${test.methodXYZ(object,"myString")}

Read more about Implicit Objects that might help you.