struts2 常量配置详解

  <!-- 设置url请求后缀 -->
    <constant name="struts.action.extension" value="do,action,html,htm"></constant>
    <!-- 指定Web应用的默认编码集,相当于调用HttpServletRequest的setCharacterEncoding方法 -->
    <constant name="struts.i18n.encoding" value="UTF-8" />
    <!-- 设置浏览器是否缓存静态内容,默认值为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 托管 -->  
<constant name="struts.objectFactory" value="spring" />  

 


  
    <!--   
        指定加载struts2配置文件管理器,默认为org.apache.struts2.config.DefaultConfiguration   
        开发者可以自定义配置文件管理器,该类要实现Configuration接口,可以自动加载struts2配置文件。   
    -->  
    <constant name="struts.configuration"  
        value="org.apache.struts2.config.DefaultConfiguration" />  
  
    <!-- 设置默认的locale和字符编码 -->  
       <constant name="struts.locale" value="zh_CN" />  
       <constant name="struts.i18n.encoding" value="GBK" />  
  
    <!-- 指定Struts的工厂类 -->  
    <constant name="struts.objectFactory" value="spring"></constant>  
  
    <!--   
        指定spring框架的装配模式,装配方式有: name, type, auto, and constructor (name   
        是默认装配模式)   
    -->  
    <constant name="struts.objectFactory.spring.autoWire" value="name" />  
  
    <!-- 该属性指定整合spring时,是否对bean进行缓存,值为true or false,默认为true -->  
    <cosntant name="struts.objectFactory.spring.useClassCache" />  
 
    <!-- 指定类型检查,包含tiger和notiger -->  
    <cosntant name="struts.objectTypeDeterminer" value="tiger" />  
 
    <!-- 该属性指定处理 MIME-type multipart/form-data,文件上传 --> 
     <constant name="struts.multipart.parser" value="cos" />  
     <constant name="struts.multipart.parser" value="pell" />  
     <constant name="struts.multipart.parser" value="jakarta" />  
 
    <!-- 指定上传文件时的临时目录,默认使用 javax.servlet.context.tempdir -->  
    <constant name="struts.multipart.saveDir" value="/tmpuploadfiles" />  
  
    <!-- 该属性指定Struts 2文件上传中整个请求内容允许的最大字节数 -->  
   <constant name="struts.multipart.maxSize" value="2097152" />  
  
    <!--   
        该属性指定Struts2应用加载用户自定义的属性文件,该自定义属性文件指定的属性不会覆盖   
        struts.properties文件中指定的属性。如果需要加载多个自定义属性文件,多个自定义属性文   
        件的文件名以英文逗号(,)隔开。(也就是说不要改写struts.properties!)   
    -->  
    <constant name="struts.custom.properties"  
        value="application,org/apache/struts2/extension/custom" />  
           
    <!-- 指定请求url与action映射器,默认为org.apache.struts2.dispatcher.mapper.DefaultActionMapper -->  
    <constant name="struts.mapper.class" value="org.apache.struts2.dispatcher.mapper.DefaultActionMapper" />  
 

       
 
    <!-- 设置是否支持动态方法调用,true为支持,false不支持. -->  
    <constant name="struts.enable.DynamicMethodInvocation" value="true" />  
           
    <!-- 设置是否可以在action中使用斜线,默认为false不可以,想使用需设置为true. -->  
    <constant name="struts.enable.SlashesInActionNames" value="true" />  
       
    <!-- 是否允许使用表达式语法,默认为true. -->  
    <constant name="struts.tag.altSyntax" value="true" />  

  
    <!-- 设置是否每次请求,都重新加载资源文件,默认值为false. -->  
    <cosntant name="struts.i18n.reload" value="false" />  
  
    <!-- 标准的UI主题,默认的UI主题为xhtml,可以为simple,xhtml或ajax -->  
    <cosntant name="struts.ui.theme" value="xhtml" />  
           
    <!-- 模板目录 -->  
    <cosntant name="struts.ui.templateDir" value="template" /> 
 
    <!-- 设置模板类型. 可以为 ftl, vm, or jsp -->  
    <cosntant name="struts.ui.templateSuffix" value="ftl" />  
  
    <!-- 定位velocity.properties 文件. 默认velocity.properties -->  
    <cosntant name="struts.velocity.configfile" value="velocity.properties" />  
       
    <!-- 设置velocity的context. -->  
   <cosntant name="struts.velocity.contexts" value="...." />  
       
    <!-- 定位toolbox -->  
    <cosntant name="struts.velocity.toolboxlocation" value="...." />  

    <!-- 指定web应用的端口 -->  
    <cosntant name="struts.url.http.port" value="80" />  
       
    <!-- 指定加密端口 -->          
   <cosntant name="struts.url.https.port" value="443" />  
  
     <!-- 设置生成url时,是否包含参数.值可以为: none,get or all -->  
    <cosntant name="struts.url.includeParams" value="get" />  
  
    <!-- 设置要加载的国际化资源文件,以逗号分隔. -->  
      <cosntant name="struts.custom.i18n.resources" value="application" />  
        
    <!-- 对于一些web应用服务器不能处理HttpServletRequest.getParameterMap(),   
        像 WebLogic,Orion, and OC4J等,须设置成true,默认为false. -->  
    <cosntant name="struts.dispatcher.parametersWorkaround" value="false" />     
  
    <!-- 指定freemarker管理器 -->  
    <cosntant name="struts.freemarker.manager.classname" value="org.apache.struts2.views.freemarker.FreemarkerManager" />    

  <!-- 设置是否对freemarker的模板设置缓存,效果相当于把template拷贝到 WEB_APP/templates. -->  
     <cosntant name="struts.freemarker.templatesCache" value="false" />       


  <!-- 通常不需要修改此属性. -->  
  <cosntant name="struts.freemarker.wrapper.altMap" value="true" />    


  <!-- 指定xslt result是否使用样式表缓存.开发阶段设为true,发布阶段设为false. -->  
  <cosntant name="struts.xslt.nocache" value="false" />    


  <!-- 设置struts自动加载的文件列表. -->  
  <cosntant name="struts.configuration.files" value="struts-default.xml,struts-plugin.xml,struts.xml" />  


  <!-- 设定是否一直在最后一个slash之前的任何位置选定namespace. -->  
  <cosntant name="struts.mapper.alwaysSelectFullNamespace" value="false" />  





