struts2 常量配置

     struts2的常量配置的方式有很多种,例如在struts.properties,struts.xml,web.xml中。

     通常,struts2框架按如下搜索顺寻加载struts2常量。

        (1) struts-default.xml: 该文件保存在struts2-core-版本号.jar文件中

        (2) struts-plugin.xml

        (3) struts.xml

        (4) struts.properties

        (5) web.xml

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

        在struts.xml文件中通过constant元素来配置常量,配置常量需要两个必须的属性,分别为name、value,大家一看也知道这两个属性的含义,一个指定常量的名字,一个指定常量的值,如下例:

       

<struts>
     <constant name="struts.custom.i18n.resources" value="mess" />
</struts>

          同样也可以在web.xml文件中通过<filter>元素的子元素<init-param>配置,将上例中的常量配置放在web.xml中如下:

<filter>
.......
<init-param>
     <param-name>struts.custom.i18n.resources</param-name>
     <param-value>mess</param-value>
</init-param>
.......
</filter>

 推荐在struts.xml文件中配置常量。

posted on 2012-07-27 11:06  幸福从不迟疑  阅读(436)  评论(0编辑  收藏  举报