struts2配置静态资源代码详解
程序员文章站
2024-04-01 17:11:28
struts2框架有两个核心配置文件:struts.xml和struts2默认属性文件default.properties(在struts2-core-2.3.20.jar...
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 通过ognl表达式实现投影 struts2修改上传文件大小限制方法解析 等,有什么问题可以随时留言,小编会及时回复大家的。感谢朋友们对本站的支持。
推荐阅读
-
struts2配置静态资源代码详解
-
struts2静态资源映射代码示例
-
详解SpringMVC中设置静态资源不被拦截的问题
-
Java 读取外部资源的方法详解及实例代码
-
Spring静态代理和动态代理代码详解
-
nginx 配置静态资源(图片)访问
-
「记录」关于 SpringBoot 版本配置拦截器方法 + 解决拦截静态资源 + 解决重定向
-
js,css,image...资源访问 博客分类: spring springMVC配置静态资源
-
js,css,image...资源访问 博客分类: spring springMVC配置静态资源
-
手动创建静态库【.framework、.a】详解-不包含资源文件