Package org.apache.struts2.result
Class ServletRedirectResult
java.lang.Object
org.apache.struts2.result.StrutsResultSupport
org.apache.struts2.result.ServletRedirectResult
- All Implemented Interfaces:
- Serializable,- Redirectable,- Result,- StrutsStatics,- ReflectionExceptionHandler
- Direct Known Subclasses:
- ServletActionRedirectResult
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:
- 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. Also known as "fragment" or colloquially as "hash". You can specify an anchor for a result.
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>
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected ActionMapperprotected Stringprotected booleanprotected intprotected booleanFields inherited from class org.apache.struts2.result.StrutsResultSupportDEFAULT_PARAM, DEFAULT_URL_ENCODING, parseLocationFields inherited from interface org.apache.struts2.StrutsStaticsACTION_MAPPING, HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION
- 
Constructor SummaryConstructorsConstructorDescriptionServletRedirectResult(String location) ServletRedirectResult(String location, String anchor) 
- 
Method SummaryModifier and TypeMethodDescriptionaddParameter(String key, Object value) Adds a request parameter to be added to the redirect urlprotected voiddoExecute(String finalLocation, ActionInvocation invocation) Redirects to the location specified by callingHttpServletResponse.sendRedirect(String).voidexecute(ActionInvocation invocation) Implementation of the execute method from the Result interface.voidHandles a reflection exceptionprotected booleanChecks if url is simple path or either full urlprotected voidsendRedirect(jakarta.servlet.http.HttpServletResponse response, String finalLocation) Sends the redirection.voidsetActionMapper(ActionMapper mapper) voidSet the optional anchor value.voidsetPrependServletContext(boolean prependServletContext) Sets whether or not to prepend the servlet context path to the redirected URL.voidsetQueryStringBuilder(QueryStringBuilder queryStringBuilder) voidsetStatusCode(int code) voidsetSuppressEmptyParameters(boolean suppressEmptyParameters) Sets the suppressEmptyParameters optionMethods inherited from class org.apache.struts2.result.StrutsResultSupportconditionalParse, conditionalParseCollection, getLastFinalLocation, getLocation, setEncode, setLocation, setParse
- 
Field Details- 
prependServletContextprotected boolean prependServletContext
- 
actionMapper
- 
statusCodeprotected int statusCode
- 
suppressEmptyParametersprotected boolean suppressEmptyParameters
- 
requestParameters
- 
anchor
 
- 
- 
Constructor Details- 
ServletRedirectResultpublic ServletRedirectResult()
- 
ServletRedirectResult
- 
ServletRedirectResult
 
- 
- 
Method Details- 
setActionMapper
- 
setQueryStringBuilder
- 
setStatusCodepublic void setStatusCode(int code) 
- 
setAnchorSet the optional anchor value.- Parameters:
- anchor- the anchor value
 
- 
setPrependServletContextpublic 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.
 
- 
executeDescription copied from class:StrutsResultSupportImplementation of the execute method from the Result interface. This will call the abstract methodStrutsResultSupport.doExecute(String, ActionInvocation)after optionally evaluating the location as an OGNL evaluation.- Specified by:
- executein interface- Result
- Overrides:
- executein class- StrutsResultSupport
- Parameters:
- invocation- the execution state of the action.
- Throws:
- Exception- if an error occurs while executing the result.
 
- 
doExecuteRedirects to the location specified by callingHttpServletResponse.sendRedirect(String).- Specified by:
- doExecutein 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.
 
- 
getProhibitedResultParams
- 
sendRedirectprotected void sendRedirect(jakarta.servlet.http.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- in case of IO errors
 
- 
isPathUrlChecks if url is simple path or either full url- Parameters:
- url- string
- Returns:
- true if it's just a path not a full url
 
- 
setSuppressEmptyParameterspublic void setSuppressEmptyParameters(boolean suppressEmptyParameters) Sets the suppressEmptyParameters option- Parameters:
- suppressEmptyParameters- The new value for this option
 
- 
addParameterAdds a request parameter to be added to the redirect url- Parameters:
- key- The parameter name
- value- The parameter value
- Returns:
- the servlet redirect result
 
- 
handleDescription copied from interface:ReflectionExceptionHandlerHandles a reflection exception- Specified by:
- handlein interface- ReflectionExceptionHandler
- Parameters:
- ex- The reflection exception
 
 
-