<!-- 设置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" />
<!-- 设置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" />
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 的位置