struts2 ajax json异常

发布于 2024-10-02 14:50:51 字数 2043 浏览 7 评论 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 类中引用的所有对象都实现了可序列化。

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

I am getting the below error when making an AJAX call in my struts2 application:

 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)

The correct Action/method are executed when the ajax call is made.

I made all objects referenced in the Action class implement Serializable.

What can i do to fix this problem? I have been searching on the internet .. but no clues..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浮萍、无处依 2024-10-09 14:50:51

发现问题..我的类中有 BidDecimal 对象,并且这种类型不支持 JSON 序列化。我将它转换为字符串和双精度,它现在可以工作了。

The found the problem .. I had BidDecimal objects in my class and JSON serialization is not supported for this type. I converted it to String and double and it iw working now.

心房敞 2024-10-09 14:50:51

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

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

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

solved the error by adding "includeProperties" param to the struts.xml and limiting the variables passed as the response for the AJAX call.

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

"returnResult" is the variable containing the data which was passed as the response for the AJAX call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文