dispatcher 默认
redirect
redirectAction
plainText
dispatcher默认方式:
struts.xml:
<package name="base" extends="struts-default">
<global-results> //全局
<result name="message">/WEB-INF/page/message.jsp</result>
</global-results>
</package>
<package name="itcast" namespace="/control/employee" extends="base"> //继承base
<action name="list" class="cn.itcast.action.HelloWorldAction" method="execute">
<result name="success">/employeeAdd.jsp?username=${username}</result> //${}访问action中属性
</action>
</package>
访问http://localhost:8080/struts2/control/employee/list,浏览器url地址不变
redirect:
struts.xml:
<package name="itcast" namespace="/control/employee" extends="base">
<action name="list" class="cn.itcast.action.HelloWorldAction" method="execute">
<result name="success" type="redirect">/employeeAdd.jsp?username=${username}</result>
</action>
</package>
地址浏览器url变化:http://localhost:8080/struts2/employeeAdd.jsp?username=liming
重定向到指定action,redirectAction:
<action name="redirectAction">
<result type="redirectAction">list</result>
</action>
如果action在其他包中
<action name="redirectAction">
<result type="redirectAction">
<param name="actionName">helloWorld</param> //重定向action名字
<param name="namespace">/test</param> //重定向action的namespace
</result>
</action>
plainText,打印源代码:
<action name="plainText">
<result type="plainText">
<param name="location">/index.jsp</param>
<param name="charSet">UTF-8</param>
</result>
</action>