Struts2常量介绍
来源:互联网 发布:mac移动硬盘写入软件 编辑:程序博客网 时间:2024/06/11 00:39
Struts2常量介绍
10级学员 刘根鹏课堂笔记
经过前几讲的介绍,我想大家对struts2有了初步的了解,下面让我来讲讲struts2中常量的用法和使用(常量的默认配置struts2-core-2.x.x.x/org/apache/struts2/default.properties文件里)。
一.常量配置:
要用常量,首先要通过配置来实现,常量可以在下面多个文件中进行定义,struts2载常量的搜索顺序如下,后面的设置可以覆盖前面的设置:
default.properties文件
struts-default.xml
struts-plugin.xml
struts.xml
struts.properties
web.xml
注意:
1. 之所以使用struts.propreties文件配置,是因为为了保持与WebWork的向后兼容
2. 在实际开发中,在web.xml中配置常量相比其他两种,需要更多的代码量,会降低了web.xml的可读性
3. 通常推荐在struts.xml文件中配置struts2的常量,而且便于集中管理
二、常量详解:
(1)struts.i18n.encoding=UTF-8
指定默认编码
用法: <constant name="struts.i18n.encoding" value="UTF-8" />
(2)struts.action.extension
指定Struts 2处理的请求后缀,默认值是action,即所有匹配*.action的请求都由Struts2处理,如果用户需要指定多个请求后缀,则多个后缀之间以英文逗号(,)隔开
用法:<constant name="struts.action.extension" value="do" /> 或者
<constant name="struts.action.extension" value="do,action" />
(3)struts.configuration.xml.reload
当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开
用法:<constant name="struts.configuration.xml.reload" value="true" />
(4)struts.devMode
开发模式下使用,默认为false,设置成true,这样可以打印出更详细的错误信息,有助于查找到错误,在开发的时候建议开启,项目发布之后改成false
<constant name="struts.devMode" value="true" />
(5)struts.multipart.parser
该属性指定处理 MIME-type multipart/form-data,文件上传方式,有三种方式cos、pell 、jakarta;struts2默认采用第三种方式,如果想用前两种方式,需要去网上下载相应jar包即可
用法: <constant name="struts.multipart.parser" value="cos" />
<constant name="struts.multipart.parser" value="pell" />
<constant name="struts.multipart.parser" value="jakarta" />
(6)struts.multipart.saveDir
指定上传文件时的临时目录,默认使用 javax.servlet.context.tempdir
用法:<constant name="struts.multipart.saveDir" value="/tmpuploadfiles" />
(7)struts.multipart.maxSize
该属性指定Struts 2文件上传中整个请求内容允许的最大字节数 默认为2M
用法:<constant name="struts.multipart.maxSize" value="2097152" />
(8)struts.ui.theme
默认的视图主题,可以为simple,xhtml或ajax
用法:<constant name="struts.ui.theme" value="simple" />
(9)struts.serve.static.browserCache
设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭
用法:<constant name="struts.serve.static.browserCache" value="false" />
(10)struts.enable.SlashesInActionNames
设置是否可以在action中使用斜线,默认为false不可以,设置为true,可以使用
用法:<constant name="struts.enable.SlashesInActionNames" value="true" />
(11)struts.enable.DynamicMethodInvocation
设置是否支持动态方法调用,true为支持,false不支持.
用法:<constant name="struts.enable.DynamicMethodInvocation" value="true" />
下面是一些不常用的常量使用方法,需要了解一下:因为重点是struts2的讲解,所以与spring集成时用到的常量,在讲spring时还将给大家重点讲解,这里就不多说了。
常量在struts2中作用也是挺大的,希望大家在学习struts2的时候,不要忘记对常量的学习
转载自:http://blog.csdn.net/redarmy_chen/article/details/7342155
阅读全文
0 0
- Struts2常量介绍
- Struts2常量介绍及说明
- Struts2常用的常量介绍
- struts2的常用常量介绍
- struts2常用的常量介绍
- Struts2常量介绍及说明
- Struts2常量介绍及说明
- 【转】Struts2常用的常量介绍
- 【转】Struts2常用的常量介绍
- struts2中常用的常量介绍
- struts2中常用的常量介绍
- struts2中常用的常量介绍
- struts2 常用的常量介绍<constant
- struts2处理后缀 常量定义 常用的常量介绍
- struts2的常量配置以及常用常量的相关介绍
- struts2:struts.properties配置文件介绍及常量加载顺序
- Struts2 中为acton注入值以及常量配置和常量介绍
- stuts2学习笔记------指定需要struts2处理的请求后缀&细说常量定义&常用常量介绍
- 算法笔记(5)图的广度优先遍历和深度优先遍历
- 百度之星初赛(A)Hdu-6113.度度熊的01世界
- [leetcode]488. Zuma Game
- android文本编辑工具类之SpannableStringUtils
- Java中的String类型
- Struts2常量介绍
- heapster资源API
- HDU6108 小C的倍数问题(规律,2017"百度之星"程序设计大赛
- mysql触发器用法
- 异步消息队列
- jquery dataTable 参数详解
- Redis的下载安装
- 判断给定森林中有多少棵树特别版
- 南理 108 士兵杀敌(一)