配置文件代码
<package name="dictionary_ajax_code" extends="json-default"> <action name="DictionaryType_ADD_SUBMIT" method="addSubmit" class="com.farm.core.dictionary.web.DictionaryTypeAction"> <result type="json"></result> </action> </package>AJAX和后台交互返回json时 报如下异常:
org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframework.aop.TruePointcut with modifiers "public" org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:243) org.apache.struts2.json.JSONWriter.process(JSONWriter.java:165) org.apache.struts2.json.JSONWriter.value(JSONWriter.java:131) org.apache.struts2.json.JSONWriter.write(JSONWriter.java:99) org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:112) org.apache.struts2.json.JSONResult.execute(JSONResult.java:198)主要原因:struts会将action中定义的一些变量序列化转换成json格式,需要调用对象的一系列get方法,因为有对象无法被序列化所以报错
解决方法
一:去掉getXXX()方法
二:在getXXX()方法上用注释@JSON(serialize=false)
作者:itmyhome
