struts2_5_struts中常量的配置

来源:互联网 发布:云计算的基础是什么 编辑:程序博客网 时间:2024/04/30 06:09

常量有两种配置方式:

1)在struts.xml中配置:(建议使用此种配置方式)

<struts>  <constant name=”struts.action.extension” value=”action”/><struts>

2)在struts.properties中配置常量:

  truts.action.extension = action

因为常量可以在下面多配置文件中进行定义,所以我们需要了解struts2加载常量的搜索顺序:

struts-default.xml

struts-plugin.xml

struts.xml

struts.properties

web.xml

如果在多个文件中配置了同一个常量,则后一个文件中配置的常量值会覆盖前面文件中配置的常量值。

常用的常量介绍:

1)指定编码集:

<constant name=”struts.i18n.encoding” value=”UTF-8”>

2)指定struts2请求处理的后缀:

该属性的默认值是Action,即所有匹配“*.action”的请求都由Struts2处理,如果需要指定多个后缀,则多个后缀之间用逗号”,“分隔开

<span style="font-size:12px;"><constant name=”struts.action.extension” value=”do,action”/></span>

3)xml文件自动重新加载:

该文件当struts被文件修改后,系统会自动重新加载该文件,默认值为false,开发阶段最好设置为true

<span style="font-size:12px;"><constant name=”struts.configuration.xml.reload” value=”true”/></span>

4)打印错误信息的常量:

次常量在开发模式下使用,会打印出更详细的错误信息

<constant name=”strus.devMode” value=”true”/>

5)struts支持动态属性:

该属性设置struts是否支持动态属性,该属性的默认值是true,关闭该属性时可以设置为false

<constant name=”struts.enable.DynamicMethodInvocation” value=”false”/>

6)管理上传文件大小的常量:

该属性可以设置上传文件的大小

<constant name="struts.multipart.maxSize" value="1000000"/>










2 0