<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont

简介:   Struts2注解 1 Struts2注解的作用 使用注解可以用来替换struts.xml配置文件!!! 2 导包   必须导入struts2-convention-plugin-2.3.15.jar包,它在struts2安装包下lib目录中。

 

Struts2注解

1 Struts2注解的作用

使用注解可以用来替换struts.xml配置文件!!!

2 导包

  必须导入struts2-convention-plugin-2.3.15.jar包,它在struts2安装包下lib目录中。 

3 通过配置文件学习对应的注解

@Action来代替<action>元素!

l  String value():指定访问路径;

l  Result[] results():指定局部结果。

@Result来代替<result>元素!

l  String name():指定结果名称;

l  String location():指定结果路径。

@Namespace代替<package>namespace属性:

l  String value():指定名称空间。

@ParentPackage代替<package>extends属性:

l  String value():指定父包名称

@Namespace("/order")

@ParentPackage("struts-default")

publicclass OrderAction extends ActionSupport  {

    @Action(value="add", results={

           @Result(name="success", location="/index.jsp"),

           @Result(name="input", location="/add.jsp")})

    public String add() {

       System.out.println("add()");

       returnSUCCESS;

    }

    @Action(value="mod", results={@Result(name="success", location="/index.jsp")})

    public String mod() {

       System.out.println("mod()");

       returnSUCCESS;

    }

    @Action(value="del", results={@Result(name="success", location="/index.jsp")})

    public String del() {

       System.out.println("del()");

       returnSUCCESS;

    }

}

 

4 注解相关常量

  struts.convention.classes.reload,默认值为false。表示在修改注解后需要重启Tomcat

 

Struts2约定(了解)

1 什么是约定

使用约定可以连注解都不写,是真正的零配置,但是它的能力有限,所以这种方式不可取的。

l  Struts2会对Action的命名,以及Action的包名都有限制;

l  Struts2会对结果页面的存放路径,以及结果页面的名称也都有限制。

  使用约定与使用注解一样,也要导包:struts2-convention-plugin-2.3.15.jar

1        约定对Action的限制

约定Action类名

要求Action的命名必须以“Action”为后缀,例如:UserActionBookAction等等。可以使用下面常量来修改后缀限制:

<constant name="struts.convention.action.suffix" value="Action"/>

约定Action包名

要求Action必须放到actionactionsstrutsstruts2包中。例如:cn.itcast.actioncn.itcast.sturtscn.itcast.action.user等等。可以使用下面常量来修改Actoin的包

<constant name="struts.convention.package.locators" value="action,actions,struts,struts2"/>

3 通过Action的限制得到访问路径

上面已经知道约定对Action的限制,现在通过Action的包名和类名得到它的访问路径

例如:cn.itcast.action.UserAction,它的访问路径为/user.action

例如:cn.itcast.action.user.UserAction,它的访问路径为/user/user.action。因为在约定包action后面还有一层包user,那么这一层就是名称空间了。

例如:com.action.cn.itcast.user.UserAction,它的访问路径为/cn/itcast/user/user.action

例如:cn.itcast.action.user.UserListAction, 它的访问路径为/user/user-list.action。当Action名称由多个单词构成,那么在访问路径中使用“-”来连接多个单词。

4 通过Action的限制得到结果页面路径

Struts2约定限制结果页面必须放到/WEB-INF/content/目录中,可以通过下面常量来修改这个限制。

<constant name="struts.convention.result.path" value="/WEB-INF/content/"/>

cn.itcast.action.UserAction返回结果为success时,Struts会依次查找如下结果页面:

l  /WEB-INF/content/user-success.jsp

l  /WEB-INF/content/user-success.html

l  /WEB-INF/content/user.jsp

cn.itcast.action.user.UserListAction返回的结果为error时,Struts会依次查找如下结果页面:

l  /WEB-INF/content/user/user-list-error.jsp

l  /WEB-INF/content/user/user-list-error.html

l  /WEB-INF/content/user/user-list.jsp

目录
相关文章
|
Web App开发 前端开发 Java
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
ZooKeeper 保证了数据的强一致性,  zk集群中任意节点(一个zkServer)上的相同znode下的数据一定是相同的。
925 0
|
Web App开发 监控 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
Hbase依赖的datanode日志中如果出现如下报错信息:DataXceiverjava.io.EOFException: INFO org.apache.hadoop.hdfs.server.datanode.DataNode: Exception in receiveBlock for block  解决办法:Hbase侧配置的dfs.socket.timeout值过小,与DataNode侧配置的 dfs.socket.timeout的配置不一致,将hbase和datanode的该配置调成大并一致。
955 0
|
Web App开发 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
PipeMapRed.waitOutputThreads(): subprocess failed with code X ,这里code X对应的信息如下:error code 1: Operation not perm...
1124 0
|
Web App开发 前端开发 测试技术
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
一、迁移步骤 1.首先安装最新版本gitlab(gitlab7.2安装) 2.停止旧版本gitlab服务 3.将旧的项目文件完整导入新的gitlab   bundle exec rake gitlab:import:r...
837 0
|
Web App开发 监控 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
hadoop服务器更换硬盘操作步骤(datanode hadoop目录${HADOOP_HOME}/bin    日志位置:/var/log/hadoop)1.登陆服务器,切换到mapred用户,执行jps命令,查看是否有TaskTracker进程。
1169 0
|
Web App开发 数据库
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
可伸缩系统的架构经验 Feb 27th, 2013 | Comments 最近,阅读了Will Larson的文章Introduction to Architecting System for Scale,感觉很有价值。
2504 0
|
Web App开发 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
service cloudera-scm-agent stop service cloudera-scm-agent stop umount /var/run/cloudera-scm-agent/process umo...
903 0
|
Web App开发 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
authentification验证 - 是指验证who you are(你是谁), 所以需要用到username和password进行身份验证。
721 0
|
Web App开发 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
一个典型的星型模式包括一个大型的事实表和一组逻辑上围绕这个事实表的维度表。  事实表是星型模型的核心,事实表由主键和度量数据两部分组成。
643 0