命名空间:
@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";
}
分享到:
相关推荐
默认包路径包含action,actions,struts,struts2的所有包都会被struts作为含有Action类的路径来搜索。你可以通过设置struts.convention.package.locators属性来修改这个配置。如: <constant name="struts.convention....
本文讲述了使用Struts 2标签的注意事项,并介绍了学习Struts 2标签比较权威的网站。
Struts2中使用annotation实现零配置
简述STRUTS2_Convention零配置
STRUTS2零配置.docSTRUTS2零配置.docSTRUTS2零配置.doc
struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置...
STRUTS2:零配置插件CodeBehind
NULL 博文链接:https://username2.iteye.com/blog/1817573
struts2 零配置 使我们项目开发时可以减少很多配置,能够通过一定的规则操作,不需要在配置 result action...等等之类的多于配置
struts2使用json注意事项 struts2使用json注意事项 struts2使用json注意事项 struts2使用json注意事项
采用Struts2注解,视图层采用FreeMarker的一个示例项目。 欢迎下载学习。
struts2231零配置 struts2231零配置
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...
该项目主要是struts2.3的零配置,里面包含两个action,下载后导入myeclipse后,部署后。可以直接访问http://localhost:8080/struts2/abc.action、login.action\login1.action。这里的返回值是以json方式返回。
struts2 Https , 轻松开发基于struts2的https开发
struts2核心配置文件,struts2.xml和struts2.properties
struts2 spring4 hibernate4 Struts2零配置基本架包 struts2-json-plugin-2.5.5.jar struts2-convention-plugin-2.5.5.jar
struts2配置过滤器 示例代码
Struts2配置详解,Struts2配置详解,Struts2配置详解,Struts2配置详解,Struts2配置详解