First, result
When the action finishes processing the user request, it returns a normal string, the entire normal string is a logical view name, STRUTS2 determines which result to respond to according to the logical view name, and processes the result using the <result> element configuration.
Local results: Configure <result> as the <action> child element.
Global Results: configures <result> as a child element of the <global-results> element.
Configuration <result> elements to specify two properties.
Name: This property specifies the configuration logical view name.
Type: Specifies the result type.
1. Global results
When the same result is used in more than one action, we should define result as a global result.
<package name= "user" extends= "struts-default" ><!--Configure global results--><global-results><result name= " Error ">/index.jsp</result></global-results><action name=" resultaction "class=" Com.kiwi.action.ResultAction "></action></package>
2. Result types
<result-types> <result-type name= "Chain" class= "Com.opensymphony.xwork2.ActionChainResult"/> ; <result-type name= "Dispatcher" class= "Org.apache.struts2.dispatcher.ServletDispatcherResult" default= "true"/ > <result-type name= "freemarker" class= "Org.apache.struts2.views.freemarker.FreemarkerResult"/> <result-type name= "Httpheader" class= "Org.apache.struts2.dispatcher.HttpHeaderResult"/> <result-t ype name= "redirect" class= "Org.apache.struts2.dispatcher.ServletRedirectResult"/> <result-type name= "Redi Rectaction "class=" Org.apache.struts2.dispatcher.ServletActionRedirectResult "/> <result-type name=" stream "class=" Org.apache.struts2.dispatcher.StreamResult "/> <result-type name=" Velocity "class=" org.apache.str Uts2.dispatcher.VelocityResult "/> <result-type name=" xslt "class=" Org.apache.struts2.views.xslt.XSLTResul T "/> < Result-type name= "plaintext" class= "Org.apache.struts2.dispatcher.PlainTextResult"/> </result-types>
(1) Dispatcher
The request is forwarded to a page. The dispatcher result type is the most commonly used result type and is also the STRUTS2 default result type. The result type has a location parameter, which is the default parameter.
(2) redirect
The request is redirected to a page. The redirect result type redirects the response to another resource, rather than to the resource.
(3) Chain
The request is forwarded to another action.
The redirectaction result type accepts the following parameters:
ActionName: Specifies the name of the "destination" action. It is the default property.
namespace: The namespace used to specify the "destination" action. If this parameter is not configured, Struts will use the namespace where the current Action is located as the "destination" namespace.
If you want to forward to another package and the package has NAMESAPCE, you can write this.
<package name= "user" extends= "struts-default" ><action name= "Act1" class= "Com.kiwi.action.ResultAction" ><result name= "Success" type= "Chain" ><param name= "namespace" >/test</param><param name= " ActionName ">act2</param></result></action></package><package name=" Server " Namespace= "/test" extends= "Struts-default" ><action name= "Act2" ><result name= "Success" >/success.jsp </result></action></package>
(4) Redirectaction
Request redirect to another action, same as above.
(5) Stream
Download it for later.
(6) PlainText
The content is presented in plain text form.
STRUTS2 Basic Learning (iii)-result and model-driven