21OGNL与ValueStack(VS)-静态方法访问

转自:https://wenku.baidu.com/view/84fa86ae360cba1aa911da02.html

在LoginAction中增加如下方法:
public static String getSta() {

              return "这是LoginAction中的静态方法";

}

然后在loginSuc.jsp中增加如下代码:

调用Action中的静态方法:<s:property value="@com.asm.LoginAction@getSta()"/><br>

调用LoginAction中的静态方_方式(2):<s:property value="@vs@getSta()"/><br>

说明:我们在方式二中用到@vs,只有那些值栈中的对象才可以这样写。
然后访问,发现访问不到,因为在struts2.1.6的版本中,struts.ognl.allowStaticMethodAccess的默认值为false,我们只需在struts.xml中增加如下内容:
<constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
再来访问时便可以访问到。

原文地址:https://www.cnblogs.com/sharpest/p/5582866.html