关于struts.xml中的namespace的一些疑问
来源:互联网 发布:java 架构师培训课程 编辑:程序博客网 时间:2024/06/14 01:14
根据struts reference中所说的
Namespaces are not a path!
Namespace are not hierarchical like a file system path. There is one namespace level. For example if the URL /barspace/myspace/bar.action is requested, the framework will first look for namespace /barspace/myspace. If the action does not exist at /barspace/myspace, the search will immediately fall back to the default namespace "". The framework will not parse the namespace into a series of "folders". In the Namespace Example, the bar action in the default namespace would be selected.
但是我在实践中发现如果请求http://localhost:8080/StrutsTest/RefLink/deap/login.action,这样的url,我的struts.xml中:
<package name="TestNamespace2" extends="struts-default" namespace="">
<action name="login" class="com.struts2.test.LoginDefault">
<result name="got">/login.jsp</result>
</action>
</package>
<package name="TestNamespace4" extends="struts-default" namespace="/RefLink">
<action name="login" class="com.struts2.test.LoginTest">
<result name="got">/login.jsp</result>
</action>
</package>
<package name="TestNamespace3" extends="struts-default" namespace="/RefLink/deap/leaf">
<action name="login" class="com.struts2.test.LoginLeaf">
<result name="test">/login.jsp</result>
</action>
</package>
如果按照reference所说的应该是找不到对应的namespace后,直接查找namespace为“”的,但是我实际试验中发现它调用LoginTest,这个情况和wdl13的http://wdl123.javaeye.com/blog/340709所说的一样,难道reference错了,还是我的英语有问题
明白了,struts的寻找方法是这样的:引自wdl13的http://wdl123.javaeye.com/blog/340709
1.获得请求路径的URI,例如url是:http://server/myapp/path1/path2/path3/test.action
2.首先寻找namespace为/path1/path2/path3的package,如果存在这个package,则在这个package中寻找名字为test的action,若找到则执行,否则报错;如果不存在这个package则转步骤3;
//问题的关键在这里:如果在寻找namespace的时候,没能找到符合的namespace,例如/path1/path2/path3,则一切如wdl123所写的,逐次往上目录当做namespace找,但是一旦存在/path1/path2/path3这样的namespace,那么如果在这个namespace下没能找到test.action,则他不会再逐次往上级目录匹配namespace,而是直接转向了namespace为""的去寻找action。
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。
更新后的<package name="TestNamespace2" extends="struts-default" namespace="">
<action name="login" class="com.struts2.test.LoginDefault">
<result name="got">/login.jsp</result>
</action>
</package>
<package name="TestNamespace4" extends="struts-default" namespace="/RefLink">
<action name="login" class="com.struts2.test.LoginTest">
<result name="got">/login.jsp</result>
</action>
</package>
<package name="TestNamespace5" extends="struts-default" namespace="/RefLink/deap">
<action name="loginNO" class="com.struts2.test.LoginTestDeap">
<result name="got">/login.jsp</result>
</action>
</package>
这次 http://localhost:8080/StrutsTest/RefLink/deap/login.action,直接在namespace="/RefLink/deap"下没有找到login.action,就不再是往/RefLink下找action了,而是直接去了namespace="", 调用了com.struts2.test.LoginDefault。
- 关于struts.xml中的namespace的一些疑问
- struts 中关于xml配置文件中namespace的理解
- Struts2的struts.xml配置中的namespace的使用
- Struts2的struts.xml配置中的namespace的使用
- 关于ip_free中的一些疑问
- 关于360的一些疑问
- 关于PopupMenuListener的一些疑问
- 关于Spring的一些疑问
- 关于chukwa的一些疑问
- 关于jdbc的一些疑问
- 关于MFC的一些疑问
- 关于socket的一些疑问
- 关于定位的一些疑问
- struts.xml中package的namespace属性
- struts.xml中package的namespace属性
- struts中的namespace
- Struts中的namespace
- 关于图片的居中的一些疑问
- oracle 判断字段是不否全为数字
- 近期项目总结之类型转换
- UIA 统一身份认证
- eclipse中jvm内存的设置
- 《GOF设计模式》—职责链(CHAIN OF RESPONSIBILITY)—Delphi源码示例:职责链接口
- 关于struts.xml中的namespace的一些疑问
- word复制图片 导致桌面图标变成蓝色阴影怎么都去不掉
- hdoj1005
- 不用中间变量,交换两个变量的值的方法
- 《GOF设计模式》—职责链(CHAIN OF RESPONSIBILITY)—Delphi源码示例:帮助机制
- Struts2配置详解
- 还原IE的*.mht文件关联
- MySQL 字段类型说明
- Linux内核设计与实现读书笔记(2)-进程管理