struts2 Action名稱的搜索順序

一、http://localhost:8080/s2_01_HCM_02/test/helloworld能夠訪問
test:包的命名空間 helloworld:action名稱
二、http://localhost:8080/s2_01_HCM_02/test/asdfasd/asdfad/asdf/helloworld也能夠訪問apache

順序:/test/asdfasd/asdfad/asdf(看看這個命名空間下有沒有,沒有的話)---/test/asdfasd/asdfad/依次往上找jsp

三、以http://localhost:8080/s2_01_HCM_02/test/helloworld爲例,
假如存在/test命名空間,可是該命名空間下沒有對應爲helloworld的action,
那麼就會到默認命名空間(namespace=""或者不寫)下找,若是沒有,則報錯404spa

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
 <package name="it"  namespace="/test" extends="struts-default">
 </package>
 
 <!-- 
  如下寫法至關於<package name="itcast" namespace="" extends="struts-default">,即默認命名空間
  -->
 <package name="itcast" extends="struts-default">
  <action name="helloworld" class="cn.itcast.action.HelloWorldAction" method="execute">
   <result name="success">/WEB-INF/page/hello.jsp</result>
  </action>
 </package>
 
</struts>
相關文章
相關標籤/搜索