struts2入门(三)常量加载顺序和常用常量

2012/05/09 1783点热度 0人点赞 0条评论

struts2中的常量

 1)常量的加载顺序

    1,org/apache/struts2/default.properties

    2,struts-default.xml

    3, struts-plugin.xml

    4, struts.xml  在src下

    5, struts.properties  在src下

    6, web.xml

  在多个文件中国配置了同一个常量,则以最后一次出现为准,后面的会覆盖前面的

    先加载struts-default.xml再加载struts-plugin.xml,再加载struts.xml文件

  分析:在StrutsPrepareAndExecuteFilter过滤器的init方法中

Dispatcher dispatcher = init.initDispatcher(config);//此方法是初始化配置参数
public Dispatcher initDispatcher( HostConfig filterConfig ) {
       Dispatcher dispatcher = createDispatcher(filterConfig);
       dispatcher.init();//关键是init()方法
       return dispatcher;
}

在dispatcher.init()方法中

private static final String DEFAULT_CONFIGURATION_PATHS = "struts-default.xml,struts-plugin.xml,struts.xml";
init_DefaultProperties(); // [1]
 //[1]是初始化org/apache/struts2/default.properties配置文件
 init_TraditionalXmlConfigurations(); // [2]
//[2]看具体的方法
  private void init_TraditionalXmlConfigurations() {
        String configPaths = initParams.get("config");
        if (configPaths == null) {
            configPaths = DEFAULT_CONFIGURATION_PATHS;//可以看出在这里将其他的配置文件加载了进来,
        }
        String[] files = configPaths.split("\\s*[,]\\s*");
        for (String file : files) {
            if (file.endsWith(".xml")) {
                if ("xwork.xml".equals(file)) {
                    configurationManager.addContainerProvider(createXmlConfigurationProvider(file, false));
                } else {
                    configurationManager.addContainerProvider(createStrutsXmlConfigurationProvider(file, false, servletContext));
                }
            } else {
                throw new IllegalArgumentException("Invalid configuration file name");
            }
        }
    }

configPaths 接收了一个常量里面依次包含了struts-default.xml,struts-plugin.xml,struts.xml文件,struts2解析到配置文件的常量以后,如果前面有就会覆盖掉原始值

所以说 在多个文件中国配置了同一个常量,则以最后一次出现为准,后面的会覆盖前面的

2)struts2中的常用常量

1:struts.configuration
       含义:用来指定一个用来读取默认配置的类,这个类需要继承org.apache.struts2.config.Configuration
       默认值:org.apache.struts2.config.DefaultConfiguration
2:struts.locale
       含义:用来设置默认的locale
       默认值:en_US
3:struts.i18n.encoding
       含义:用来设置默认的编码方式
       默认值:UTF-8
4:struts.objectFactory
       含义:用来设置默认的对象工厂,使用struts-spring-plugin插件时可以配置,也可以不配置,因为在插件包中已经配置了
       默认值:spring
5:struts.objectFactory.spring.autoWire
       含义:如果使用spring作为默认的对象工厂,这里就配置spring的自动装配策略
       默认值:name
6:struts.objectFactory.spring.useClassCache
       含义:配置当struts和spring集成时,是否缓存类实例
       默认值:true
7:struts.objectFactory.spring.autoWire.alwaysRespect
       含义:总是使用spring的自动装配策略
       默认值:false
8:struts.objectTypeDeterminer
       含义:对象类型确定器。
       默认值:tiger
9:struts.multipart.parser
       含义:指定进行multipart上传的解释器,也就是如何处理文件上传。
       默认值:jakarta
10:struts.multipart.saveDir
       含义:指定进行multipart上传的临时文件存放路径。
       默认值:没有指定
11:struts.multipart.maxSize
       含义:指定进行multipart上传的临时文件的最大限制。
       默认值:2097152
