struts2中关于package的namespace和访问路径嵌套的处理关系

来源:互联网 发布:淘宝网雷丝高领打底衫 编辑:程序博客网 时间:2024/06/05 15:08

<package name="user" namespace="/user" extends="struts-default">        <action name="index">    <result>/index.jsp</result>    </action>       </package><package name="user1" namespace="/user/user" extends="struts-default">        <action name="index">    <result>/index_special.jsp</result>    </action>     </package>


假设配置文件中有两个package,分别为user和user1:namespace分别为/user和/user/user

当访问的路径为http://localhost:8080/Struts2_1600_GlobalResult/user/user/index的时候,出现的界面为index_special.jsp

当访问的路径为http://localhost:8080/Struts2_1600_GlobalResult/user/user/user/user/index的时候,出现的界面为index_special.jsp

而当访问的路径为http://localhost:8080/Struts2_1600_GlobalResult/user/index的时候,出现的界面为index.jsp

由此可知:

其处理的方式为:

1、首先寻找namespace为/user/user/user/user的package,如果存在,则寻找该空间下名为index的action。如果不存在这个package则寻找/user/user/user的package,如果存在,则寻找action如果依然不存在,则继续向下寻找/user/user的package,存在,则寻找该空间下名为index的action。如果还不存在,则寻找/user的package。

2.分析上面所写的路径:

第一个路径:首先寻找/user/user的package,因为存在这个package,所以寻找名为index的action,再加载result中的index_special.jsp页面。

第二个路径:首先寻找/user/user/user/user的package,因为不存在,所以继续寻找/user/user/user的package,因为不存在,所以继续寻找/user/user的package,因为存在这个package,所以加载的是index_special.jsp页面

第三个路径:首先寻找的是/user的package,因为存在,所以寻找该package下名为index的action,再加载result中的index.jsp页面。



阅读全文
1 0