struts2中一些需要注意的常量
2014-01-22 09:46
351 查看
一。“struts.action.extension”指定需要Struts 2处理的请求后缀
FilterDispatcher是Struts 2框架的核心控制器,它负责拦截由<url-pattern>/*</url-pattern>指定的所有用户请求,当用户请求到达时,该Filter会过滤用户请求。默认情况下,如果用户请求的路径以.action结尾,该请求将被转入Struts 2框架处理,否则该请求将略过Struts 2框架的处理。
默认处理的后缀是可以通过常量”struts.action.extension“进行修改的,如下面配置Struts 2只处理以.do为后缀的请求路径:
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.action.extension" value="do"/>
</struts>
如果用户需要指定多个请求后缀,则多个后缀之间以英文逗号(,)隔开。如:
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.action.extension" value="do,action"/>
</struts>
二。其他一些基本常量
1。<!-- 指定默认编码集,作用于HttpServletRequest的setCharacterEncoding方法 和freemarker 、velocity的输出 -->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.i18n.encoding" value="UTF-8"/>
2。<!-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 -->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.serve.static.browserCache" value="false"/>
3。<!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 -->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.configuration.xml.reload" value="true"/>
4。<!-- 开发模式下使用,这样可以打印出更详细的错误信息 -->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.devMode" value="true" />
5。<!-- 默认的视图主题 -->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.ui.theme" value="simple" />
6。<!– 与spring集成时,指定由spring负责action对象的创建 -->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.objectFactory" value="spring" />
7。<!–该属性设置Struts 2是否支持动态方法调用,该属性的默认值是true。如果需要关闭动态方法调用,则可设置该属性为false。 -->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
8。<!--上传文件的大小限制-->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.multipart.maxSize" value="10701096"/>
一定要注意参数名的书写格式。像maxSize一定不能写maxsize等。
三。常量定义
下面以对struts.i18n.encoding=UTF-8的配置为例进行说明:
在struts.xml配置形式如下:
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<struts>
<constant name="struts.i18n.encoding" value="gbk"></constant>
</struts>
在struts.properties的配置形式如下:
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
struts.i18n.encoding=UTF-8
在web.xml中配置如下:
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<filter>
<filter-name>struts2</filter-name>
<filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
<init-param>
<param-name>struts.i18n.encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
四。配置文件的优先级
通常,struts2按如下搜索顺序加载struts2常量:
struts-default.xml
struts-plugin.xml
struts.xml
struts.properties
web.xml
如果在多个文件中配置了同一个常量,则后一个文件中配置的常量值会覆盖前面文件中配置的常量值.
FilterDispatcher是Struts 2框架的核心控制器,它负责拦截由<url-pattern>/*</url-pattern>指定的所有用户请求,当用户请求到达时,该Filter会过滤用户请求。默认情况下,如果用户请求的路径以.action结尾,该请求将被转入Struts 2框架处理,否则该请求将略过Struts 2框架的处理。
默认处理的后缀是可以通过常量”struts.action.extension“进行修改的,如下面配置Struts 2只处理以.do为后缀的请求路径:
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.action.extension" value="do"/>
</struts>
如果用户需要指定多个请求后缀,则多个后缀之间以英文逗号(,)隔开。如:
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.action.extension" value="do,action"/>
</struts>
二。其他一些基本常量
1。<!-- 指定默认编码集,作用于HttpServletRequest的setCharacterEncoding方法 和freemarker 、velocity的输出 -->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.i18n.encoding" value="UTF-8"/>
2。<!-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 -->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.serve.static.browserCache" value="false"/>
3。<!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 -->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.configuration.xml.reload" value="true"/>
4。<!-- 开发模式下使用,这样可以打印出更详细的错误信息 -->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.devMode" value="true" />
5。<!-- 默认的视图主题 -->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.ui.theme" value="simple" />
6。<!– 与spring集成时,指定由spring负责action对象的创建 -->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.objectFactory" value="spring" />
7。<!–该属性设置Struts 2是否支持动态方法调用,该属性的默认值是true。如果需要关闭动态方法调用,则可设置该属性为false。 -->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
8。<!--上传文件的大小限制-->
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<constant name="struts.multipart.maxSize" value="10701096"/>
一定要注意参数名的书写格式。像maxSize一定不能写maxsize等。
三。常量定义
下面以对struts.i18n.encoding=UTF-8的配置为例进行说明:
在struts.xml配置形式如下:
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<struts>
<constant name="struts.i18n.encoding" value="gbk"></constant>
</struts>
在struts.properties的配置形式如下:
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
struts.i18n.encoding=UTF-8
在web.xml中配置如下:
Xml代码
![](http://ryxxlong.iteye.com/images/icon_star.png)
<filter>
<filter-name>struts2</filter-name>
<filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
<init-param>
<param-name>struts.i18n.encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
四。配置文件的优先级
通常,struts2按如下搜索顺序加载struts2常量:
struts-default.xml
struts-plugin.xml
struts.xml
struts.properties
web.xml
如果在多个文件中配置了同一个常量,则后一个文件中配置的常量值会覆盖前面文件中配置的常量值.
相关文章推荐
- struts2中一些需要注意的常量
- struts2中用OGNL表达式定义字符串常量与单个字符常量需要注意的一个小细节
- 【struts2】开发过程中遇到的需要注意的小问题的原因与解决方法
- 关于ROS的一些需要注意的点
- 传奇绘图更换笔记:ZenGL 一些需要注意的事情
- Mysql分区表使用的一些限制和需要注意的地方
- MVC一些需要注意的问题
- Android开发的一些需要注意的细节
- 在c#里调用C++的dll时,需要注意的一些问题
- jQuery调用WCF需要注意的一些问题
- Laravel使用消息队列需要注意的一些问题
- javascript中的一些核心知识点以及需要注意的地方
- 数据结构中栈一些需要注意的地方
- 移动端开 发需要注意的一些事情
- 解析256色位图需要注意的一些问题
- idea创建maven web项目需要注意的一些细节
- 【SSH】struts2中的struts.xml相关的一些基本常量配置
- WINCE添加新字体需要注意的一些问题
- Java打成可执行jar过程中需要注意的一些问题
- Android替换字体时需要注意的一些问题