Accessing static variable using OGNL in Struts2

情到浓时终转凉″ 提交于 2019-12-05 03:27:06

@see OGNL Basics : Accessing static properties

BEAN :

public class ContactsBean {
    private static int count = 1; 

    // static getter
    // setter
}

<s:property value="@com.demo.bean.ContactsBean@getCount()" />

other case

public class ContactsBean {
    public static final int SCALE = 50;
}

<s:property value="@com.demo.bean.ContactsBean@SCALE" />

Apache Struts 2 Documentation - struts.properties http://struts.apache.org/2.0.14/docs/strutsproperties.html

To enable static method access / invocation set the Struts2 constant in your struts.properties file in your base package:

struts.ognl.allowStaticMethodAccess=true 

.. or I believe you can set it in the struts.xml as

<constant name="struts.ognl.allowStaticMethodAccess" value="true"/> 

Its work fine if we mentioned the below entry in struts.xml

  <constant name="struts.ognl.allowStaticMethodAccess" value="true"/> 
Alireza Fattahi

As mentioned in new release of struts 2 (2.3.20), this (struts.ognl.allowStaticMethodAccess) will be removed soon from struts.

Please review Struts 2 refactoring code to avoid OGNL static method access to find out how you can still use this feature in new version.

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