關于struts 2加載常量的搜索順序

jopen 8年前發布 | 7K 次閱讀 Struts2 Web框架

          新建一個struts 2項目,命名為struts2按照下面的xml來配置Action

<package name="hello" namespace="/action" extends="struts-default">
   <action name="helloworld" class="com.struts.action.HelloWorldAction" method="execute">
           <result name="success">/WEB-INF/test/hello.jsp</result>
   </action>
</package>

 

          將應用部署,我們一般都是這樣訪問我們的Action的。http://localhost:8080/struts2/test/.helloword 

          但是當我們訪問如下路徑:http://localhost:8080/struts2/test/sdf/dsf/32/d/helloworld時, 依然可以訪問到Action。
          這關系到Action的名稱的搜索順序

         假如我們獲得如下路徑:http://localhost:8080/struts2/path1/path2/path3/test。那么當struts2加載時,首先尋找namespace為path1/path2/path2的package。如果不存在這個package就尋找namespace為path1/path2的package。如果還是不存在這個package,就在namespace為path1的package尋找,如果還是不存在這個package,就在namespace 為/的package。如果最后還是不存在的話,就會到默認的namespace的package尋找action。還是找不到的話,頁面就會提示找不到action。如果上面的一步中存在這樣的package,就會在這個package里面尋找名為test的action。當該package中不存在這樣的action時,就會到默認的namespace下的package尋找名為test的action。如果還是不存的話,頁面就會提示找不到action。

       

         讀李剛《輕量級java EE企業應用實戰(第三版)—struts 2+Spring 3+Hibernate整合開發》

   

來自: http://blog.csdn.net/chenssy/article/details/7264579

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!