Struts2配置文件-struts.xml 和struts.properties

struts.properties 是可以不要的!!!
因为  struts.xml文件中 有 <constant> 这个节点, 你可以把你想写在struts.properties的自定义配置
写在 struts.xml文件当中.

例如,你想 开启 struts2 的开发模式
可以直接在 struts.xml文件当中写上.
<constant name="struts.devMode" value="true“>
不用再去 去创建 一个 struts.properties,并写上 struts.devMode = true

所有的配置项目,其实 你可以去看看 struts2 默认的配置文件 default.properties.
位置在 struts2-core-2.x.x.jar 的 org.apache.struts2 包 下面的

当然,你可能又会问了,如果同时都在两个文件配置了,一个相同的项目,哪个是有效的呢
他其实是有一个加载顺序的: 先加载 struts.xml,再加载 struts.properties
也就是说 struts.properties 是可以覆盖 struts.xml里面的 配置的,
具体 是否 要 struts.properties ,还是得根据 具体情况,具体分析吧,
不过 我基本上不用,免得 出现 配置混乱的情况.呵呵

在struts2中默认处理的请求后缀为action,或.do,我们可以修改struts.xml 和struts.properties来修改默认的配置。
1、在struts.xml中<struts>添加子结点
<constant name="struts.action.extension" value="action,do,webwork" />

2、或者是修改struts.properties文件,添加
struts.action.extension = action,do

3.struts.properties配置文件

该文件定义了struts2框架的大量属性。只要将该文件放在web应用的CLASSPATH下,struts2框架就会自动加载。

 4、在struts2.xml配置文件中,这些有什么作用?

<constant name="struts.custom.i18n.resources" value="globalMessages" />   设置全局资源文件名称
   为globalMessages(src下会有一个globalMessages.properties)
<constant name="struts.action.extension" value="do, ," />   设置Action的访问扩展名为 .do
<constant name="struts.i18n.encoding" value="UTF-8" />   设置参数编码为UTF-8
<constant name="struts.multipart.maxSize" value="1075555555" />  设置上传文件允许的最大字节数
<constant name="struts.multipart.saveDir" value="C:/" />  设置上传文件所保存的临时文件夹

猜你喜欢

转载自jackroomage.iteye.com/blog/1883600