How do I call a java method in JSTL?
This may be a recurring question.
I just want to call a method that is not a getter or setter for example. makeCall (someObj, "stringvalue") of the xyz class.
Java class
Class XYZ{
public String makeCall("someValue1","stringValue2"){
//some logic here
}
}
JSTL
<jsp:userBean id="xyz" class="com.XYZ"/>
${xyz.makeCall("hello","Friend")}
+3
source to share
3 answers
Just create an object of the class with <jsp:useBean>
and call the method using the JavaServer Pages Standard Tag Library or Expression Language , which is easier to use and less error prone.
example code:
<jsp:useBean id="test" class="com.x.y.z.XYZ"/>
${test.methodXYZ(object,"myString")}
Read more on Implicit Objects that can help you.
+2
source to share