org.apache.struts2.dispatcher
Class ServletRedirectResult

java.lang.Object
  extended by org.apache.struts2.dispatcher.StrutsResultSupport
      extended by org.apache.struts2.dispatcher.ServletRedirectResult
All Implemented Interfaces:
Result, Serializable, StrutsStatics
Direct Known Subclasses:
ServletActionRedirectResult

public class ServletRedirectResult
extends StrutsResultSupport

Calls the sendRedirect method to the location specified. The response is told to redirect the browser to the specified location (a new request from the client). The consequence of doing this means that the action (action instance, action errors, field errors, etc) that was just executed is lost and no longer available. This is because actions are built on a single-thread model. The only way to pass data is through the session or with web parameters (url?name=value) which can be OGNL expressions.

This result type takes the following parameters:

This result follows the same rules from StrutsResultSupport.

Example:

 <result name="success" type="redirect">
   <param name="location">foo.jsp</param>
   <param name="parse">false</param>
 </result>
 

See Also:
Serialized Form

Field Summary
protected  ActionMapper actionMapper
           
private static Logger LOG
           
protected  boolean prependServletContext
           
private static long serialVersionUID
           
protected  int statusCode
           
 
Fields inherited from class org.apache.struts2.dispatcher.StrutsResultSupport
DEFAULT_PARAM
 
Fields inherited from interface org.apache.struts2.StrutsStatics
HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_PORTLET_CONTEXT
 
Constructor Summary
ServletRedirectResult()
           
ServletRedirectResult(String location)
           
 
Method Summary
protected  void doExecute(String finalLocation, ActionInvocation invocation)
          Redirects to the location specified by calling HttpServletResponse.sendRedirect(String).
private static boolean isPathUrl(String url)
           
protected  void sendRedirect(HttpServletResponse response, String finalLocation)
          Sends the redirection.
 void setActionMapper(ActionMapper mapper)
           
 void setPrependServletContext(boolean prependServletContext)
          Sets whether or not to prepend the servlet context path to the redirected URL.
 void setStatusCode(int code)
           
 
Methods inherited from class org.apache.struts2.dispatcher.StrutsResultSupport
conditionalParse, execute, getLastFinalLocation, getLocation, setEncode, setLocation, setParse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

LOG

private static final Logger LOG

prependServletContext

protected boolean prependServletContext

actionMapper

protected ActionMapper actionMapper

statusCode

protected int statusCode
Constructor Detail

ServletRedirectResult

public ServletRedirectResult()

ServletRedirectResult

public ServletRedirectResult(String location)
Method Detail

setActionMapper

public void setActionMapper(ActionMapper mapper)

setStatusCode

public void setStatusCode(int code)

setPrependServletContext

public void setPrependServletContext(boolean prependServletContext)
Sets whether or not to prepend the servlet context path to the redirected URL.

Parameters:
prependServletContext - true to prepend the location with the servlet context path, false otherwise.

doExecute

protected void doExecute(String finalLocation,
                         ActionInvocation invocation)
                  throws Exception
Redirects to the location specified by calling HttpServletResponse.sendRedirect(String).

Specified by:
doExecute in class StrutsResultSupport
Parameters:
finalLocation - the location to redirect to.
invocation - an encapsulation of the action execution state.
Throws:
Exception - if an error occurs when redirecting.

sendRedirect

protected void sendRedirect(HttpServletResponse response,
                            String finalLocation)
                     throws IOException
Sends the redirection. Can be overridden to customize how the redirect is handled (i.e. to use a different status code)

Parameters:
response - The response
finalLocation - The location URI
Throws:
IOException

isPathUrl

private static boolean isPathUrl(String url)


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.