------------------------------------------- struts2 常量配置详解2 -----------------------------------------------------------

1,struts.action.extension

作用:设置为htm的时候, 把url后缀为htm的映射成为action

源码:org.apache.struts2.dispatcher.mapper.DefaultActionMapper

 

Java代码   收藏代码
  1. @Inject(StrutsConstants.STRUTS_ACTION_EXTENSION)  
  2.     public void setExtensions(String extensions) {  
  3.         if (extensions != null && !"".equals(extensions)) {  
  4.             List<String> list = new ArrayList<String>();  
  5.             String[] tokens = extensions.split(",");  
  6.             for (String token : tokens) {  
  7.                 list.add(token);  
  8.             }  
  9.             if (extensions.endsWith(",")) {  
  10.                 list.add("");  
  11.             }  
  12.             this.extensions = Collections.unmodifiableList(list);  
  13.         } else {  
  14.             this.extensions = null;  
  15.         }  
  16.     }  

 从源代码得知,这个可以用配置可以用“,”分割

 

2,struts.enable.DynamicMethodInvocation

作用:动态调用action方法,action!method

源码:org.apache.struts2.dispatcher.mapper.DefaultActionMapper

 

 

 

Java代码   收藏代码
  1. if (allowDynamicMethodCalls) {  
  2.             // handle "name!method" convention.  
  3.             String name = mapping.getName();  
  4.             int exclamation = name.lastIndexOf("!");  
  5.             if (exclamation != -1) {  
  6.                 mapping.setName(name.substring(0, exclamation));  
  7.                 mapping.setMethod(name.substring(exclamation + 1));  
  8.             }  
  9.         }  
  10.         return mapping;  

 

 

3,struts.devMode

作用:设置为true的时候,开启dev模式,会输出很多有用的日志

 

 

4,struts.i18n.reload

作用:设置为true的时候,每次获取ResourceBundle的资源,都从文件加载,而不从内存中取

源码:com.opensymphony.xwork2.util.LocalizedTextUtil

 

