读书人

ognl.OgnlException: target is null

发布时间: 2012-09-02 21:00:34 作者: rapoo

ognl.OgnlException: target is null for setProperty(null, "description", [Ljava.l
以前也遇到过这样的错误,没有怎么注意。今天又遇到了。总结一下。
Struts页面参数传递错误原因有四种可能性。

一、数据类型不匹配:
如Action中为Integer类型,而传递过来的是String类型,此种原因多半因为写Struts标签或EL表达式时写错了。

二、也可以称作数据类型不匹配:
如Action中的属性为Integer id; 但是页面上传递参数时同时传递了多个name为id
的参数,如此以来即因为不能将整型数组转换成整型而出错。

三、无法访问属性出错
如Action中有一个Student的属性stu,Student有age的属性,但是Student却没有无参数的构造方法,或者age这个属性没有getter或setter方法,就或出错,这是网上的说法。

四、Spring管理下的Action出错:
这是今天我遇到的错误,也是最隐蔽的错误。
情况如下:
我使用注解的方式,将Action纳入Spring管理:


BussinessAction(业务),里面用到了javaBean:AcceptType(受理类型):
Cannot convert value of type [cn.chinacti.crm.action.AcceptAction] to required type [cn.chinacti.crm.entity.AcceptType] for property 'acceptType': no matching editors or conversion strategy found

解决办法:
修改Action的名称

读书人网 >软件架构设计

热点推荐