0

在我的 struts2 应用程序中进行 AJAX 调用时出现以下错误:

 org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException:             org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
 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)
 com...hony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
 com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
 com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
 com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
 org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
 com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
 com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
 com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
 com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
 com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
 org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
 org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
 org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)

进行 ajax 调用时执行正确的操作/方法。

我使 Action 类中引用的所有对象都实现了 Serializable。

我能做些什么来解决这个问题?我一直在互联网上搜索..但没有任何线索..

4

2 回答 2

2

发现了问题.. 我的班级中有 BidDecimal 对象,并且这种类型不支持 JSON 序列化。我将它转换为 String 和 double 并且它现在可以工作了。

于 2010-11-15T05:46:42.790 回答
1

通过将“includeProperties”参数添加到 struts.xml 并限制作为 AJAX 调用的响应传递的变量来解决错误。

<result name="imgData" type="json">
    <param name="includeProperties"> returnResult </param>
</result>

“returnResult”是包含作为 AJAX 调用响应传递的数据的变量。

于 2018-10-09T05:06:30.587 回答