struts中的重定向轉發功能配置文件的撰寫

//Demo1Action.javahtml

package com.struts.a_result;

import com.opensymphony.xwork2.ActionSupport;

public class Demo1Action extends ActionSupport {
	
	
	@Override
	public String execute() throws Exception {

		return "SUCCESS";
	}
	
	

}

//struts.xmljava

<?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>
	<!-- 可配置的常量 -->
	<!-- i18n:國際化  解決post的提交亂碼和輸出中文亂碼 -->
	<constant name="struts.i18n.encoding" value="UTF-8"></constant>
	<!-- 指定反問action時的後綴名 
		http://localhost:8080/Struts2_test1/hello/HelloAction.xhtml
	-->
	<constant name="struts.action.extension" value="action"></constant>
	<!-- 指定struts2是否以開發模式運行
			1.熱加載主配置.(不須要重啓便可生效)
			2.提供更多錯誤信息輸出,方便開發時的調試
	 -->
	<constant name="struts.devMode" value="true"></constant>
	
	<package name="SSDA1" namespace="/" extends="struts-default" >
	
		<action name="Demo1Action" class="com.struts.a_result.Demo1Action" method="execute" >
			<result name="SUCCESS" type="dispatcher" >/hello.jsp</result><!-- type="dispatcher" 默認爲轉發 -->
		</action>
		
		<!-- 重定向 -->
		<action name="Demo2Action" class="com.struts.a_result.Demo2Action" method="execute" >
			<result name="SUCCESS" type="redirect" >/hello.jsp</result><!-- type="dispatcher" 默認爲轉發 -->
		</action>
		
		<!-- 重定向到Action -->
		<action name="Demo3Action" class="com.struts.a_result.Demo3Action" method="execute" >
			<result  name="SUCCESS"  type="redirectAction">
				 <!-- action的名字 -->
	             <param name="actionName">Demo1Action</param>
	             <!-- action所在的命名空間 -->
	             <param name="namespace">/</param>
            </result>
		</action>
		
		
	</package>
	
	
	
	<!-- <include file=""></include>com/struts2/b_dynamic/struts.xml -->
</struts>
相關文章
相關標籤/搜索