When the action class's method processes the request, it returns a string (the logical view name), which selects the corresponding result from the results code, and outputs it to the user, so it is necessary to provide the <result> element definition result page in Struts.xml. This result page can be either a local result page or a global results page.
1. Local results page and global results page
1) Local results page
1 <Actionname= "Result"class= "Cn.sunny.action.ResultAction">2 <!--Local result current action use -3 <resultname= "Success">/result.jsp</result> 4 </Action>
2) Global Results Page
1 < global-results > 2 <!-- Global results all actions in the current package are available with the --> 3 name = "Success" > /result.jsp</ result Span style= "color: #0000ff;" >> 4 </ global-results >
- If the STRUTS2 program finds information or type conversion failures or input checksum failures in Addfielderror () during the run, it will automatically jump to the result page with the name value of input, if the name value of input is not provided. <result>, then an error occurs, the 404 error will be prompted directly in the browser;
- If the form in a JSP page is written in normal <form>, the original data disappears when an error occurs and the page is returned
- If the form is written in <s:form> on a JSP page, and the page is returned when an error occurs, the original data still exists
2. Result page Jump type
The struts-default.xml defines some of the result page types for the type attribute in <result>, the default type type is dispatcher forwarding, and the type attribute is:
1 <Result-types>2 <!--to handle the action chain -3 <Result-typename= "Chain"class= "Com.opensymphony.xwork2.ActionChainResult"/>4 <!--used to turn to the page, usually working with JSPs -5 <Result-typename= "Dispatcher"class= "Org.apache.struts2.dispatcher.ServletDispatcherResult"default= "true"/>6 <!--working with Freemarker templates -7 <Result-typename= "Freemarker"class= "Org.apache.struts2.views.freemarker.FreemarkerResult"/>8 <!--The result type that controls the special HTTP behavior -9 <Result-typename= "Httpheader"class= "Org.apache.struts2.dispatcher.HttpHeaderResult"/>Ten <!--redirect to a URL - One <Result-typename= "Redirect"class= "Org.apache.struts2.dispatcher.ServletRedirectResult"/> A <!--REDIRECT to an Action - - <Result-typename= "Redirectaction"class= "Org.apache.struts2.dispatcher.ServletActionRedirectResult"/> - <!--sends a Inputsream object to the browser, which is typically used to process file downloads and also to return AJAX data. - the <Result-typename= "Stream"class= "Org.apache.struts2.dispatcher.StreamResult"/> - <!--working with Velocity templates - - <Result-typename= "Velocity"class= "Org.apache.struts2.dispatcher.VelocityResult"/> - <!--working with Xml/xlst templates - + <Result-typename= "XSLT"class= "Org.apache.struts2.views.xslt.XSLTResult"/> - <!--Display source file contents, such as file source - + <Result-typename= "PlainText"class= "Org.apache.struts2.dispatcher.PlainTextResult" /> A </Result-types>
So the type attribute can take the following values: chain, Dispatcher, Freemarker, Httpheader, redirect, redirectaction, stream, velocity, XSLT, plaintext.
STRUTS2 Study Notes (iv)--result result type