Strut2中Action的Result部类
Strut2中Action的Result类型
Jsp页面代码
resultType01.jsp部分代码
resultType02.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>
<body> dispatcher Type!!! <br> </body>
<body> redirect Type!!!! <br> </body>