struts2 恒量配置详解
1,struts.action.extension
作用:设置为htm的时候, 把url后缀为htm的映射成为action
源码:org.apache.struts2.dispatcher.mapper.DefaultActionMapper
- @Inject (StrutsConstants.STRUTS_ACTION_EXTENSION)
- public void setExtensions(String extensions) {
- if (extensions != null && ! "" .equals(extensions)) {
- List<String> list = new ArrayList<String>();
- String[] tokens = extensions.split("," );
- for (String token : tokens) {
- list.add(token);
- }
- if (extensions.endsWith( "," )) {
- list.add("" );
- }
- this .extensions = Collections.unmodifiableList(list);
- } else {
- this .extensions = null ;
- }
- }
从源代码得知,这个可以用配置可以用“,”分割
2,struts.enable.DynamicMethodInvocation
作用:动态调用action方法,action!method
源码:org.apache.struts2.dispatcher.mapper.DefaultActionMapper
- if (allowDynamicMethodCalls) {
- // handle "name!method" convention.
- String name = mapping.getName();
- int exclamation = name.lastIndexOf( "!" );
- if (exclamation != - 1 ) {
- mapping.setName(name.substring(0 , exclamation));
- mapping.setMethod(name.substring(exclamation + 1 ));
- }
- }
- return mapping;
3,struts.devMode
作用:设置为true的时候,开启dev模式,会输出很多有用的日志
4,struts.i18n.reload
作用:设置为true的时候,每次获取ResourceBundle的资源,都从文件加载,而不从内存中取
源码:com.opensymphony.xwork2.util.LocalizedTextUtil
- private static void reloadBundles() {
- if (reloadBundles) {
- try {
- clearMap(ResourceBundle.class , null , "cacheList" );
- // now, for the true and utter hack, if we're running in tomcat, clear
- // it's class loader resource cache as well.
- clearTomcatCache();
- }
- catch (Exception e) {
- LOG.error("Could not reload resource bundles" , e);
- }
- }
- }
5,struts.i18n.encoding
作用:设置默认的 字符集编码(我习惯设置为UTF-8,像人人这种网站都是用UTF-8的)
源码:org.apache.struts2.dispatcher.Dispatcher(还有很多地方用到)
- /**
- * Prepare a request, including setting the encoding and locale.
- *
- * @param request The request
- * @param response The response
- */
- public void prepare(HttpServletRequest request, HttpServletResponse response) {
- String encoding = null ;
- if (defaultEncoding != null ) {
- encoding = defaultEncoding;
- }
- Locale locale = null ;
- if (defaultLocale != null ) {
- locale = LocalizedTextUtil.localeFromString(defaultLocale, request.getLocale());
- }
- if (encoding != null ) {
- try {
- request.setCharacterEncoding(encoding);
- } catch (Exception e) {
- LOG.error("Error setting character encoding to '" + encoding + "' - ignoring." , e);
- }
- }
- if (locale != null ) {
- response.setLocale(locale);
- }
- if (paramsWorkaroundEnabled) {
- request.getParameter("foo" ); // simply read any parameter (existing or not) to "prime" the request
- }
- }
6,struts.configuration.xml.reload
作用:是否每次执行action的时候(com.opensymphony.xwork2. XWork.executeAction)reload struts相关的配置文件
源码:com.opensymphony.xwork2.config.ConfigurationManager
- /**
- * Reloads the Configuration files if the configuration files indicate that they need to be reloaded.
- */
- public synchronized void conditionalReload() {
- if (FileManager.isReloadingConfigs()) {
- boolean reload;
- if (LOG.isDebugEnabled()) {
- LOG.debug("Checking ConfigurationProviders for reload." );
- }
- reload = false ;
- List<ContainerProvider> providers = getContainerProviders();
- for (ContainerProvider provider : providers) {
- if (provider.needsReload()) {
- if (LOG.isInfoEnabled()) {
- LOG.info("Detected container provider " +provider+ " needs to be reloaded. Reloading all providers." );
- }
- reload = true ;
- //break;
- }
- } ..........
7,struts.action.excludePattern
作用:设置 不需要执行的 action的pattern(以JDK自带的正则表达式作匹配),以逗号分隔
源码:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter
- if ( excludedPatterns != null && prepare.isUrlExcluded(request, excludedPatterns)) {
- request.setAttribute(REQUEST_EXCLUDED_FROM_ACTION_MAPPING, new Object());
- } else {
- request = prepare.wrapRequest(request);
- prepare.findActionMapping(request, response);
- }
8,struts.tag.altSyntax
作用:具体没研究透 可以设置为true
源代码:org.apache.struts2.components.Component
- /**
- * If altsyntax (%{...}) is applied, simply strip the "%{" and "}" off.
- * @param stack the ValueStack where the context value is searched for.
- * @param expr the expression (must be not null)
- * @return the stripped expression if altSyntax is enabled. Otherwise
- * the parameter expression is returned as is.
- */
- public static String stripExpressionIfAltSyntax(ValueStack stack, String expr) {
- if (altSyntax(stack)) {
- // does the expression start with %{ and end with }? if so, just cut it off!
- if (expr.startsWith( "%{" ) && expr.endsWith( "}" )) {
- return expr.substring( 2 , expr.length() - 1 );
- }
- }
- return expr;
- }
9,struts.url.http.port
作用:struts 生成URL的时候需要带上的端口号,默认80是不需要带的
源码:
- int httpPort = Integer.parseInt(cont.getInstance(String. class , StrutsConstants.STRUTS_URL_HTTP_PORT));
- int httpsPort = Integer.parseInt(cont.getInstance(String. class , StrutsConstants.STRUTS_URL_HTTPS_PORT));
- // only append scheme if it is different to the current scheme *OR*
- // if we explicity want it to be appended by having forceAddSchemeHostAndPort = true
- if (forceAddSchemeHostAndPort) {
- String reqScheme = request.getScheme();
- changedScheme = true ;
- link.append(scheme != null ? scheme : reqScheme);
- link.append("://" );
- link.append(request.getServerName());
- if (scheme != null ) {
- // If switching schemes, use the configured port for the particular scheme.
- if (!scheme.equals(reqScheme)) {
- if ((scheme.equals( "http" ) && (httpPort != DEFAULT_HTTP_PORT)) || (scheme.equals( "https" ) && httpsPort != DEFAULT_HTTPS_PORT)) {
- link.append(":" );
- link.append(scheme.equals("http" ) ? httpPort : httpsPort);
- }
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";