struts常量和struts.xml配置文件分解配置

来源:互联网 发布:惠灵顿牛排 知乎 编辑:程序博客网 时间:2024/05/16 14:14

一:struts常量
①常量可以在struts.xml或struts.properties(放在src下)中配置,推荐在struts.xml中配置(最好把需要配置的常量统一配置到这个文件里面).
②因常量可在多个配置文件中进行定义,struts2加载常量的搜索顺序:
1 struts-default.xml
2  struts-plugin.xml
3  struts.xml
4 struts.properties
5 web.xml
如在多个文件中配置同一个常量,则后一个文件中配置的常量值会覆盖前一个文件配置的常量值.按搜索顺序,以最后的设定值为准。

③常用的一些常量:
   指定默认编码集,作用于HttpServletRequest的setCharacterEncoding方法和freemarker 、velocity输出
    <constant name="struts.i18n.encoding" value="UTF-8"/>
   指定需要Struts 2处理的请求后缀,默认是action,如用户需指定多个请求后缀,则多个后缀之间以英文逗号(,)隔开
    <constant name="struts.action.extension" value="do"/>
   设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 
    <constant name="struts.serve.static.browserCache" value="false"/>
   系统是否自动重新加载修改后的struts配置文件,默认值为false(生产环境下使用),开发阶段最好打开。
    <constant name="struts.configuration.xml.reload" value="true"/>
  打印出更详细的错误信息(开发模式下使用) 
    <constant name="struts.devMode" value="true" />
   默认视图主题
    <constant name="struts.ui.theme" value="simple" />
  与spring集成时,指定由spring负责action对象的创建
    <constant name="struts.objectFactory" value="spring" />
   该属性设置Struts 2是否支持动态方法调用(默认值是true)
    <constant name="struts.enable.DynamicMethodInvocation" value="false"/>
   上传文件大小限制
     <constant name="struts.multipart.maxSize" value=“10701096"/>


二:struts.xml配置文件分解配置

在大部分应用里,随着应用规模增大,Action数量会大量增加,导致struts.xml配置文件变得臃肿。为了避免struts.xml文件过于庞大、臃肿,提高并发开发效率,增强配置文件文件可读性,可将一个struts.xml配置文件分解成多个配置文件,在struts.xml文件中引入这些配置文件。分解的配置子文件名字任意。

图示的子配置文件配置到struts.xml 中。


配置到struts.xml
<?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.enable.DynamicMethodInvocation" value="true" /><constant name="struts.devMode" value="false" /><constant name="struts.custom.i18n.resources" value="fileuploadresource" />          <include file="com/tianci/struts2_1/struts_test_1.xml" />   <!-- file的值是完整的相对路径。 --></struts>





1 0
原创粉丝点击