Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call java method in JSTL? [duplicate]

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")}
like image 227
Sachin J Avatar asked Aug 09 '26 13:08

Sachin J


2 Answers

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.

like image 65
Braj Avatar answered Aug 11 '26 01:08

Braj


Try with this:

<c:out value="${XYZbean.makeCall(someObjBean, 'value')}" />
like image 25
Balduz Avatar answered Aug 11 '26 02:08

Balduz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!