<!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开发 监控 前端开发
<!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的该配置调成大并一致。
979 0
|
Web App开发 前端开发
|
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...
1175 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
基于大数据的精准营销与应用场景 2015年08月11日 大数据 大数据营销时代来临营销学领域过去半个多世纪的发展让我们见证了从“以产品为中心”到“以客户为中心”的转变。
1122 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...
927 0
|
SQL 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
     如果在INSERT语句末尾指定了ON DUPLICATE KEY UPDATE,并且插入行后会导致在一个UNIQUE索引或PRIMARY KEY中出现重复值,则在出现重复值的行执行UPDATE;如果不会导致唯一值列重复的问题,则插入新行。
946 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
CentOS 6.5安装配置ldap 时间:2015-07-14 00:54来源:blog.51cto.com 作者:“ly36843运维” 博客 举报 点击:274次 一.
1079 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
一、概述   多维数据模型是最流行的数据仓库的数据模型,多维数据模型最典型的数据模式包括星型模式、雪花模式和事实星座模式,本文以实例方式展示三者的模式和区别。
900 0

热门文章

最新文章