Struts 2 - Interceptor reset the response JSON Object

不打扰是莪最后的温柔 提交于 2019-11-29 18:17:40

There are mutliple errors in your code.

  • Response is HttpServletResponse, you should not give that name to a JSONObject.
  • Interceptors are NOT THREAD-SAFE, that means that you should define the JSONObject inside the method, to prevent multiple users to update it concurrently, one over the other
  • You should use statusCode or errorCode as described in the JSON plugin documentation, by configuring it as the Error result you are returning:

Use statusCode to set the status of the response:

<result name="error" type="json">
  <param name="statusCode">304</param>
</result>

And errorCode to send an error(the server might end up sending something to the client which is not the serialized JSON):

 <result name="error" type="json">
  <param name="errorCode">404</param>
</result>

and then read it client-side in the AJAX callback function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!