type="dispatcher" 只是跳转,没有重定向
type="redirect" 重定向type="chain" 可以直接反问aciton不是重定向
type="redirectAction" 直接result的值可以是一个Action是重定向
Jsp页面代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
Result类型
<ol>
<li><a href="r/r1">dispatcher</a></li>
<li><a href="r/r2">redirect</a></li>
<li><a href="r/r3">chain</a></li>
<li><a href="r/r4">redirectAction</a></li>
<li>freemarker</li>
<li>httpheader</li>
<li>stream</li>
<li>velocity</li>
<li>xslt</li>
<li>plaintext</li>
<li>tiles</li>
</ol>
</body>
</html>
struts.xml文件的配置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>
<package name="login" extends="struts-default" namespace="/r">
<action name="r1">
<result type="dispatcher">/resultType01.jsp</result>
</action>
<action name="r2">
<result type="redirect">/resultType02.jsp</result>
</action>
<!-- 直接result的值是一个Action不是重定向 -->
<action name="r3">
<result type="chain">r1</result>
</action>
<!-- 直接result的值是一个Action是重定向 -->
<action name="r4">
<result type="redirectAction">r2</result>
</action>
</package>
</struts>
resultType01.jsp部分代码
<body>
dispatcher Type!!! <br>
</body>
resultType02.jsp部分代码
<body>
redirect Type!!!! <br>
</body>