Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.struts2.dispatcher
Class ServletRedirectResult

    java.lang.Object
      org.apache.struts2.dispatcher.StrutsResultSupport
          org.apache.struts2.dispatcher.ServletRedirectResult

All Implemented Interfaces:
  Result, ReflectionExceptionHandler, java.io.Serializable, StrutsStatics

Direct Known Subclasses:
  ServletActionRedirectResult

    public class ServletRedirectResult

extends StrutsResultSupport
implements ReflectionExceptionHandler

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:

- location (default) - the location to go to after execution.
- parse - true by default. If set to false, the location param will not be parsed for Ognl expressions.
- anchor - optional, you can specify an anchor for result.

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>
       <param name="anchor">FRAGMENT</param>
     </result>

See Also:
  Serialized Form

Field Summary
`protected ActionMapper` | `actionMapper`
`protected java.lang.String` | `anchor`
`protected boolean` | `prependServletContext`
`protected java.util.Map<java.lang.String,java.lang.String>` | `requestParameters`
`protected int` | `statusCode`
`protected boolean` | `supressEmptyParameters`

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

Constructor Summary
`ServletRedirectResult()`
`ServletRedirectResult(java.lang.String location)`
`ServletRedirectResult(java.lang.String location, java.lang.String anchor)`

Method Summary
`ServletRedirectResult` | `addParameter(java.lang.String key, java.lang.Object value)` Adds a request parameter to be added to the redirect url
`protected void` | `doExecute(java.lang.String finalLocation, ActionInvocation invocation)` Redirects to the location specified by calling `HttpServletResponse.sendRedirect(String)`.
`void` | `execute(ActionInvocation invocation)` Implementation of the `execute` method from the `Result` interface.
`protected java.util.List<java.lang.String>` | `getProhibitedResultParams()`
`void` | `handle(ReflectionException ex)`
`protected void` | `sendRedirect(javax.servlet.http.HttpServletResponse response, java.lang.String finalLocation)` Sends the redirection.
`void` | `setActionMapper(ActionMapper mapper)`
`void` | `setAnchor(java.lang.String anchor)` Set the optional anchor value.
`void` | `setPrependServletContext(boolean prependServletContext)` Sets whether or not to prepend the servlet context path to the redirected URL.
`void` | `setStatusCode(int code)`
`void` | `setSupressEmptyParameters(boolean supressEmptyParameters)` Sets the supressEmptyParameters option

Methods inherited from class org.apache.struts2.dispatcher.StrutsResultSupport
`conditionalParse, 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

### prependServletContext

    protected boolean prependServletContext

### actionMapper

    protected ActionMapper actionMapper

### statusCode

    protected int statusCode

### supressEmptyParameters

    protected boolean supressEmptyParameters

### requestParameters

    protected java.util.Map<java.lang.String,java.lang.String> requestParameters

### anchor

    protected java.lang.String anchor

Constructor Detail

### ServletRedirectResult

    public ServletRedirectResult()

### ServletRedirectResult

    public ServletRedirectResult(java.lang.String location)

### ServletRedirectResult

    public ServletRedirectResult(java.lang.String location,
                                 java.lang.String anchor)

Method Detail

### setActionMapper

    public void setActionMapper(ActionMapper mapper)

### setStatusCode

    public void setStatusCode(int code)

### setAnchor

    public void setAnchor(java.lang.String anchor)

  Set the optional anchor value.

  Parameters:
    `anchor` -

### 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.

### execute

    public void execute(ActionInvocation invocation)
                 throws java.lang.Exception

  Description copied from class: `StrutsResultSupport`
  Implementation of the `execute` method from the `Result` interface. This will call the abstract method `StrutsResultSupport.doExecute(String, ActionInvocation)` after optionally evaluating the location as an OGNL evaluation.

  Specified by:
    `execute` in interface `Result`
  Overrides:
    `execute` in class `StrutsResultSupport`
  Parameters:
    `invocation` - the execution state of the action.
  Throws:
    `java.lang.Exception` - if an error occurs while executing the result.

### doExecute

    protected void doExecute(java.lang.String finalLocation,
                             ActionInvocation invocation)
                      throws java.lang.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:
    `java.lang.Exception` - if an error occurs when redirecting.

### getProhibitedResultParams

    protected java.util.List<java.lang.String> getProhibitedResultParams()

### sendRedirect

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

### setSupressEmptyParameters

    public void setSupressEmptyParameters(boolean supressEmptyParameters)

  Sets the supressEmptyParameters option

  Parameters:
    `supressEmptyParameters` - The new value for this option

### addParameter

    public ServletRedirectResult addParameter(java.lang.String key,
                                              java.lang.Object value)

  Adds a request parameter to be added to the redirect url

  Parameters:
    `key` - The parameter name
    `value` - The parameter value

### handle

    public void handle(ReflectionException ex)

  Specified by:
    `handle` in interface `ReflectionExceptionHandler`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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