加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

ognl.OgnlException异常处理原因及处理

(2010-12-04 13:43:02)
标签:

处理

解释

原因

杂谈

分类: struts2
问题:
G'day, I appear to have resolved this issue that I kept running into with the Jasper Reports plugin... If I have an action defined as:
<action name="foo_*" method="{1}" class="com.xxx.foo">
<result name="success" type="jasper">
<param name="location">WEB-INF/foo.jasper</param>
<param name="format">${contentType}</param>
<param name="dataSource">dataSource</param>
<param name="imageServletUrl">/servlets/image?image=</param>
</result>
</action>
Using the Jasper Reports plugin that ships with S2 current, I get: 16:02:13,220 WARN [OgnlUtil] Caught OgnlException while setting property 'imageServletUrl' on type 'org.apache.struts2.views.jasperreports.JasperReportsResult'. java.lang.IllegalAccessException: Class ognl.OgnlRuntime can not access a member of class org.apache.struts2.views.jasperreports.JasperReportsResult with modifiers "protected" at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65) at java.lang.reflect.Field.doSecurityCheck(Field.java:960) at java.lang.reflect.Field.getFieldAccessor(Field.java:896) at java.lang.reflect.Field.set(Field.java:657) at ognl.OgnlRuntime.setFieldValue(OgnlRuntime.java:1140) ... And the imageServletUrl param does not take effect.

解释:

The issue appears to be that all of the setters in JasperReportsResult return a JasperReportsResult. The JavaBeans spec identifies that the setter for a simple property must return void. As a result, BeanInfo.getPropertyDescriptors won't see these setters as write methods for properties. With the other props in this class, that's not a problem - since they don't have getters, we don't get any propertyDescriptors for the properties, and proceed to look for methods individually (OgnlRuntime.java:1296). For imageServletUrl, however, there _is_ a valid getter. BeanInfo sees this as a read-only prop and returns a property descriptor for it, showing exactly that. Back in OGNL code, we see that we got a PropertyDescriptor, and don't bother asking for all methods. getSetMethod says "I don't have a set method," so OGNL eventually tries to just poke the field, resulting in the above error because the field is protected. Solution: modify the setters in JasperReportsResult to return void. This has been confirmed to fix the above problem. PK ---------------------------------------------------------------------


<result name="showorder" type="redirectAction">
                <!-- struts-sjiang.xml -->
                showOrderfood?desk_id=${desk_id}&amp;orderform_id=${orderform_id}
<!--                <param name="actionName">showOrderfood</param>-->
<!--                <param name="desk_id">${desk_id}</param>-->
<!--                <param name="orderform_id">${orderform_id}</param>-->
</result>

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有