Struts2 result type:
<action name="loginAction" class="com.itheima.action.LoginAction"><result name="success" <strong><span style="color:#FF6666;">type="chain"</span></strong>><param name="actionName">successAction</param><param name="name">${name}</param></result></action>The result types in struts2 are as follows:
<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-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/> <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/> <result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/> <result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/> <result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/> <result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" /> <result-type name="postback" class="org.apache.struts2.dispatcher.PostbackResult" /> </result-types>
There are several important types:
Dispatcher -- the request is forwarded to a page (default) and cannot be forwarded to an action in this way.
Chain -- forward an action request to another action
Redirect -- redirect a response to a page, or redirect a response to an action
Redirectaction -- redirect an action response to another action
Stream -- File Download
Note:: If the result type is changed to type = "chain", adding the parameters that carry will not work, because chain is a request forwarding and is still in a request, the parameter is included in the request, and does not need to be declared or added. It does not work because the information of the request is fixed after the form is submitted.
Response redirection prevents repeated submission of forms
Generally, action is redirected to JSP, but sometimes it is redirected to another action.
First, let's take a look at loginaction. Java
Package COM. itheima. action; public class loginaction {private string name; Public String getname () {return name;} Public String execute () {// The name is fixed, so setxxx () is not required () method Name = "LCL"; Return "success ";}}
Successaction. Java
package com.itheima.action;public class SuccessAction {private String name;public String getName() {return name;}public void setName(String name) {this.name = name;}public String execute() {return "success";}}
You can use the following methods to pass parameters during redirection:
<action name="loginAction" class="com.itheima.action.LoginAction"><result type="redirect">successAction?name=${name}</result> </action><action name="successAction" class="com.itheima.action.SuccessAction"><result type="redirect">/login.jsp?name=${name}</result></action>
<action name="loginAction" class="com.itheima.action.LoginAction"><result type="redirectAction">successAction?name=${name}</result></action><action name="successAction" class="com.itheima.action.SuccessAction"><result type="redirect">/login.jsp?name=${name}</result></action>
<action name="loginAction" class="com.itheima.action.LoginAction"><result type="redirectAction"><param name="actionName">successAction</param><param name="name">${name}</param></result></action><action name="successAction" class="com.itheima.action.SuccessAction"><result type="redirect">/login.jsp?name=${name}</result></action>However, the following configuration does not work:
<action name="loginAction" class="com.itheima.action.LoginAction"><result type="redirect"><param name="actionName">successAction</param><param name="name">${name}</param></result></action><action name="successAction" class="com.itheima.action.SuccessAction"><result type="redirect">/login.jsp?name=${name}</result></action>
Struts2 action redirection