<?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>
<!-- struts.xml檔建議分而治之,意旨分工寫在xml檔中後再引入 -->
<!-- 可以用<include file="xx.xml" />的方式來引入設定,使<struts>檔不會太肥大 -->
<constant name="struts.devMode" value="true" />
<!-- struts.devMode代表是開發模式,正式上線時要改成false -->
<!-- 同功能的action會宣告在同一個package裡面 ,package可以互相繼承如下extends="struts-default" -->
<!-- struts-default被定義在lib\struts2-core-xxx.jar中的struts-default.xml中 -->
<!-- abstract預設值為false,如果設成true則此package只能被繼承,裡面不能有任何action設定 -->
<package name="myPackage" namespace="/myNamespace" extends="struts-default">
<!-- 以下是全域設定,例如每個頁面如果出現識別字error都要導向同一個頁面,那就乾脆設一個全域的, -->
<!-- struts會先找找看對應action中有沒有同樣的識別字,接下來就會來找全域了 -->
<!-- 因為某種DTD規定,所以package裡面的元素排列順序為: -->
<!-- (result-types?,interceptors?,default-interceptor-ref?,default-action-ref?, -->
<!-- default-class-ref?,global-results?,global-exception-mappings?,action*)". -->
<!-- 因此global要排在action上面 -->
<global-results>
<result name="error">/Error.jsp</result>
<result name="login.jsp" type="redirectAction">Login!input</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="error" exception="java.lang.Exception" />
</global-exception-mappings>
<!-- namespace="/myNamespace"可以不寫,系統會自己先找namespace="/myNamespace"有沒有myAction方法,之後再找namespace="" -->
<!-- 中有沒有myAction方法 ,也可以寫成namespace="/" ,不同的package可以有相同的namespace -->
<action name="myAction" class="com.action.HelloAction">
<!-- name不可省略,不可重複 -->
<result name="success">/hello.jsp</result>
<!-- result是呼應action的回傳值success,並指定一個view為/hello.jsp -->
<!-- type=dispatcher相當於forward(),此為預設值可略 -->
<!-- type=redirect,相當於使用sendRedirect() -->
<!-- 以上兩個是比較常用的,以下是所有的,都寫在struts-defult.xml檔中 -->
<!-- <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-types> -->
</action>
</package>
</struts>