訪問HelloWorld應用的路徑的設置
在struts2中,訪問struts2中action的URL路徑由兩部份組成:
包的命名空間+action的名稱
例如: 訪問本例子HelloWorldAction的URL路徑爲: /l6n/helloWorldAction (注意:完整路徑爲:http://localhost:端口/內容路徑/l6n/helloWorldAction)。另外我們也可以加上.action後綴訪問此Action。
- <package name=“hello" namespace=“/l6n“ extends="struts-default">
- <action name="helloWorldAction" class="cn.l6n.action.HelloWorldAction">
- <result name="success" type="dispatcher">/success.jsp</result>
- </action>
- </package>
Action名稱的搜索順序
1.獲得請求路徑的URI,例如url是:
http://server/struts2/path1/path2/path3/test.action
2.首先尋找namespace爲/path1/path2/path3的package,
如果存在這個package,則在這個package中尋找名字爲test的action,
如果不存在這個package則轉步驟3;
3.尋找namespace爲/path1/path2的package,
如果存在這個package,則在這個package中尋找名字爲test的action,
如果不存在這個package,則轉步驟4;
4.尋找namespace爲/path1的package,
如果存在這個package,則在這個package中尋找名字爲test的action,
如果仍然不存在這個package,就去默認的namaspace的package下面去找名
字爲test的action(默認的命名空間爲空字符串“/” ),
如果還是找不到,頁面提示找不到action。