How to call java method in JSTL? [duplicate]

廉价感情. 提交于 2019-12-07 14:23:03

问题


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("someValue1","stringValue2"){

    //some logic here

    }
}

JSTL

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

回答1:


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.




回答2:


Try with this:

<c:out value="${XYZbean.makeCall(someObjBean, 'value')}" />



回答3:


For resolve this we need create your own tag. (in .tld file)

and need to write one java class for this tag.

After this you can call method within that your own class and set result to pageCotext to retrive it on jsp.



来源:https://stackoverflow.com/questions/25198690/how-to-call-java-method-in-jstl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!