設置 namespace 不同值的路徑訪問

1. namespace 的路徑訪問問題:

注意:添加多個 package 時,一定要先修改 name 屬性。設置其分別爲不同包。

eg:

(1)

<package name="default"namespace="/" extends="struts-default">       
        <action
name="hello">
            <result>
                /Hello.jsp
            </result>
        </action>
    </package>    
  

訪問地址:http://localhost:8080/Struts2_0200_Namespace/hello

 

(2)
    <package name="package2" namespace="/path1" extends="struts-default">       
        <action
name="path11">
            <result>
                /Path1.jsp
            </result>
        </action>
    </package>
    

訪問地址:http://localhost:8080/Struts2_0200_Namespace/path1/path11/

 

(3)
    <package name="package3" namespace="/path2/path21" extends="struts-default">       
        <action name="path221">
            <result>
                /Path2.jsp
            </result>
        </action>
    </package>
   

訪問地址:http://localhost:8080/Struts2_0200_Namespace/path2/path21/path221

 

(4) 
    <package name="package4" namespace="" extends="struts-default">       
        <action name="all">
            <result>
                /World.jsp
            </result>
        </action>
    </package>   

訪問地址:http://localhost:8080/Struts2_0200_Namespace/...../..../all   

 

2. package 的作用:

(1)name:包名,把 action 分類

(2)extends:暫時不管

(3)namespace:在 action 訪問路徑前加的路徑名,一定要加 “/”,且與 name 一般都一樣,用模塊命名。

 

3. 爲 tomcat 服務器導入新項目後注意的地方:

我們知道導入跟現有項目類似的項目有兩種方法:第一,直接在 myeclipse 左邊導航窗口中複製,粘貼現有項目;第二,用 import 命令導入存在項目。

注意:導入項目後,要設置以下項目名稱,否則,tomcat 服務器將還是關聯以前的項目。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章