该Bug的异常栈如下:
Unable to set parameter [id] in result of type [org.apache.struts2.dispatcher.ServletActionRedirectResult] ==> com.opensymphony.xwork2.util.logging.commons.CommonsLogger.error(CommonsLogger.java:27)
Caught OgnlException while setting property 'id' on type 'org.apache.struts2.dispatcher.ServletActionRedirectResult'.
- Class: ognl.ObjectPropertyAccessor
File: ObjectPropertyAccessor.java
Method: setProperty
Line: 132 - ognl/ObjectPropertyAccessor.java:132:-1
at com.opensymphony.xwork2.ognl.OgnlUtil.internalSetProperty(OgnlUtil.java:392)
at com.opensymphony.xwork2.ognl.OgnlUtil.setProperty(OgnlUtil.java:143)
at com.opensymphony.xwork2.ognl.OgnlReflectionProvider.setProperty(OgnlReflectionProvider.java:91)
at com.opensymphony.xwork2.ObjectFactory.buildResult(ObjectFactory.java:221)
at com.opensymphony.xwork2.DefaultActionInvocation.createResult(DefaultActionInvocation.java:208)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:355)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265)
....
....
....
Caused by: ognl.NoSuchPropertyException: org.apache.struts2.dispatcher.ServletActionRedirectResult.id
at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:132)
at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:28)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1656)
at ognl.ASTProperty.setValueBody(ASTProperty.java:101)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)
at ognl.SimpleNode.setValue(SimpleNode.java:246)
at ognl.Ognl.setValue(Ognl.java:476)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:192)
at com.opensymphony.xwork2.ognl.OgnlUtil.internalSetProperty(OgnlUtil.java:385)
如果我们在redirectAction result中使用动态参数就会出现如上异常,如下:
<result name="articleDetail" type="redirectAction">
<param name="actionName">article</param>
<param name="method">detail</param>
<param name="parse">true</param>
<param name="id">${id}</param>
</result>
这个bug在struts2.1.6中尚没有解决,bug出现的地方位于com.opensymphony.xwork2.ognl.OgnlUtil
try {
setValue(name, context, o, value);
} catch (OgnlException e) {
Throwable reason = e.getReason();
String msg = "Caught OgnlException while setting property '" + name + "' on type '" + o.getClass().getName() + "'.";
Throwable exception = (reason == null) ? e : reason;
if (throwPropertyExceptions) {
throw new ReflectionException(msg, exception);
} else {
if (devMode) {
LOG.warn(msg, exception);
}
}
}
原因是Ognl试图在ServletActionResult中寻找一个叫id的属性,找不到就抛出了这个Ognl异常。但是ServletActionResult最终还是能拿到这个动态参数,并且使用它来构造查询串。这个对程序的执行结果没有影响,但服务器端总是打出这样的log,让人感觉很不舒服。或者我们可以选择改变struts2的log level来避免它!
分享到:
相关推荐
精通Struts 2:Web 2.0开发实战 PDF版 免费分享
STRUTS 2:基于MVC的JAVA WEB应用开发实战——网络商店实例编程part1
从jsp页面提交form表单后,在struts.xml中寻找匹配的action。在action中处理完业务后返回,在struts.xml中的result属性中转向到另外一个action。
STRUTS2:零配置插件CodeBehind
STRUTS2:拦截器Interceptor
struts2:我想用struts标签来统计购物车的总价
struts2中result类型之redirectAction
struts2中result类型之redirect,重定向
NULL 博文链接:https://liuzidong.iteye.com/blog/920940
STRUTS 2:基于MVC的JAVA WEB应用开发实战——网络商店实例编程part2
struts2 <s:if>标签使用struts2 <s:if>标签使用struts2 <s:if>标签使用struts2 <s:if>标签使用struts2 <s:if>标签使用struts2 <s:if>标签使用
Struts2框架实现action和jsp的数据交互,前面例解了怎么实现,后面配上一首陈慧琳的谁愿放手歌词,精美大气,谢谢各位老板
struts logic:iterater 换行
struts2一个action处理多个请求
Struts 2实战 struts2 in Action
关于struts2 Result的配置,有例子
第1章 Struts 2:现代Web框架 2 1.1 Web应用程序:快速学习 2 1.1.1 构建Web应用程序 2 1.1.2 基础技术简介 3 1.1.3 深入研究 6 1.2 Web应用程序框架 7 1.2.1 什么是框架 7 1.2.2 为什么使用框架 8 1.3 Struts 2框架...
STRUTS:struts2标签库
struts2的action的几种result type说明