Class JSONActionRedirectResult

All Implemented Interfaces:
Serializable, Redirectable, Result, StrutsStatics, ReflectionExceptionHandler

public class JSONActionRedirectResult extends ServletActionRedirectResult implements Redirectable
Specialized form of ServletActionRedirectResult which takes care of situation that browser has a JS/AJAX context, there are no validation errors and action is executed. In this case a http redirect is harmful as browsers don't pass them to JS handlers. So this result produces a JSON response containing redirect data.

To be used along with JSONValidationInterceptor.

Response JSON looks like this:

{"location": "$redirect url$"}

See Also:
  • Constructor Details

    • JSONActionRedirectResult

      public JSONActionRedirectResult()
  • Method Details

    • sendRedirect

      protected void sendRedirect(jakarta.servlet.http.HttpServletResponse response, String finalLocation) throws IOException
      Overrides:
      sendRedirect in class ServletRedirectResult
      Throws:
      IOException
    • sendJsonInsteadOfRedirect

      protected boolean sendJsonInsteadOfRedirect()
      If browser has called action in a JS/AJAX context we cannot send a redirect as response.
      Returns:
      true if a JSON response shall be generated, false if a redirect shall be sent.
    • printJson

      protected void printJson(jakarta.servlet.http.HttpServletResponse response, String finalLocation) throws IOException
      Throws:
      IOException
    • isJsonEnabled

      protected boolean isJsonEnabled(jakarta.servlet.http.HttpServletRequest request)
    • isValidateOnly

      protected boolean isValidateOnly(jakarta.servlet.http.HttpServletRequest request)