Java代码   收藏代码
  1. private static void reloadBundles() {  
  2.         if (reloadBundles) {  
  3.             try {  
  4.                 clearMap(ResourceBundle.classnull"cacheList");  
  5.   
  6.                 // now, for the true and utter hack, if we're running in tomcat, clear  
  7.                 // it's class loader resource cache as well.  
  8.                 clearTomcatCache();  
  9.             }  
  10.             catch (Exception e) {  
  11.                 LOG.error("Could not reload resource bundles", e);  
  12.             }  
  13.         }  
  14.     }  

 

5,struts.i18n.encoding

作用:设置默认的 字符集编码(我习惯设置为UTF-8,像人人这种网站都是用UTF-8的)

源码:org.apache.struts2.dispatcher.Dispatcher(还有很多地方用到)

 

Java代码   收藏代码
  1. /** 
  2.     * Prepare a request, including setting the encoding and locale. 
  3.     * 
  4.     * @param request The request 
  5.     * @param response The response 
  6.     */  
  7.    public void prepare(HttpServletRequest request, HttpServletResponse response) {  
  8.        String encoding = null;  
  9.        if (defaultEncoding != null) {  
  10.            encoding = defaultEncoding;  
  11.        }  
  12.   
  13.        Locale locale = null;  
  14.        if (defaultLocale != null) {  
  15.            locale = LocalizedTextUtil.localeFromString(defaultLocale, request.getLocale());  
  16.        }  
  17.   
  18.        if (encoding != null) {  
  19.            try {  
  20.                request.setCharacterEncoding(encoding);  
  21.            } catch (Exception e) {  
  22.                LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);  
  23.            }  
  24.        }  
  25.   
  26.        if (locale != null) {  
  27.            response.setLocale(locale);  
  28.        }  
  29.   
  30.        if (paramsWorkaroundEnabled) {  
  31.            request.getParameter("foo"); // simply read any parameter (existing or not) to "prime" the request  
  32.        }  
  33.    }  
 

6,struts.configuration.xml.reload

作用:是否每次执行action的时候(com.opensymphony.xwork2.XWork.executeAction)reload struts相关的配置文件

源码:com.opensymphony.xwork2.config.ConfigurationManager

 

