org.apache.struts2.json

## 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:
    Result, ReflectionExceptionHandler, Serializable, Redirectable, StrutsStatics

      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:
    Serialized Form

- - ### 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, STRUTS_PORTLET_CONTEXT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JSONActionRedirectResult()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected boolean` | `isJsonEnabled(javax.servlet.http.HttpServletRequest request)`
    `protected boolean` | `isValidateOnly(javax.servlet.http.HttpServletRequest request)`
    `protected void` | `printJson(javax.servlet.http.HttpServletResponse response, String finalLocation)`
    `protected boolean` | `sendJsonInsteadOfRedirect()` If browser has called action in a JS/AJAX context we cannot send a redirect as response.
    `protected void` | `sendRedirect(javax.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 Detail

    - #### JSONActionRedirectResult

          public JSONActionRedirectResult()

  - ### Method Detail

    - #### sendRedirect

          protected void sendRedirect(javax.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(javax.servlet.http.HttpServletResponse response,
                                   String finalLocation)
                            throws IOException

      Throws:
        `IOException`

    - #### isJsonEnabled

          protected boolean isJsonEnabled(javax.servlet.http.HttpServletRequest request)

    - #### isValidateOnly

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

Copyright © 2000–2022 Apache Software Foundation. All rights reserved.