Using more than one result type in the same action method in struts 2?

后端 未结 1 1170
别那么骄傲
别那么骄傲 2021-01-24 21:50

I have used the result type stream in my action method which depends on an ajax call. This ajax call is activated on focus out of a textfield on my JSP. The function of this A

相关标签:
1条回答
  • 2021-01-24 22:01

    The error is logical: if you return an error result, or an error mapped to an exception, you are still returning a success result, because the relative httpheader (statusCode) will always be 200 (Success).

    It is an error only to you, the browser (and hence the jQuery callback function) can't know it is an error result.

    To enter the request.fail(function( jqXHR, textStatus ) { part, you need to send a different statusCode (4xx or 5xx), eg. 500 (Internal Server Error), otherwise you'll always enter the .done

    To do this in Struts2, you can use:

    1. the Struts2 JSON plugin returning the following result as described here:

      <result name="error" type="json">
          <param name="errorCode">500</param>
      </result>
      
    2. the Struts2 HttpHeader result. Due to an error, the documentation is not available right now; I've opened a JIRA ticket for it, meanwhile you can check the Javadoc:

      <result name="error" type="httpheader">
          <param name="error">500</param>
      </result>
      
    0 讨论(0)
提交回复
热议问题