Java代码   收藏代码
  1. /** 
  2.      * Reloads the Configuration files if the configuration files indicate that they need to be reloaded. 
  3.      */  
  4.     public synchronized void conditionalReload() {  
  5.         if (FileManager.isReloadingConfigs()) {  
  6.             boolean reload;  
  7.   
  8.             if (LOG.isDebugEnabled()) {  
  9.                 LOG.debug("Checking ConfigurationProviders for reload.");  
  10.             }  
  11.   
  12.             reload = false;  
  13.   
  14.             List<ContainerProvider> providers = getContainerProviders();  
  15.             for (ContainerProvider provider : providers) {  
  16.                 if (provider.needsReload()) {  
  17.                     if (LOG.isInfoEnabled()) {  
  18.                         LOG.info("Detected container provider "+provider+" needs to be reloaded.  Reloading all providers.");  
  19.                     }  
  20.                     reload = true;  
  21.   
  22.                     //break;  
  23.                 }  
  24.             } ..........  
 

7,struts.action.excludePattern

作用:设置 不需要执行的 action的pattern(以JDK自带的正则表达式作匹配),以逗号分隔

源码:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter

 

Java代码   收藏代码
  1. if ( excludedPatterns != null && prepare.isUrlExcluded(request, excludedPatterns)) {  
  2.             request.setAttribute(REQUEST_EXCLUDED_FROM_ACTION_MAPPING, new Object());  
  3.         } else {  
  4.             request = prepare.wrapRequest(request);  
  5.             prepare.findActionMapping(request, response);  
  6.         }  
 

8,struts.tag.altSyntax

作用:具体没研究透 可以设置为true

源代码:org.apache.struts2.components.Component

 

Java代码   收藏代码
  1. /** 
  2.      * If altsyntax (%{...}) is applied, simply strip the "%{" and "}" off. 
  3.      * @param stack the ValueStack where the context value is searched for.  
  4.      * @param expr the expression (must be not null) 
  5.      * @return the stripped expression if altSyntax is enabled. Otherwise 
  6.      * the parameter expression is returned as is. 
  7.      */  
  8.     public static String stripExpressionIfAltSyntax(ValueStack stack, String expr) {  
  9.         if (altSyntax(stack)) {  
  10.             // does the expression start with %{ and end with }? if so, just cut it off!  
  11.             if (expr.startsWith("%{") && expr.endsWith("}")) {  
  12.                 return expr.substring(2, expr.length() - 1);  
  13.             }  
  14.         }  
  15.         return expr;  
  16.     }  
 

9,struts.url.http.port  

作用:struts 生成URL的时候需要带上的端口号,默认80是不需要带的

源码:

 

Java代码   收藏代码
  1. int httpPort = Integer.parseInt(cont.getInstance(String.class, StrutsConstants.STRUTS_URL_HTTP_PORT));  
  2. int httpsPort = Integer.parseInt(cont.getInstance(String.class, StrutsConstants.STRUTS_URL_HTTPS_PORT));  
  3.   
  4. // only append scheme if it is different to the current scheme *OR*  
  5. // if we explicity want it to be appended by having forceAddSchemeHostAndPort = true  
  6. if (forceAddSchemeHostAndPort) {  
  7.     String reqScheme = request.getScheme();  
  8.     changedScheme = true;  
  9.     link.append(scheme != null ? scheme : reqScheme);  
  10.     link.append("://");  
  11.     link.append(request.getServerName());  
  12.   
  13.     if (scheme != null) {  
  14.         // If switching schemes, use the configured port for the particular scheme.  
  15.         if (!scheme.equals(reqScheme)) {  
  16.             if ((scheme.equals("http") && (httpPort != DEFAULT_HTTP_PORT)) || (scheme.equals("https") && httpsPort != DEFAULT_HTTPS_PORT)) {  
  17.                 link.append(":");  
  18.                 link.append(scheme.equals("http") ? httpPort : httpsPort);  
  19.             }  
 

10,struts.url.https.port 同上,差不多。

 

11,struts.url.includeParams

作用:不够详细的介绍

none: 在ServletUrlRenderer渲染URL的时候不会把参数带进去 

get:会把get参数带进去

all:会把 get参数和 Component的参数都带进去

 

12,struts.urlRenderer

作用:修改 UrlRenderer 的实现类,默认为 ServletUrlRenderer

 

13,struts.objectFactory

作用:The com.opensymphony.xwork2.ObjectFactory 的实现类 默认是 org.apache.struts2.impl.StrutsObjectFactory

 

14,struts.objectTypeDeterminer

作用:使用 ognl 获取数据时候 自动判断 数据类型的实现类(我这里没仔细看,分析的不够具体)

 

15,struts.continuations.package

未发现有使用的地方,貌似是个无用的配置 

 

16,struts.configuration

这个配置经测试,貌似无效 

 

17,struts.locale

设置 struts 的 本地默认国家和语言。

 

 

18,struts.dispatcher.parametersWorkaround

什么跟WebLogic有关的设置,不懂,不解释。

 

 

19,struts.freemarker.manager.classname

作用:FreemarkerManager 的实现类 默认org.apache.struts2.views.freemarker.FreemarkerManager

 

20,struts.freemarker.templatesCache

不推荐使用这个,改为使用 struts.freemarker.mru.max.strong.size >0                 struts.freemarker.templatesCache.updateDelay>0

 

21,struts.freemarker.templatesCache.updateDelay

作用:设置正整数和0 几秒钟更新一次freemarket模板

 

22,struts.freemarker.mru.max.strong.size

作用:设置正整数和0 引用英文原描述:the maximum number of strongly referenced templates

 

23,struts.freemarker.beanwrapperCache

作用:设置true 表示使用cache ?????

 

24,struts.velocity.manager.classname

作用:设置VelocityManager 的实现类,默认 org.apache.struts2.views.velocity.VelocityManager

 

25,struts.velocity.configfile

作用:设置哪里读取velocity 的velocity.properties

 

26,struts.velocity.toolboxlocation

作用:设置velocity的toolbox的位置

 

27,struts.velocity.contexts

设置velocity context 的类,以逗号分隔

 

28,struts.ui.templateDir

设置struts 的ui template 的位置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值