struts2 常量配置详解

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 的位置

 

29,待补充中

 

 

/** The default UI template theme */

    public static final String STRUTS_UI_THEME = "struts.ui.theme";

 

    /** The maximize size of a multipart request (file upload) */

    public static final String STRUTS_MULTIPART_MAXSIZE = "struts.multipart.maxSize";

 

    /** The directory to use for storing uploaded files */

    public static final String STRUTS_MULTIPART_SAVEDIR = "struts.multipart.saveDir";

 

    /**

     * The name of the bean that will handle multipart requests

     */

    public static final String STRUTS_MULTIPART_HANDLER = "struts.multipart.handler";

 

    /**

     * The org.apache.struts2.dispatcher.multipart.MultiPartRequest parser implementation

     * for a multipart request (file upload)

     */

    public static final String STRUTS_MULTIPART_PARSER = "struts.multipart.parser";

 

    /** How Spring should autowire.  Valid values are 'name', 'type', 'auto', and 'constructor' */

    public static final String STRUTS_OBJECTFACTORY_SPRING_AUTOWIRE = "struts.objectFactory.spring.autoWire";

 

    /** Whether the autowire strategy chosen by STRUTS_OBJECTFACTORY_SPRING_AUTOWIRE is always respected.  Defaults

     * to false, which is the legacy behavior that tries to determine the best strategy for the situation.

     * @since 2.1.3

     */

    public static final String STRUTS_OBJECTFACTORY_SPRING_AUTOWIRE_ALWAYS_RESPECT = "struts.objectFactory.spring.autoWire.alwaysRespect";

 

    /** Whether Spring should use its class cache or not */

    public static final String STRUTS_OBJECTFACTORY_SPRING_USE_CLASS_CACHE = "struts.objectFactory.spring.useClassCache";

 

    /** Whether or not XSLT templates should not be cached */

    public static final String STRUTS_XSLT_NOCACHE = "struts.xslt.nocache";

 

    /** Location of additional configuration properties files to load */

    public static final String STRUTS_CUSTOM_PROPERTIES = "struts.custom.properties";

 

    /** Location of additional localization properties files to load */

    public static final String STRUTS_CUSTOM_I18N_RESOURCES = "struts.custom.i18n.resources";

 

    /** The org.apache.struts2.dispatcher.mapper.ActionMapper implementation class */

    public static final String STRUTS_MAPPER_CLASS = "struts.mapper.class";

 

    /**

     * A prefix based action mapper that is capable of delegating to other

     * {@link org.apache.struts2.dispatcher.mapper.ActionMapper}s based on the request's prefix

     * You can specify different prefixes that will be handled by different mappers

     */

    public static final String PREFIX_BASED_MAPPER_CONFIGURATION = "struts.mapper.prefixMapping";

 

    /** Whether the Struts filter should serve static content or not */

    public static final String STRUTS_SERVE_STATIC_CONTENT = "struts.serve.static";

 

    /** If static content served by the Struts filter should set browser caching header properties or not */

    public static final String STRUTS_SERVE_STATIC_BROWSER_CACHE = "struts.serve.static.browserCache";

 

    /** Allows one to disable dynamic method invocation from the URL */

    public static final String STRUTS_ENABLE_DYNAMIC_METHOD_INVOCATION = "struts.enable.DynamicMethodInvocation";

 

    /** Whether slashes in action names are allowed or not */

    public static final String STRUTS_ENABLE_SLASHES_IN_ACTION_NAMES = "struts.enable.SlashesInActionNames";

 

    /** Prefix used by {@link CompositeActionMapper} to identify its containing {@link org.apache.struts2.dispatcher.mapper.ActionMapper} class. */

    public static final String STRUTS_MAPPER_COMPOSITE = "struts.mapper.composite";

 

    public static final String STRUTS_ACTIONPROXYFACTORY = "struts.actionProxyFactory";

 

    public static final String STRUTS_FREEMARKER_WRAPPER_ALT_MAP = "struts.freemarker.wrapper.altMap";

 

    /** The name of the xwork converter implementation */

    public static final String STRUTS_XWORKCONVERTER = "struts.xworkConverter";

 

    public static final String STRUTS_ALWAYS_SELECT_FULL_NAMESPACE = "struts.mapper.alwaysSelectFullNamespace";

 

    /** XWork default text provider */

    public static final String STRUTS_XWORKTEXTPROVIDER = "struts.xworkTextProvider";

 

    /** The name of the parameter to create when mapping an id (used by some action mappers) */

public static final String STRUTS_ID_PARAMETER_NAME = "struts.mapper.idParameterName";

/** The name of the parameter to determine whether static method access will be allowed in OGNL expressions or not */

public static final String STRUTS_ALLOW_STATIC_METHOD_ACCESS = "struts.ognl.allowStaticMethodAccess";

 

/** The com.opensymphony.xwork2.validator.ActionValidatorManager implementation class */

    public static final String STRUTS_ACTIONVALIDATORMANAGER = "struts.actionValidatorManager";

 

    /** The {@link com.opensymphony.xwork2.util.ValueStackFactory} implementation class */

    public static final String STRUTS_VALUESTACKFACTORY = "struts.valueStackFactory";

 

    /** The {@link com.opensymphony.xwork2.util.reflection.ReflectionProvider} implementation class */

    public static final String STRUTS_REFLECTIONPROVIDER = "struts.reflectionProvider";

 

    /** The {@link com.opensymphony.xwork2.util.reflection.ReflectionContextFactory} implementation class */

    public static final String STRUTS_REFLECTIONCONTEXTFACTORY = "struts.reflectionContextFactory";

 

    /** The {@link com.opensymphony.xwork2.util.PatternMatcher} implementation class */

    public static final String STRUTS_PATTERNMATCHER = "struts.patternMatcher";

 

    /** The {@link org.apache.struts2.dispatcher.StaticContentLoader} implementation class */

    public static final String STRUTS_STATIC_CONTENT_LOADER = "struts.staticContentLoader";

 

    /** The {@link com.opensymphony.xwork2.UnknownHandlerManager} implementation class */

    public static final String STRUTS_UNKNOWN_HANDLER_MANAGER = "struts.unknownHandlerManager";

 

    /** Throw RuntimeException when a property is not found, or the evaluation of the espression fails*/

    public static final String STRUTS_EL_THROW_EXCEPTION = "struts.el.throwExceptionOnFailure";

 

    /** Logs properties that are not found (very verbose) **/

    public static final String STRUTS_LOG_MISSING_PROPERTIES = "struts.ognl.logMissingProperties";

 

    /** Enables caching of parsed OGNL expressions **/

    public static final String STRUTS_ENABLE_OGNL_EXPRESSION_CACHE = "struts.ognl.enableExpressionCache";

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值