Class JSONActionRedirectResult

java.lang.Object
org.apache.struts2.result.StrutsResultSupport
org.apache.struts2.result.ServletRedirectResult
org.apache.struts2.result.ServletActionRedirectResult
org.apache.struts2.json.JSONActionRedirectResult
All Implemented Interfaces:
com.opensymphony.xwork2.Result, com.opensymphony.xwork2.util.reflection.ReflectionExceptionHandler, Serializable, org.apache.struts2.result.Redirectable, org.apache.struts2.StrutsStatics

public class JSONActionRedirectResult extends org.apache.struts2.result.ServletActionRedirectResult implements org.apache.struts2.result.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:
  • Field Summary

    Fields inherited from class org.apache.struts2.result.ServletActionRedirectResult

    actionName, DEFAULT_PARAM, method, namespace

    Fields inherited from class org.apache.struts2.result.ServletRedirectResult

    actionMapper, anchor, prependServletContext, requestParameters, statusCode, suppressEmptyParameters

    Fields inherited from class org.apache.struts2.result.StrutsResultSupport

    DEFAULT_URL_ENCODING, parseLocation

    Fields inherited from interface org.apache.struts2.StrutsStatics

    ACTION_MAPPING, HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    isJsonEnabled(jakarta.servlet.http.HttpServletRequest request)
     
    protected boolean
    isValidateOnly(jakarta.servlet.http.HttpServletRequest request)
     
    protected void
    printJson(jakarta.servlet.http.HttpServletResponse response, String finalLocation)
     
    protected boolean
    If browser has called action in a JS/AJAX context we cannot send a redirect as response.
    protected void
    sendRedirect(jakarta.servlet.http.HttpServletResponse response, String finalLocation)
     

    Methods inherited from class org.apache.struts2.result.ServletActionRedirectResult

    execute, getProhibitedResultParams, setActionName, setMethod, setNamespace

    Methods inherited from class org.apache.struts2.result.ServletRedirectResult

    addParameter, doExecute, handle, isPathUrl, setActionMapper, setAnchor, setPrependServletContext, setQueryStringBuilder, setStatusCode, setSuppressEmptyParameters

    Methods inherited from class org.apache.struts2.result.StrutsResultSupport

    conditionalParse, conditionalParseCollection, getLastFinalLocation, getLocation, setEncode, setLocation, setParse

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.opensymphony.xwork2.util.reflection.ReflectionExceptionHandler

    handle
  • Constructor Details

    • JSONActionRedirectResult

      public JSONActionRedirectResult()
  • Method Details

    • sendRedirect

      protected void sendRedirect(jakarta.servlet.http.HttpServletResponse response, String finalLocation) throws IOException
      Overrides:
      sendRedirect in class org.apache.struts2.result.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)