12:struts.custom.properties
       含义:用户自定义属性文件的路径,不能是struts.properties。
       默认值:application,org/apache/struts2/extension/custom
13:struts.mapper.class
       含义:设置如何把url和类进行对应。
       默认值:org.apache.struts2.dispatcher.mapper.DefaultActionMapper
14:struts.action.extension
       含义:指定需要Struts2处理的后缀列表,多个名字间用逗号分隔。
       默认值:action,,
15:struts.serve.static
       含义:表示struts是否应该提供其jar文件内部的静态内容。
       默认值:true
16:struts.serve.static.browserCache
       含义:是否缓存静态资源。
       默认值:true
17:struts.enable.DynamicMethodInvocation
       含义:是否启用动态方法调用的功能。
       默认值:true
18:struts.enable.SlashesInActionNames
       含义:是否可以在action的名称里面使用“/”。
       默认值:false
19:struts.tag.altSyntax
       含义:是否可以使用“%{…}”格式的表达式。
       默认值:true
20:struts.devMode
       含义:是否启用开发模式。
       默认值:false
21:struts.i18n.reload
       含义:是否启用i18n自动重载。
       默认值:false
22:struts.ui.theme
       含义:默认的主题
       默认值:xhtml
23:struts.ui.templateDir
       含义:模板的默认存放路径
       默认值:template
24:struts.ui.templateSuffix
       含义:模板的默认类型,可以是ftl(FreeMarker)、vm(Velocity)、jsp(JSP)
       默认值:ftl
25:struts.configuration.xml.reload
       含义:指定是否在struts.xml文件被修改后重新加载它
       默认值:false
26:struts.velocity.configfile
       含义:指定默认的Velocity配置文件
       默认值:velocity.properties
27:struts.velocity.contexts
       含义:指定默认的Velocity Context的配置文件列表,用逗号分隔
       默认值:没有指定
28:struts.velocity.toolboxlocation
       含义:指定Velocity工具箱的存放位置
       默认值:没有指定
29:struts.url.http.port
       含义:指定默认的http端口号
       默认值:80
30:struts.url.https.port
       含义:指定默认的https端口号
       默认值:443
31:struts.url.includeParams
       含义:指定Struts 2生成URL时是否包含请求参数
       默认值:none
32:struts.custom.i18n.resources
       含义:指定自定义的i18n资源包的名称
       默认值:testmessages,testmessages2
33:struts.dispatcher.parametersWorkaround
       含义:指定为不支持HttpServlet Request调用getParameterMap()方法的应用程序提供其他方式的支持
       默认值:false
34:struts.freemarker.manager.classname
       含义:指定使用哪一种FreeMarker Manager类。
       默认值:org.apache.struts2.views.freemarker.FreemarkerManager
35:struts.freemarker.templatesCache
       含义:指定是否对FreeMarker的模板进行缓存。
       默认值:false
36:struts.freemarker.beanwrapperCache
       含义:指定是否启用BeanWrapper的模型缓存。
       默认值:false
37:struts.freemarker.mru.max.strong.size
       含义:指定Freemaker中MruCacheStorage的maxStrongSize。
       默认值:100
38:struts.xslt.nocache
       含义:是否使用样式表缓存。
       默认值:false
39:struts.mapper.alwaysSelectFullNamespace
       含义:是否允许把最后一个反斜线之前的所有东西作为一个完整的命名空间。
       默认值:false
40:struts.ognl.allowStaticMethodAccess
       含义:是否允许在OGNL表达式中访问静态方法。
       默认值:false
41:struts.el.throwExceptionOnFailure
       含义:设置在处理el表达式的时候,是否可以抛出运行时错误。
       默认值:false
42:struts.ognl.logMissingProperties
       含义:设置是否记录缺失属性日志。
       默认值:false
43:struts.ognl.enableExpressionCache
       含义:设置设置是否缓存解析过的OGNL表达式。
       默认值:true

yxkong

这个人很懒,什么都没留下

文章评论