org.apache.struts2.json
Class JSONActionRedirectResult

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

public class JSONActionRedirectResult
extends ServletActionRedirectResult

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.dispatcher.ServletActionRedirectResult
actionName, DEFAULT_PARAM, method, namespace
 
Fields inherited from class org.apache.struts2.dispatcher.ServletRedirectResult
actionMapper, anchor, prependServletContext, requestParameters, statusCode, suppressEmptyParameters
 
Fields inherited from class org.apache.struts2.dispatcher.StrutsResultSupport
DEFAULT_URL_ENCODING
 
Fields inherited from interface org.apache.struts2.StrutsStatics
HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION, STRUTS_PORTLET_CONTEXT
 
Constructor Summary
JSONActionRedirectResult()
           
 
Method Summary
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.dispatcher.ServletActionRedirectResult
execute, getProhibitedResultParams, setActionName, setMethod, setNamespace
 
Methods inherited from class org.apache.struts2.dispatcher.ServletRedirectResult
addParameter, doExecute, handle, isPathUrl, setActionMapper, setAnchor, setPrependServletContext, setStatusCode, setSuppressEmptyParameters, setUrlHelper
 
Methods inherited from class org.apache.struts2.dispatcher.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-2017 Apache Software Foundation. All Rights Reserved.