public class ServletRedirectResult extends StrutsResultSupport implements ReflectionExceptionHandler, Redirectable
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:
<!-- The redirect URL generated will be: /foo.jsp#FRAGMENT --> <result name="success" type="redirect"> <param name="location">foo.jsp</param> <param name="parse">false</param> <param name="anchor">FRAGMENT</param> </result>
Modifier and Type | Field and Description |
---|---|
protected ActionMapper |
actionMapper |
protected String |
anchor |
protected boolean |
prependServletContext |
protected Map<String,Object> |
requestParameters |
protected int |
statusCode |
protected boolean |
suppressEmptyParameters |
DEFAULT_PARAM, DEFAULT_URL_ENCODING, parseLocation
HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION, STRUTS_PORTLET_CONTEXT
Constructor and Description |
---|
ServletRedirectResult() |
ServletRedirectResult(String location) |
ServletRedirectResult(String location,
String anchor) |
Modifier and Type | Method and Description |
---|---|
ServletRedirectResult |
addParameter(String key,
Object value)
Adds a request parameter to be added to the redirect url
|
protected void |
doExecute(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 List<String> |
getProhibitedResultParams() |
void |
handle(ReflectionException ex)
Handles a reflection exception
|
protected boolean |
isPathUrl(String url)
Checks if url is simple path or either full url
|
protected void |
sendRedirect(javax.servlet.http.HttpServletResponse response,
String finalLocation)
Sends the redirection.
|
void |
setActionMapper(ActionMapper mapper) |
void |
setAnchor(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 |
setSuppressEmptyParameters(boolean suppressEmptyParameters)
Sets the suppressEmptyParameters option
|
void |
setUrlHelper(UrlHelper urlHelper) |
conditionalParse, conditionalParseCollection, getLastFinalLocation, getLocation, setEncode, setLocation, setParse
protected boolean prependServletContext
protected ActionMapper actionMapper
protected int statusCode
protected boolean suppressEmptyParameters
protected String anchor
public ServletRedirectResult()
public ServletRedirectResult(String location)
public void setActionMapper(ActionMapper mapper)
public void setUrlHelper(UrlHelper urlHelper)
public void setStatusCode(int code)
public void setAnchor(String anchor)
anchor
- the anchor valuepublic void setPrependServletContext(boolean prependServletContext)
prependServletContext
- true to prepend the location with the servlet context path, false otherwise.public void execute(ActionInvocation invocation) throws Exception
StrutsResultSupport
StrutsResultSupport.doExecute(String, ActionInvocation)
after optionally evaluating the
location as an OGNL evaluation.execute
in interface Result
execute
in class StrutsResultSupport
invocation
- the execution state of the action.Exception
- if an error occurs while executing the result.protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception
HttpServletResponse.sendRedirect(String)
.doExecute
in class StrutsResultSupport
finalLocation
- the location to redirect to.invocation
- an encapsulation of the action execution state.Exception
- if an error occurs when redirecting.protected void sendRedirect(javax.servlet.http.HttpServletResponse response, String finalLocation) throws IOException
response
- The responsefinalLocation
- The location URIIOException
- in case of IO errorsprotected boolean isPathUrl(String url)
url
- stringpublic void setSuppressEmptyParameters(boolean suppressEmptyParameters)
suppressEmptyParameters
- The new value for this optionpublic ServletRedirectResult addParameter(String key, Object value)
key
- The parameter namevalue
- The parameter valuepublic void handle(ReflectionException ex)
ReflectionExceptionHandler
handle
in interface ReflectionExceptionHandler
ex
- The reflection exceptionCopyright © 2000–2020 Apache Software Foundation. All rights reserved.