struts2配置静态资源代码详解
发布时间 - 2026-01-11 03:30:07 点击率:次Struts2框架有两个核心配置文件:struts.xml和Struts2默认属性文件default.properties(在struts2-core-2.3.20.jar中)

default.properties可以通过自己在classpath下写一个struts.properties文件进行定制改写
为什么是struts.properties,这可以看org.apache.struts2.config下的DefaultSettings和PropertiesSettings源码
DefaultSettings.java
public DefaultSettings() {
ArrayList<Settings> list = new ArrayList<Settings>();
// stuts.properties, default.properties
try {
list.add(new PropertiesSettings("struts"));
} catch (Exception e) {
log.warn("DefaultSettings: Could not find or error in struts.properties", e);
}
PropertiesSettings.java
public PropertiesSettings(String name) {
URL settingsUrl = ClassLoaderUtil.getResource(name + ".properties", getClass());
if (settingsUrl == null) {
if (LOG.isDebugEnabled()) {
LOG.debug(name + ".properties missing");
}
settings = new LocatableProperties();
return;
}
也可以把你想写在struts.properties的自定义配置写在struts.xml文件下<constant>节点中,java培训如果同时都在两个文件配置了,一个相同的项目, 先加载 struts.xml,再加载struts.properties也就是说 struts.properties 是可以覆盖 struts.xml里面的配置的
<constant name="struts.devMode" value="false" />
<constant name="struts.i18n.encoding" value="UTF-8" />
<constant name="struts.action.extension" value="action," />
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources,errors" />
<constant name="struts.multipart.maxSize" value="2097152" />
<constant name="struts.ui.theme" value="css_xhtml" />
<constant name="struts.codebehind.pathPrefix" value="/WEB-INF/pages/" />
<constant name="struts.enable.SlashesInActionNames" value="true" />
<constant name="struts.convention.action.disableScanning"
value="true" />
<constant name="struts.mapper.alwaysSelectFullNamespace"
value="false" />
<!-- Allow <s:submit> to call method names directly -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.multipart.saveDir" value="/tmp"></constant>
在strut源码StrutsConstants.class包含了所有可配置项
package org.apache.struts2;
import org.apache.struts2.dispatcher.mapper.CompositeActionMapper;
/**
* This class provides a central location for framework configuration keys
* used to retrieve and store Struts configuration settings.
*/
public final class StrutsConstants {
/** Whether Struts is in development mode or not */
public static final String STRUTS_DEVMODE = "struts.devMode";
/** Whether the localization messages should automatically be reloaded */
public static final String STRUTS_I18N_RELOAD = "struts.i18n.reload";
/** The encoding to use for localization messages */
public static final String STRUTS_I18N_ENCODING = "struts.i18n.encoding";
/** Whether to reload the XML configuration or not */
public static final String STRUTS_CONFIGURATION_XML_RELOAD = "struts.configuration.xml.reload";
/** The URL extension to use to determine if the request is meant for a Struts action */
public static final String STRUTS_ACTION_EXTENSION = "struts.action.extension";
/** Comma separated list of patterns (java.util.regex.Pattern) to be excluded from Struts2-processing */
public static final String STRUTS_ACTION_EXCLUDE_PATTERN = "struts.action.excludePattern";
/** Whether to use the alterative syntax for the tags or not */
public static final String STRUTS_TAG_ALTSYNTAX = "struts.tag.altSyntax";
/** The HTTP port used by Struts URLs */
public static final String STRUTS_URL_HTTP_PORT = "struts.url.http.port";
/** The HTTPS port used by Struts URLs */
public static final String STRUTS_URL_HTTPS_PORT = "struts.url.https.port";
/** The default includeParams method to generate Struts URLs */
public static final String STRUTS_URL_INCLUDEPARAMS = "struts.url.includeParams";
public static final String STRUTS_URL_RENDERER = "struts.urlRenderer";
/** The com.opensymphony.xwork2.ObjectFactory implementation class */
public static final String STRUTS_OBJECTFACTORY = "struts.objectFactory";
public static final String STRUTS_OBJECTFACTORY_ACTIONFACTORY = "struts.objectFactory.actionFactory";
public static final String STRUTS_OBJECTFACTORY_RESULTFACTORY = "struts.objectFactory.resultFactory";
public static final String STRUTS_OBJECTFACTORY_CONVERTERFACTORY = "struts.objectFactory.converterFactory";
public static final String STRUTS_OBJECTFACTORY_INTERCEPTORFACTORY = "struts.objectFactory.interceptorFactory";
public static final String STRUTS_OBJECTFACTORY_VALIDATORFACTORY = "struts.objectFactory.validatorFactory";
public static final String STRUTS_OBJECTFACTORY_UNKNOWNHANDLERFACTORY = "struts.objectFactory.unknownHandlerFactory";
/** The com.opensymphony.xwork2.util.FileManager implementation class */
public static final String STRUTS_FILE_MANAGER_FACTORY = "struts.fileManagerFactory";
/** The com.opensymphony.xwork2.util.fs.FileManager implementation class */
public static final String STRUTS_FILE_MANAGER = "struts.fileManager";
/** The com.opensymphony.xwork2.util.ObjectTypeDeterminer implementation class */
public static final String STRUTS_OBJECTTYPEDETERMINER = "struts.objectTypeDeterminer";
/** The package containing actions that use Rife continuations */
public static final String STRUTS_CONTINUATIONS_PACKAGE = "struts.continuations.package";
/** The org.apache.struts2.config.Configuration implementation class */
public static final String STRUTS_CONFIGURATION = "struts.configuration";
/** The default locale for the Struts application */
public static final String STRUTS_LOCALE = "struts.locale";
/** Whether to use a Servlet request parameter workaround necessary for some versions of WebLogic */
public static final String STRUTS_DISPATCHER_PARAMETERSWORKAROUND = "struts.dispatcher.parametersWorkaround";
/** The org.apache.struts2.views.freemarker.FreemarkerManager implementation class */
public static final String STRUTS_FREEMARKER_MANAGER_CLASSNAME = "struts.freemarker.manager.classname";
@Deprecated
/** Cache Freemarker templates, this cache is managed by struts2,instead of native freemarker cache,set STRUTS_FREEMARKER_MRU_MAX_STRONG_SIZE >0&&STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY>0*/
public static final String STRUTS_FREEMARKER_TEMPLATES_CACHE = "struts.freemarker.templatesCache";
/** Update freemarker templates cache in seconds*/
public static final String STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY = "struts.freemarker.templatesCache.updateDelay";
/** Cache model instances at BeanWrapper level */
public static final String STRUTS_FREEMARKER_BEANWRAPPER_CACHE = "struts.freemarker.beanwrapperCache";
/** Maximum strong sizing for MruCacheStorage for freemarker */
public static final String STRUTS_FREEMARKER_MRU_MAX_STRONG_SIZE = "struts.freemarker.mru.max.strong.size";
/** org.apache.struts2.views.velocity.VelocityManager implementation class */
public static final String STRUTS_VELOCITY_MANAGER_CLASSNAME = "struts.velocity.manager.classname";
/** The Velocity configuration file path */
public static final String STRUTS_VELOCITY_CONFIGFILE = "struts.velocity.configfile";
/** The location of the Velocity toolbox */
public static final String STRUTS_VELOCITY_TOOLBOXLOCATION = "struts.velocity.toolboxlocation";
/** List of Velocity context names */
public static final String STRUTS_VELOCITY_CONTEXTS = "struts.velocity.contexts";
/** The directory containing UI templates. All templates must reside in this directory. */
public static final String STRUTS_UI_TEMPLATEDIR = "struts.ui.templateDir";
/** The default UI template theme */
public static final String STRUTS_UI_THEME = "struts.ui.theme";
/** Token to use to indicate start of theme to be expanded. */
public static final String STRUTS_UI_THEME_EXPANSION_TOKEN = "struts.ui.theme.expansion.token";
/** 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";
/** Declares the buffer size to be used during streaming multipart content to disk. Used only with {@link org.apache.struts2.dispatcher.multipart.JakartaStreamMultiPartRequest} */
public static final String STRUTS_MULTIPART_BUFFERSIZE = "struts.multipart.bufferSize";
/**
* 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";
/** Uses different logic to construct beans, see https://issues.apache.org/jira/browse/WW-4110 */
public static final String STRUTS_OBJECTFACTORY_SPRING_ENABLE_AOP_SUPPORT = "struts.objectFactory.spring.enableAopSupport";
/** 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 {@link com.opensymphony.xwork2.LocaleProvider} implementation class */
public static final String STRUTS_LOCALE_PROVIDER = "struts.localeProvider";
/** 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";
/** Enables evaluation of OGNL expressions **/
public static final String STRUTS_ENABLE_OGNL_EVAL_EXPRESSION = "struts.ognl.enableOGNLEvalExpression";
/** Disables {@link org.apache.struts2.dispatcher.StrutsRequestWrapper} request attribute value stack lookup (JSTL accessibility) **/
public static final String STRUTS_DISABLE_REQUEST_ATTRIBUTE_VALUE_STACK_LOOKUP = "struts.disableRequestAttributeValueStackLookup";
/** The{@link org.apache.struts2.views.util.UrlHelper} implementation class **/
public static final String STRUTS_URL_HELPER = "struts.view.urlHelper";
/** {@link com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter} **/
public static final String STRUTS_CONVERTER_COLLECTION = "struts.converter.collection";
public static final String STRUTS_CONVERTER_ARRAY = "struts.converter.array";
public static final String STRUTS_CONVERTER_DATE = "struts.converter.date";
public static final String STRUTS_CONVERTER_NUMBER = "struts.converter.number";
public static final String STRUTS_CONVERTER_STRING = "struts.converter.string";
/** Enable handling exceptions by Dispatcher - true by default **/
public static final String STRUTS_HANDLE_EXCEPTION = "struts.handle.exception";
public static final String STRUTS_CONVERTER_PROPERTIES_PROCESSOR = "struts.converter.properties.processor";
public static final String STRUTS_CONVERTER_FILE_PROCESSOR = "struts.converter.file.processor";
public static final String STRUTS_CONVERTER_ANNOTATION_PROCESSOR = "struts.converter.annotation.processor";
public static final String STRUTS_CONVERTER_CREATOR = "struts.converter.creator";
public static final String STRUTS_CONVERTER_HOLDER = "struts..converter.holder";
public static final String STRUTS_EXPRESSION_PARSER = "struts.expression.parser";
/** actions names' whitelist **/
public static final String STRUTS_ALLOWED_ACTION_NAMES = "struts.allowed.action.names";
/** enables action: prefix **/
public static final String STRUTS_MAPPER_ACTION_PREFIX_ENABLED = "struts.mapper.action.prefix.enabled";
/** enables access to actions in other namespaces than current with action: prefix **/
public static final String STRUTS_MAPPER_ACTION_PREFIX_CROSSNAMESPACES = "struts.mapper.action.prefix.crossNamespaces";
public static final String DEFAULT_TEMPLATE_TYPE_CONFIG_KEY = "struts.ui.templateSuffix";
/** Allows override default DispatcherErrorHandler **/
public static final String STRUTS_DISPATCHER_ERROR_HANDLER = "struts.dispatcher.errorHandler";
/** Comma delimited set of excluded classes and package names which cannot be accessed via expressions **/
public static final String STRUTS_EXCLUDED_CLASSES = "struts.excludedClasses";
public static final String STRUTS_EXCLUDED_PACKAGE_NAME_PATTERNS = "struts.excludedPackageNamePatterns";
/** Dedicated services to check if passed string is excluded/accepted **/
public static final String STRUTS_EXCLUDED_PATTERNS_CHECKER = "struts.excludedPatterns.checker";
public static final String STRUTS_ACCEPTED_PATTERNS_CHECKER = "struts.acceptedPatterns.checker";
/** Constant is used to override framework's default excluded patterns **/
public static final String STRUTS_OVERRIDE_EXCLUDED_PATTERNS = "struts.override.excludedPatterns";
public static final String STRUTS_OVERRIDE_ACCEPTED_PATTERNS = "struts.override.acceptedPatterns";
public static final String STRUTS_ADDITIONAL_EXCLUDED_PATTERNS = "struts.additional.excludedPatterns";
public static final String STRUTS_ADDITIONAL_ACCEPTED_PATTERNS = "struts.additional.acceptedPatterns";
}
其中
/** Comma separated list of patterns (java.util.regex.Pattern) to be excluded from Struts2-processing */ public static final String STRUTS_ACTION_EXCLUDE_PATTERN = "struts.action.excludePattern";
保存了不由struts2处理的路径,我们在struts.properties或者struts.xml中配置即可.
struts.action.excludePattern=/dwr/.*,/dwr/test/.*
正则表达式,并非URL匹配地址
总结
以上就是本文关于struts2配置静态资源代码详解的全部内容,希望对大家有所帮助。感兴趣的朋友可以参阅:struts2静态资源映射代码示例 Struts2 通过ognl表达式实现投影 Struts2修改上传文件大小限制方法解析 等,有什么问题可以随时留言,小编会及时回复大家的。感谢朋友们对本站的支持。
# struts2
# 配置静态资源
# 静态资源
# Struts2的配置 struts.xml Action详解
# 详解在Java的Struts2框架中配置Action的方法
# Struts 2中的constant配置详解
# struts2中使用注解配置Action方法详解
# Struts2开发 基本配置与类型转换
# Struts2学习笔记(9)-Result配置全局结果集
# struts2开发流程及详细配置
# struts2入门(搭建环境、配置、示例)详解
# Struts2的配置文件方法小结
# Struts2.5版本struts.xml与web.xml配置的更改方法
# 写在
# 有什么
# 都在
# 你想
# 感兴趣
# 朋友们
# 可以通过
# 自定义
# 再加
# 这可
# 可以随时
# 小编
# 配置文件
# 存了
# 也就是说
# 加载
# 上传
# 有两个
# 包含了
# 为什么是
相关栏目:
【
网站优化151355 】
【
网络推广146373 】
【
网络技术251813 】
【
AI营销90571 】
相关推荐:
实例解析Array和String方法
Python面向对象测试方法_mock解析【教程】
如何用已有域名快速搭建网站?
Laravel如何实现数据导出到PDF_Laravel使用snappy生成网页快照PDF【方案】
Laravel Eloquent性能优化技巧_Laravel N+1查询问题解决
C++时间戳转换成日期时间的步骤和示例代码
Python图片处理进阶教程_Pillow滤镜与图像增强
javascript中数组(Array)对象和字符串(String)对象的常用方法总结
jimdo怎样用html5做选项卡_jimdo选项卡html5实现与切换效果【指南】
网站制作公司哪里好做,成都网站制作公司哪家做得比较好,更正规?
Python结构化数据采集_字段抽取解析【教程】
Laravel怎么判断请求类型_Laravel Request isMethod用法
HTML5段落标签p和br怎么选_文本排版常用标签对比【解答】
Laravel怎么实现验证码(Captcha)功能
android nfc常用标签读取总结
Laravel项目如何进行性能优化_Laravel应用性能分析与优化技巧大全
BootStrap整体框架之基础布局组件
浅谈Javascript中的Label语句
如何在HTML表单中获取用户输入并结合JavaScript动态控制复利计算循环
如何用AWS免费套餐快速搭建高效网站?
Laravel如何生成API文档?(Swagger/OpenAPI教程)
JS去除重复并统计数量的实现方法
google浏览器怎么清理缓存_谷歌浏览器清除缓存加速详细步骤
linux top下的 minerd 木马清除方法
详解免费开源的DotNet二维码操作组件ThoughtWorks.QRCode(.NET组件介绍之四)
Python正则表达式进阶教程_复杂匹配与分组替换解析
如何用5美元大硬盘VPS安全高效搭建个人网站?
如何快速搭建二级域名独立网站?
长沙企业网站制作哪家好,长沙水业集团官方网站?
Laravel如何使用Eloquent进行子查询
百度浏览器如何管理插件 百度浏览器插件管理方法
Bootstrap CSS布局之列表
如何在腾讯云服务器快速搭建个人网站?
谷歌浏览器如何更改浏览器主题 Google Chrome主题设置教程
Laravel如何设置定时任务(Cron Job)_Laravel调度器与任务计划配置
javascript中的try catch异常捕获机制用法分析
Gemini手机端怎么发图片_Gemini手机端发图方法【步骤】
网站制作大概多少钱一个,做一个平台网站大概多少钱?
html如何与html链接_实现多个HTML页面互相链接【互相】
Laravel如何创建自定义Artisan命令?(代码示例)
制作网站软件推荐手机版,如何制作属于自己的手机网站app应用?
如何快速查询网址的建站时间与历史轨迹?
javascript基于原型链的继承及call和apply函数用法分析
如何自己制作一个网站链接,如何制作一个企业网站,建设网站的基本步骤有哪些?
标题:Vue + Vuex + JWT 身份认证的正确实践与常见误区解析
如何在阿里云购买域名并搭建网站?
如何在阿里云高效完成企业建站全流程?
电商网站制作价格怎么算,网上拍卖流程以及规则?
Laravel中的withCount方法怎么高效统计关联模型数量
如何用VPS主机快速搭建个人网站?

