1、前台代码如:
<s:checkbox name="singleTrip.transmit"></s:checkbox>
2、后台定义了:
singleTrip属性的get/set方法
3、进入Action时报错:
ognl.OgnlException: target is null for setProperty(null, "transmit", [Ljava.lang.String;@1a0561d)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2219)
at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.ASTChain.setValueBody(ASTChain.java:227)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.Ognl.setValue(Ognl.java:737)
...
at java.lang.Thread.run(Thread.java:619)
expr: __checkbox_singleTrip.transmit val: [Ljava.lang.String;@1a0561d context: ognl.OgnlContext@c3e4e056 root:[com.csair.vos.order.action.BookInQueryAction@c0fd31, com.opensymphony.xwork2.DefaultTextProvider@2ed8df] value: [Ljava.lang.String;@1a0561d
4、分析前台html代码,发现struts2生成的代码为:
<input type="checkbox" name="singleTrip.transmit" value="true" id="singleTrip_transmit"/>
<input type="hidden" id="__checkbox_singleTrip_transmit" name="__checkbox_singleTrip.transmit" value="true" />
5、发现问题:
多了name="__checkbox_singleTrip.transmit"的hidden控件,所以报错了;
在Action中添加__checkbox_singleTrip属性与get/set方法,就没有报上面的错误了。