struts2配置文件

在struts.xml中可以定義bean,include,package,constant

bean 配置組件,可參考

(struts.xml文件之Bean的配置)http://blog.163.com/artsn@126/blog/static/36533281201111511381316/

include 把其他配置文件包含進來,可以避免一個struts.xml中內容過多導致不便維護和開發.

constant 設置struts2的常量   和在struts.properties中一樣 也可以在web.xml中設置

參考:

struts.xml文件之常量的配置http://blog.163.com/artsn@126/blog/static/3653328120111150503558/

struts2常量詳解http://riddickbryant.iteye.com/blog/557373

package 功能的集合 action

         包含:(result-types?,interceptors?, default-interceptor-ref?, default-action-ref?, default-

 class-ref?, global-results?,global-exception-mappings?, action*)

 

package的幾個注意點:

name不可以重複,僅僅是個標識,類似id便與讓其他包使用例如繼承

namespace 不填寫默認爲“”,“”表示是默認的命名空間,多個包可以有相同的命名空間。在一個命名空間中不能有相同名字的action

 

先舉個幾個例子

頁面發出請求/test/hello.action,

struts2會在命名空間名字爲/test中找名字爲hello的action

如果找不到就在默認的命名空間“”中,找名字爲 hello的action

如果還還找不到,就報錯

        

頁面發出請求/test/book/hello/abc/hello.action,

那麼struts2會在命名空間名字爲/test/book/hello/abc中找名字爲hello的action,

如果找不到就在默認的命名空間“”中,找名字爲 hello的action,

如果還還找不到,就報錯

 

         頁面發出請求/hello.action

那麼struts2會在命名空間名字爲/中找名字爲hello的action

如果找不到就在默認的命名空間“”中,找名字爲 hello的action,

如果還還找不到,就報錯

(通常把命名空間爲“/”的叫根命名空間)

 

result-types 結果處理類型,可以自己添加,一般不用,直接使用struts-default中的即可,

關於那些結果類型的介紹:參考http://blog.csdn.net/thunder_1985/article/details/4551071

如果返回類型是json,那麼參考http://yshjava.iteye.com/blog/1333104

基於Struts2Result Type爲chain的Action之間數據傳遞

                                                                 http://wenku.baidu.com/view/0ce52969a98271fe910ef9f4.html

interceptors 攔截器

default-interceptor-ref 默認的攔截器,如果不寫,默認是父包中默認的攔截器

default-action-ref  默認的action,如果不寫,那麼找不到action時就出錯

default- class-ref  action標籤不寫class屬性時默認的class,如果不配置,那麼默認是ActionSupport返回”success”

global-results  該包中全局的結果,便於多個action返回相同的結果

global-exception-mappings 異常的處理 http://www.cnblogs.com/codeplus/archive/2011/07/16/2107999.html

action

發佈了46 篇原創文章 · 獲贊 26 · 訪問量 26萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章