说明
本文主要讲解Struts2的结果类型
struts.xml部分
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="login.action.LoginAction" extends="struts-default" namespace="/">
<default-action-ref name="login"/>
<action name="login" class="login.action.LoginAction" method="index">
<result name="login" type="dispatcher">/index.jsp</result>
</action>
<action name="*_*_*" class="{1}.action.{2}Action" method="{3}">
<result name="success" type="dispatcher">/login/login.jsp</result>
<result name="login" type="dispatcher">/index.jsp</result>
</action>
</package>
</struts>
struts-default.xml涉及到type类型(struts.xml中的result 的type属性)
<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>
- chain Action链式处理结果类型 ,表示的是一个转发的关系,是在一个请求里面。一般情况下,当处理完一个action 之后会直接返回页面,输出结果。但也会存在当一个action处理完后,会直接跳到下一个action进行处理,这时候就会用到chain。
- dispatcher 默认的请求转发的结果类型
- redirect 重定向,重定向到一个路径信息,路径信息没有限制(不在一个请求中)
- redirectAction 重定向到某个action上面