根据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.iteye.com/blog/340709所说的一样,难道reference错了,还是我的英语有问题
明白了,struts的寻找方法是这样的:引自wdl13的http://wdl123.iteye.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。
分享到:
- 2009-08-19 22:47
- 浏览 2158
- 评论(0)
- 论坛回复 / 浏览 (0 / 2659)
- 查看更多
相关推荐
再声讨下struts2,为什么要在框架里面加载一个死的struts.xml,难得不能想struts1 一样的在web.xml里面配置吗? 看网上都催struts2比struts1 整的整的好,我看就这个问题,完全可以算struts2是个垃圾 我现在把完整...
配置常量,可以改变Struts 2框架的一些行为 name属性表示常量名称,value属性表示常量值 package元素: 包的作用:简化维护工作,提高重用性 包可以“继承”已定义的包,并可以添加自己包的配置 name属性为必须去且...
struts2课件 很好的struts2当输入login.jsp访问jsp页面填写完相关信息并提交给login.action时,它会首先被在web.xml中配置的过滤器监听到,过滤器会去查找strust.xml文件,并结合namespace查找名为login的action,...
struts2.0扫盲文档2加入struts.xml配置文件(自己建) <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" ...
接触新版本出了问题后,解决了把jar文件上传上来供大家分享, 一共9个jar文件,我试过没问题 ...<package name="default" namespace="/" extends="struts-default"> /helloWorld.jsp </struts>
struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> ...
<package name="default" namespace="/" extends="struts-default"> <action name="helloworld" class="com.mytest.HelloWorldAction"> <result> /result.jsp <package name="LoginForm" extends="...
ssh 整合所有配置文件的配置 各个标签如何填写 Struts2.xml配置文档 ... <package name="mystruts" extends="struts-default" namespace="/"> <result></result> </struts> struts2在web.xml里的配置
This result uses the ActionMapper provided by the ActionMapperFactory to redirect the browser to a URL that invokes the specified action and (optional) namespace. This is better than the ...
<package name="" namespace="/" extends="struts-default"> <action name="helloWorld" class="com.top.web.HelloWorldAction"> <result>welcome.jsp </struts> 在webroot目录下新建JSP页面,名字:welcome....
需要在你项目的struts.xml中添加如下配置 name="struts.convention.action.suffix" value="Controller"/> name="struts.convention.action.mapAllMatches" value="true"/> name="struts.convention....
2. 配置struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" ...
- Parsing configuration file [struts.xml] - Initializing Struts-Spring integration... - Setting autowire strategy to name - ... initialized Struts-Spring integration successfully - Initializing Spring...
2,struts.xml配置 name="gweb.groovy.dir" value="biz" /> name="gweb" namespace="/index" extends="gpipe-default"> name="index" class="com.gweb.front.action.Index"> name="success" type...
-- include节点是struts2中组件化的方式 可以将每个功能模块独立到一个xml配置文件中 然后用include节点引用 --> <include file="struts-default.xml"> <!-- package提供了将多个Action组织为一个模块的方式 ...
<package name="default" namespace="/" extends="struts-default"> <!-- 添加如下内容 --> <result-types> <result-type name="streamx" class="com.sunspoter.lib.web.struts2.dispatcher.StreamResultX"/> ...
<package name="Student_CRUD_DEMO" extends="struts-default" namespace="/jsp"> <action name="add" class="cn.fjnu.edu.action.AddAction" method="addStu"> <result name="success">list.jsp ...
该漏洞可能在两种情况下被触发,第一,当没有为底层xml配置中定义的结果设置namespace 值,并且其上层动作集配置没有或只有通配符命名空间值,可能构成 RCE攻击。第二,当使用没有 value和动作集的url标签时,并且其...