OGNL Syntax Issue

前端 未结 2 1319
走了就别回头了
走了就别回头了 2021-01-15 08:42

I have a Struts 2 JSP page with the following snippet:


which correctly prints out the value of

相关标签:
2条回答
  • 2021-01-15 08:56

    I think you are missing target object, ex

    <s:property value="%{myTarget.myMethod(myVariable)}" />
    

    More: How to pass parameter to method call in Struts 2 OGNL

    0 讨论(0)
  • 2021-01-15 08:58
    <s:property value="%{myMethod(myVariable)}" />
    

    is a correct syntax, but to get the value of the method that have a signature

    public String myMethod(String value){
      return value;
    }
    

    required the getter for myVariable

    public String getMyVariable() {
      return myVariable;
    }
    

    if you set the value to myVariable like

    private String myVariable = "myValue";
    

    then it should be printed in JSP. If the argument is other type it will be converted to String and the method will call.

    0 讨论(0)
提交回复
热议问题