struts中constant的作用
来源:互联网 发布:c语言三个整数排序 编辑:程序博客网 时间:2024/06/05 00:45
- struts.properties文件的内容均可在struts.xml中以<constant name="" value=""></constant>加载。
例如: - struts.xml文件中配置:
- <struts>
<constant name="struts.devMode" value="true" /> - </struts>
- 在 struts.properties中配置struts.devMode
=true
struts.properties文件在WEB-INF/classes目录下存放。
这个文件用来配置Struts2系统的一些基本规约,所有在struts.properties中配置的内容都可以在struts.xml中配置,或者web.xml中在struts2 filter中配置,例如:
Struts.properties中的如下配置:
struts.i18n.encoding=UTF-8
相当于struts.xml中的如下配置:
<constant name=“struts.i18n.encoding” value=“UTF-8” />
相当于web.xml中的如下配置:
<filter>
<filter-name>struts</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> <init-param> <param-name>struts.i18n.encoding</param-name> <param-value>true</param-value> </init-param> </filter>
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/struts2/archive/2007/07/30/1717084.aspx
在struts2中默认处理的请求后缀为action,我们可以修改struts.xml 和struts.properties来修改默认的配置,在struts.xml中<struts>添加子接点<constant name=”struts.action.extension” value=”do” /> 或者是修改struts.properties文件添加struts.action.extension = do这都是一样的效果
如何调用Action的方法 这是本章的重点
1) 如果在Action中只有一个 execute方法那么配置好后就会自动访问这个方法。如果方法名字不是execute 那么我们需要在struts.xml中的Action接点添加一个method属性为该方法签名,如下:
<action method=”hello” name=”helloAction” class=”com.struts2.chapter5.HelloAction”></action>
这样就会调用hello的方法!
2)这是一个控制器负责处理一个请求的方式,但这样就会造成很多的Action类,给维护带来困难。所以可以让一个 Action可以处理多个不同的请求。对于一个学生信息管理模块来说,通过一个Action处理学生信息的添、查、改、删(CRUD)请求,可以大大减少 Action的数量,有效降低维护成本。下面代码让我们可以使用通配符来操作
}
<action name=”*Student” class=”com.struts2.chapter5.StudentAction” method=”{1}”>
</action>
仔细观察一下,发现name属性中有一个”*”号,这是一个通配符,说白了就是方法名称,此时method必须配置成method={1},才能找到对应的方法。现在,如果想调用insertStudent方法,则可以输入下面的URL进行访问:http://localhost:8081 /Struts2Demo/insertStudent.do,如果想调用updateStudent方法,则输入http://localhost:8081/Struts2Demo/updateStudent.do即可。格式如何定义,完全由程序员决定,”*”放在什么地方,也是可以自定义的。
3)对于上面的StudentAction我们还可以这样配置
<action name=”studentAction” class=”com.struts2.demo.StudentAction”>
调用Action的方法还可以通过”Action配置名!方法名.扩展名”
http://localhost:8081/Struts2Demo/studentAction!insertStudent.do
http://localhost:8081/Struts2Demo/studentAction!updateStudent.do
- struts中constant的作用
- struts中constant的作用
- struts 常用的constant作用和配置
- struts 常用的constant作用和配置
- Struts中constant的详解
- struts.xml中constant的配置
- Struts 2中 Constant详解
- struts2 中Struts.xml -- constant配置参数的含义
- struts2 中Struts.xml -- constant配置参数的含义
- struts2 中Struts.xml -- constant配置参数的含义
- struts中 Actionsupport 的作用
- struts constant
- struts constant
- struts <constant/>
- struts.xml中配置常量constant详解
- struts.xml 中配置常量constant详解
- struts.xml 中配置常量constant详解
- struts.xml中一些constant配置含义
- 查看linux 发行版本
- 年终策划序:创业者装逼指南 v1.0
- Lucene学习总结之一:全文检索的基本原理
- 转载:FastDFS的配置、部署与API使用解读(2)以字节方式上传文件的客户端代码
- shopex sdb_goods和sdb_products的区别 商品和货品的区别 商品类型 商品规格 商品属性 商品入库 之间的关系和sql语句 上图
- struts中constant的作用
- python编码问题
- MySQL 查询缓存的实际应用代码示例
- Weblogic 9.2 LINUX安装方法
- GDI+ 添加图片资源函数封装
- JTAG接口20针、14针、8针的制作及重要信号定义
- PopupWindow的显示位置及简单的响应事件
- 转载:FastDFS的配置、部署与API使用解读(3)以流的方式上传文件的客户端代码
- <Android> Failed to pull selection 解决