如何从URI映射到一个action中
关于如何从URI映射到一个action中我做了一些测试,发现可以遵循如下的一条规则:
1.获得请求路径的URI,例如url是:http://server/myapp/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。
这里有几点特殊的情况要说明一下,如下所示:
1.如果匹配到了多个package,比如上述流程中有多个namespace为/path1/path2/path3
的package,此时按照package出现的顺序从前向后(我修改过)查找action,直至找完为止。(执行最后一个)
2.如果在一个package中有多个name属性相同的action,那么执行最后一个action。比如上述流程中,有一个namespace为/path1/path2/path3的package,它里面含有多个名字为test的action,那么选择最后一个执行。
上面这几点是我通过多次测试总结出来的,不知道是否概括到了所有可能的情况,纰漏之处,还请指正。
摘自:http://blog.csdn.net/cmtobby/archive/2007/09/06/1775190.aspx
我的总结:
1、form标签最好写成以下两种方式(它们是完全等价的):简单易用
action="HelloWorld" namespace="/tt" çè
action="/tt/HelloWorld.action"
2、form标签:无namespace,一定要加” .action”后缀;
若有namespace,可加可不加” .action”后缀;
若加了” .action”后缀,则Struts框架不会自动添加namespace属性了。(感觉Struts框架是一起添加namespace和后缀的。)
3、 form标签里写namespace=“”和不写 是完全一样的;它们两个和“/”基本一样(还待发掘)。
如果namespace=“/”,则查看JSP页面的代码是 /App/**.action,但在匹配的struts中的action是一样的;namespace=“”和不写,则查看JSP页面的代码是 **.action。
还有一点要说明:(我的理解)
.action的位置只和 struts.xml的命名空间namespace和当前应用程序位置有关,与result中的JSP路径无关;同理,result中的JSP路径也与struts.xml、.action的位置无关。
PS:一点体会:
这些东西,只要会用就可以了,不必深究,因为它只是Struts2里面的一个规定而已,并没有太多的设计思想。但文档里面写得不是很清楚,用的时候一直出问题,所以专门花了点时间查了很多资料,总结在此备忘,也方便其他初学者。
分享到:
相关推荐
struts2-core-2.0.1.jar, struts2-core-2.0.11.1.jar, struts2-core-2.0.11.2.jar, struts2-core-2.0.11.jar, struts2-core-2.0.12.jar, struts2-core-2.0.14.jar, struts2-core-2.0.5.jar, struts2-core-2.0.6.jar,...
-- 为修复struts2 s2-016、s2-017漏洞,重写DefaultActionMapper --> <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="myDefaultActionMapper" class=...
struts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jarstruts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jar
2017年7月7日,Apache Struts发布最新的安全公告,Apache Struts2-strus1-plugin插件存在远程代码执行的高危漏洞,漏洞编号为CVE-2017-9791(S2-048),主要受影响的Struts版本为:2.3.x。 攻击者可以构造恶意的字段值...
struts-core-1.3.10.jar, struts2-cdi-plugin-2.3.30.jar, struts2-codebehind-plugin-2.3.30.jar, struts2-config-browser-plugin-2.3.30.jar, struts2-convention-plugin-2.3.30.jar, struts2-core-2.3.30.jar, ...
struts-taglib-1.3.8.jar struts-taglib-1.3.8.jar
struts2-config-browser-plugin-2.3.24.jar, struts2-core-2.3.24.jar, struts2-jasperreports-plugin-2.3.24.jar, struts2-jfreechart-plugin-2.3.24.jar, struts2-pell-multipart-plugin-2.3.24.jar, struts2-...
struts2 s2-045
struts2-json-plugin,Struts JSON插件
赠送jar包:struts2-json-plugin-2.3.24.jar; 赠送原API文档:struts2-json-plugin-2.3.24-javadoc.jar; 赠送源代码:struts2-json-plugin-2.3.24-sources.jar; 赠送Maven依赖信息文件:struts2-json-plugin-...
struts2-bean-validation-plugin-2.5.2.jar, struts2-cdi-plugin-2.5.2.jar, struts2-config-browser-plugin-2.5.2.jar, struts2-convention-plugin-2.5.2.jar, struts2-core-2.5.2.jar, struts2-dwr-plugin-2.5.2....
struts2-ssl-plugin-1.2.1.jar
struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-...
包含Struts2框架的核心类库,以及Struts2的第三方插件类库 struts2-core-2.0.14 xwork-2.0.7 ognl-2.6.11 commons-logging-1.0.4 freemarker-2.3.8 等等。
【Struts2】〖所有依赖jar包〗struts-2.3.37-lib 我寻见一片海 碧蓝且耀着光 大片船只航行其上 都向着远方 Shared by Foriver_江河 © 1997-8023 江河 All Rights Reserved.
包含struts2-core-2.5.10.1.jar,struts2-jfreechart-plugin-2.5.10.1.jar,struts2-json-plugin-2.5.10.1.jar,struts2-junit-plugin-2.5.10.1.jar,struts2-bean-validation-plugin-2.5.10.1.jar,struts2-cdi-...
struts2-dojo-plugin-2.3.4 jar 日期控件的jar包 需要的自行下载
struts2-convention-plugin-2.3.32
struts2-jquery-plugin-3.1.0.jar
struts1.38包,struts-core-1.3.8.jarstruts1.38包,struts-core-1.3.8.jar