Struts:配置<constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
ognl类:
package com.zy.entity;
public class OgnlInfo {
//定义静态方法;
public static String sayBye(String name){
return name+"再见";
}
public String sayHello(String name){
return name+"你好";
}
}
index.jsp:
<body>
<%
//实例化ognl对象;
OgnlInfo ognlInfo=new OgnlInfo();
//将ognlInfo对象存入request作用域内
request.setAttribute("ognlInfo",ognlInfo);
%>
dddee
<!-- 执行ognl对象非静态方法 -->
<s:property value="#request.ognlInfo.sayHello('java')"/>
<!-- 执行ognl静态方法 -->
<s:property value="@com.zy.entity.OgnlInfo@sayBye('tom')"/>
</body>
请大神帮忙看下啊!!!
------解决思路----------------------
<s:property value="#request.ognlInfo.sayHello('java')"/>
<!-- 执行ognl静态方法 -->
<s:property value="@com.zy.entity.OgnlInfo@sayBye('tom')"/>
改为如下看看
<s:property value="ognlInfo.sayHello('java')"/>
<!-- 执行ognl静态方法 -->
<s:property value="${@com.zy.entity.OgnlInfo@sayBye('tom')}"/>
------解决思路----------------------
不建议在jsp中写java代码