Struts2 零配置注意事项
2012-05-30 17:50
459 查看
命名空间:
@Namespace
当出现@Namespace时,它会取代当前所有Action的名空间。
例:当一个LoginAction在org.hzy.actions.xx下面中,其命名空间是/xx,(其LoginAction方法名叫login())
访问路径:http:localhost:8080:/struts2/xx/login,
出现@Namespace("/aa"),则其名空间是/aa,访问/xx/login则找不到,而是/aa/login
访问路径:http:localhost:8080:/struts2/aa/login,
@Action
当@Action中最前面出现"/"时,它会忽略 @Namespace中的名空间,
例:上面是/aa/login,当出现@Action("/ss")时,这时的名空间是/,
访问路径:http:localhost:8080:/struts2/ss
而当@Action中没出现"/"时,它是走@Namespace的名空间,
例:上面是@Namespace("/aa"),当出现@Action("bb")时,这时的名空间是/aa,
访问路径:http:localhost:8080:/struts2/aa/bb
当Action跳到JSP中,是以当前Action的名空间下去找的,
例:访问路径:http:localhost:8080:/struts2/aa/bb,它找bb对应的JSP,是在content/aa下找的,
是在Action当前名空间下找。
当在有效的名空间当中找不到action,零配置就会去找相应的jsp,两者都找不到则报错。
例子:
Action跳转到action
(1)
(2)
@Namespace
当出现@Namespace时,它会取代当前所有Action的名空间。
例:当一个LoginAction在org.hzy.actions.xx下面中,其命名空间是/xx,(其LoginAction方法名叫login())
访问路径:http:localhost:8080:/struts2/xx/login,
出现@Namespace("/aa"),则其名空间是/aa,访问/xx/login则找不到,而是/aa/login
访问路径:http:localhost:8080:/struts2/aa/login,
@Action
当@Action中最前面出现"/"时,它会忽略 @Namespace中的名空间,
例:上面是/aa/login,当出现@Action("/ss")时,这时的名空间是/,
访问路径:http:localhost:8080:/struts2/ss
而当@Action中没出现"/"时,它是走@Namespace的名空间,
例:上面是@Namespace("/aa"),当出现@Action("bb")时,这时的名空间是/aa,
访问路径:http:localhost:8080:/struts2/aa/bb
当Action跳到JSP中,是以当前Action的名空间下去找的,
例:访问路径:http:localhost:8080:/struts2/aa/bb,它找bb对应的JSP,是在content/aa下找的,
是在Action当前名空间下找。
当在有效的名空间当中找不到action,零配置就会去找相应的jsp,两者都找不到则报错。
例子:
package org.hzy.actions.xx; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Actions; import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.ResultPath; @ResultPath("/WEB-INF/Jsp")//改变默认的/WEB-INF/content路径 //@Namespace("/cc")//覆盖org.hzy.actions.xx(/xx) public class HelloWorldAction { // @Actions({ // @Action("/aa"), // @Action("/los"), // @Action("bb") //是/cc/bb // }) public String login(){ System.out.println("helloworld!!!!!!!!!!!!!"); return "success"; } }
Action跳转到action
(1)
@Action("login")//跳到login-query public String login() throws Exception { // TODO Auto-generated method stub System.out.println("login!!!!!!!!!!!!!!!!!!!!!"); System.out.println(this.uname); return "query"; } @Action("login-query")//对应的是content下面的login-query-los.jsp public String query() throws Exception { // TODO Auto-generated method stub System.out.println("query!!!!!!!!!!!!!!!!!!!!!"); System.out.println(this.uname); return "los"; }
(2)
//这里location="test"是跳到test action @Results({ @Result(name = "failure", location = "test", type="chain") }) public class LosAction { @Action(value = "url", results = { @Result(name = "success", location = "/WEB-INF/Jsp/los.jsp", type = "chain") }) public String login() throws Exception { // TODO Auto-generated method stub System.out.println("los!!!!!!!!!!!!"); return "failure"; //会先找本身的result 再去找全局的 } @Action(value = "test", results = { @Result(name = "success", location = "/WEB-INF/Jsp/los.jsp", type = "dispatcher") }) public String test() throws Exception { // TODO Auto-generated method stub System.out.println("test!!!!!!!!!!!!"); return "success"; }
相关文章推荐
- 《struts2 in action》学习问题——零配置——几点注意事项
- struts2注解配置注意事项
- Struts2 零配置注意事项
- Struts2 零配置注意事项
- Struts2的配置文件加载顺序及常用常量名及更改方法、注意事项
- struts2注解配置注意事项
- struts2注解配置注意事项
- struts2注解配置注意事项
- tokuDB存储引擎的安装、配置、使用及注意事项
- opencv配置注意事项【总结】
- UEditor在线编辑器配置及注意事项
- Linux-RHEL5-初学者配置vsftpd注意事项
- struts2注意事项
- [转]@Transactional spring 配置事务 注意事项
- ssh免密码登陆配置及注意事项
- ubuntu下配置nginx 加php需注意事项
- 配置Oracle RAC时修改/etc/hosts文件的注意事项
- solr配置的 时候的注意事项以及修改tomcat端口号的方法
- iOS常用配置注意事项
- 工作流 Shark 的 JSPClient例子配置注意事项