Class StrutsResultSupport
- All Implemented Interfaces:
- Serializable,- Result,- StrutsStatics
- Direct Known Subclasses:
- FreemarkerResult,- PlainTextResult,- PostbackResult,- ServletDispatcherResult,- ServletRedirectResult,- StreamResult
A base class for all Struts action execution results. The "location" param is the default parameter, meaning the most common usage of this result would be:
This class provides two common parameters for any subclass:
- location - the location to go to after execution (could be a jsp page or another action).
 It can be parsed as per the rules definied in the
 translateVariablesmethod
- parse - true by default. If set to false, the location param will not be parsed for expressions
- encode - false by default. If set to false, the location param will not be url encoded. This only have effect when parse is true
NOTE: The encode param will only have effect when parse is true
In the struts.xml configuration file, these would be included as:
  <result name="success" type="redirect">
      <param name="location">foo.jsp</param>
  </result>
 or
 
  <result name="success" type="redirect" >
      <param name="location">foo.jsp?url=${myUrl}</param>
      <param name="parse">true</param>
      <param name="encode">true</param>
  </result>
 
 In the above case, myUrl will be parsed against Ognl Value Stack and then URL encoded.1
or when using the default parameter feature
<result name="success" type="redirect">foo.jsp</result>
 You should subclass this class if you're interested in adding more parameters or functionality
 to your Result. If you do subclass this class you will need to
 override doExecute(String, ActionInvocation).
 
Any custom result can be defined in struts.xml as:
  <result-types>
      ...
      <result-type name="myresult" class="com.foo.MyResult" />
  </result-types>
 
 
 Please see the Result class for more info on Results in general.
 
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringThe default parameterstatic final Stringuse UTF-8 as this is the recommended encoding by W3C to avoid incompatibilities.protected booleanFields inherited from interface org.apache.struts2.StrutsStaticsACTION_MAPPING, HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION
- 
Constructor SummaryConstructorsConstructorDescriptionStrutsResultSupport(String location) StrutsResultSupport(String location, boolean parse, boolean encode) 
- 
Method SummaryModifier and TypeMethodDescriptionprotected StringconditionalParse(String param, ActionInvocation invocation) Parses the parameter for OGNL expressions against the valuestackprotected Collection<String>conditionalParseCollection(String param, ActionInvocation invocation, boolean excludeEmptyElements) AsconditionalParse(String, ActionInvocation)but does not convert found object into String.protected abstract voiddoExecute(String finalLocation, ActionInvocation invocation) Executes the result given a final location (jsp page, action, etc) and the action invocation (the state in which the action was executed).voidexecute(ActionInvocation invocation) Implementation of the execute method from the Result interface.Returns the last parsed and encoded location valueGets the location it was created with, mainly for testingvoidsetEncode(boolean encode) Set encode to true to indicate that the location should be url encoded.voidsetLocation(String location) The location to go to after action execution.voidsetParse(boolean parse) Set parse to true to indicate that the location should be parsed as an OGNL expression.
- 
Field Details- 
DEFAULT_PARAMThe default parameter- See Also:
 
- 
DEFAULT_URL_ENCODINGuse UTF-8 as this is the recommended encoding by W3C to avoid incompatibilities.- See Also:
 
- 
parseLocationprotected boolean parseLocation
 
- 
- 
Constructor Details- 
StrutsResultSupportpublic StrutsResultSupport()
- 
StrutsResultSupport
- 
StrutsResultSupport
 
- 
- 
Method Details- 
setLocationThe location to go to after action execution. This could be a JSP page or another action. The location can contain OGNL expressions which will be evaulated if the parse parameter is set to true.- Parameters:
- location- the location to go to after action execution.
- See Also:
 
- 
getLocationGets the location it was created with, mainly for testing- Returns:
- the location
 
- 
getLastFinalLocationReturns the last parsed and encoded location value- Returns:
- the last final location
 
- 
setParsepublic void setParse(boolean parse) Set parse to true to indicate that the location should be parsed as an OGNL expression. This is set to true by default.- Parameters:
- parse- true if the location parameter is an OGNL expression, false otherwise.
 
- 
setEncodepublic void setEncode(boolean encode) Set encode to true to indicate that the location should be url encoded. This is set to true by default- Parameters:
- encode- true if the location parameter should be url encode, false otherwise.
 
- 
executeImplementation of the execute method from the Result interface. This will call the abstract methoddoExecute(String, ActionInvocation)after optionally evaluating the location as an OGNL evaluation.
- 
conditionalParseParses the parameter for OGNL expressions against the valuestack- Parameters:
- param- The parameter value
- invocation- The action invocation instance
- Returns:
- the resulting string
 
- 
conditionalParseCollectionprotected Collection<String> conditionalParseCollection(String param, ActionInvocation invocation, boolean excludeEmptyElements) AsconditionalParse(String, ActionInvocation)but does not convert found object into String. If found object is a collection it is returned if found object is not a collection it is wrapped in one.- Parameters:
- param- parameter
- invocation- action invocation
- excludeEmptyElements- 'true' for excluding empty elements
- Returns:
- the parsed collection of strings
 
- 
doExecuteprotected abstract void doExecute(String finalLocation, ActionInvocation invocation) throws Exception Executes the result given a final location (jsp page, action, etc) and the action invocation (the state in which the action was executed). Subclasses must implement this class to handle custom logic for result handling.- Parameters:
- finalLocation- the location (jsp page, action, etc) to go to.
- invocation- the execution state of the action.
- Throws:
- Exception- if an error occurs while executing the result.
 
 
-