struts2配置静态资源代码详解
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
publicDefaultSettings(){
ArrayListlist=newArrayList();
//stuts.properties,default.properties
try{
list.add(newPropertiesSettings("struts"));
}catch(Exceptione){
log.warn("DefaultSettings:Couldnotfindorerrorinstruts.properties",e);
}
PropertiesSettings.java
publicPropertiesSettings(Stringname){
URLsettingsUrl=ClassLoaderUtil.getResource(name+".properties",getClass());
if(settingsUrl==null){
if(LOG.isDebugEnabled()){
LOG.debug(name+".propertiesmissing");
}
settings=newLocatableProperties();
return;
}
也可以把你想写在struts.properties的自定义配置写在struts.xml文件下
在strut源码StrutsConstants.class包含了所有可配置项
packageorg.apache.struts2;
importorg.apache.struts2.dispatcher.mapper.CompositeActionMapper;
/**
*Thisclassprovidesacentrallocationforframeworkconfigurationkeys
*usedtoretrieveandstoreStrutsconfigurationsettings.
*/
publicfinalclassStrutsConstants{
/**WhetherStrutsisindevelopmentmodeornot*/
publicstaticfinalStringSTRUTS_DEVMODE="struts.devMode";
/**Whetherthelocalizationmessagesshouldautomaticallybereloaded*/
publicstaticfinalStringSTRUTS_I18N_RELOAD="struts.i18n.reload";
/**Theencodingtouseforlocalizationmessages*/
publicstaticfinalStringSTRUTS_I18N_ENCODING="struts.i18n.encoding";
/**WhethertoreloadtheXMLconfigurationornot*/
publicstaticfinalStringSTRUTS_CONFIGURATION_XML_RELOAD="struts.configuration.xml.reload";
/**TheURLextensiontousetodetermineiftherequestismeantforaStrutsaction*/
publicstaticfinalStringSTRUTS_ACTION_EXTENSION="struts.action.extension";
/**Commaseparatedlistofpatterns(java.util.regex.Pattern)tobeexcludedfromStruts2-processing*/
publicstaticfinalStringSTRUTS_ACTION_EXCLUDE_PATTERN="struts.action.excludePattern";
/**Whethertousethealterativesyntaxforthetagsornot*/
publicstaticfinalStringSTRUTS_TAG_ALTSYNTAX="struts.tag.altSyntax";
/**TheHTTPportusedbyStrutsURLs*/
publicstaticfinalStringSTRUTS_URL_HTTP_PORT="struts.url.http.port";
/**TheHTTPSportusedbyStrutsURLs*/
publicstaticfinalStringSTRUTS_URL_HTTPS_PORT="struts.url.https.port";
/**ThedefaultincludeParamsmethodtogenerateStrutsURLs*/
publicstaticfinalStringSTRUTS_URL_INCLUDEPARAMS="struts.url.includeParams";
publicstaticfinalStringSTRUTS_URL_RENDERER="struts.urlRenderer";
/**Thecom.opensymphony.xwork2.ObjectFactoryimplementationclass*/
publicstaticfinalStringSTRUTS_OBJECTFACTORY="struts.objectFactory";
publicstaticfinalStringSTRUTS_OBJECTFACTORY_ACTIONFACTORY="struts.objectFactory.actionFactory";
publicstaticfinalStringSTRUTS_OBJECTFACTORY_RESULTFACTORY="struts.objectFactory.resultFactory";
publicstaticfinalStringSTRUTS_OBJECTFACTORY_CONVERTERFACTORY="struts.objectFactory.converterFactory";
publicstaticfinalStringSTRUTS_OBJECTFACTORY_INTERCEPTORFACTORY="struts.objectFactory.interceptorFactory";
publicstaticfinalStringSTRUTS_OBJECTFACTORY_VALIDATORFACTORY="struts.objectFactory.validatorFactory";
publicstaticfinalStringSTRUTS_OBJECTFACTORY_UNKNOWNHANDLERFACTORY="struts.objectFactory.unknownHandlerFactory";
/**Thecom.opensymphony.xwork2.util.FileManagerimplementationclass*/
publicstaticfinalStringSTRUTS_FILE_MANAGER_FACTORY="struts.fileManagerFactory";
/**Thecom.opensymphony.xwork2.util.fs.FileManagerimplementationclass*/
publicstaticfinalStringSTRUTS_FILE_MANAGER="struts.fileManager";
/**Thecom.opensymphony.xwork2.util.ObjectTypeDeterminerimplementationclass*/
publicstaticfinalStringSTRUTS_OBJECTTYPEDETERMINER="struts.objectTypeDeterminer";
/**ThepackagecontainingactionsthatuseRifecontinuations*/
publicstaticfinalStringSTRUTS_CONTINUATIONS_PACKAGE="struts.continuations.package";
/**Theorg.apache.struts2.config.Configurationimplementationclass*/
publicstaticfinalStringSTRUTS_CONFIGURATION="struts.configuration";
/**ThedefaultlocalefortheStrutsapplication*/
publicstaticfinalStringSTRUTS_LOCALE="struts.locale";
/**WhethertouseaServletrequestparameterworkaroundnecessaryforsomeversionsofWebLogic*/
publicstaticfinalStringSTRUTS_DISPATCHER_PARAMETERSWORKAROUND="struts.dispatcher.parametersWorkaround";
/**Theorg.apache.struts2.views.freemarker.FreemarkerManagerimplementationclass*/
publicstaticfinalStringSTRUTS_FREEMARKER_MANAGER_CLASSNAME="struts.freemarker.manager.classname";
@Deprecated
/**CacheFreemarkertemplates,thiscacheismanagedbystruts2,insteadofnativefreemarkercache,setSTRUTS_FREEMARKER_MRU_MAX_STRONG_SIZE>0&&STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY>0*/
publicstaticfinalStringSTRUTS_FREEMARKER_TEMPLATES_CACHE="struts.freemarker.templatesCache";
/**Updatefreemarkertemplatescacheinseconds*/
publicstaticfinalStringSTRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY="struts.freemarker.templatesCache.updateDelay";
/**CachemodelinstancesatBeanWrapperlevel*/
publicstaticfinalStringSTRUTS_FREEMARKER_BEANWRAPPER_CACHE="struts.freemarker.beanwrapperCache";
/**MaximumstrongsizingforMruCacheStorageforfreemarker*/
publicstaticfinalStringSTRUTS_FREEMARKER_MRU_MAX_STRONG_SIZE="struts.freemarker.mru.max.strong.size";
/**org.apache.struts2.views.velocity.VelocityManagerimplementationclass*/
publicstaticfinalStringSTRUTS_VELOCITY_MANAGER_CLASSNAME="struts.velocity.manager.classname";
/**TheVelocityconfigurationfilepath*/
publicstaticfinalStringSTRUTS_VELOCITY_CONFIGFILE="struts.velocity.configfile";
/**ThelocationoftheVelocitytoolbox*/
publicstaticfinalStringSTRUTS_VELOCITY_TOOLBOXLOCATION="struts.velocity.toolboxlocation";
/**ListofVelocitycontextnames*/
publicstaticfinalStringSTRUTS_VELOCITY_CONTEXTS="struts.velocity.contexts";
/**ThedirectorycontainingUItemplates.Alltemplatesmustresideinthisdirectory.*/
publicstaticfinalStringSTRUTS_UI_TEMPLATEDIR="struts.ui.templateDir";
/**ThedefaultUItemplatetheme*/
publicstaticfinalStringSTRUTS_UI_THEME="struts.ui.theme";
/**Tokentousetoindicatestartofthemetobeexpanded.*/
publicstaticfinalStringSTRUTS_UI_THEME_EXPANSION_TOKEN="struts.ui.theme.expansion.token";
/**Themaximizesizeofamultipartrequest(fileupload)*/
publicstaticfinalStringSTRUTS_MULTIPART_MAXSIZE="struts.multipart.maxSize";
/**Thedirectorytouseforstoringuploadedfiles*/
publicstaticfinalStringSTRUTS_MULTIPART_SAVEDIR="struts.multipart.saveDir";
/**Declaresthebuffersizetobeusedduringstreamingmultipartcontenttodisk.Usedonlywith{@linkorg.apache.struts2.dispatcher.multipart.JakartaStreamMultiPartRequest}*/
publicstaticfinalStringSTRUTS_MULTIPART_BUFFERSIZE="struts.multipart.bufferSize";
/**
*Theorg.apache.struts2.dispatcher.multipart.MultiPartRequestparserimplementation
*foramultipartrequest(fileupload)
*/
publicstaticfinalStringSTRUTS_MULTIPART_PARSER="struts.multipart.parser";
/**HowSpringshouldautowire.Validvaluesare'name','type','auto',and'constructor'*/
publicstaticfinalStringSTRUTS_OBJECTFACTORY_SPRING_AUTOWIRE="struts.objectFactory.spring.autoWire";
/**WhethertheautowirestrategychosenbySTRUTS_OBJECTFACTORY_SPRING_AUTOWIREisalwaysrespected.Defaults
*tofalse,whichisthelegacybehaviorthattriestodeterminethebeststrategyforthesituation.
*@since2.1.3
*/
publicstaticfinalStringSTRUTS_OBJECTFACTORY_SPRING_AUTOWIRE_ALWAYS_RESPECT="struts.objectFactory.spring.autoWire.alwaysRespect";
/**WhetherSpringshoulduseitsclasscacheornot*/
publicstaticfinalStringSTRUTS_OBJECTFACTORY_SPRING_USE_CLASS_CACHE="struts.objectFactory.spring.useClassCache";
/**Usesdifferentlogictoconstructbeans,seehttps://issues.apache.org/jira/browse/WW-4110*/
publicstaticfinalStringSTRUTS_OBJECTFACTORY_SPRING_ENABLE_AOP_SUPPORT="struts.objectFactory.spring.enableAopSupport";
/**WhetherornotXSLTtemplatesshouldnotbecached*/
publicstaticfinalStringSTRUTS_XSLT_NOCACHE="struts.xslt.nocache";
/**Locationofadditionalconfigurationpropertiesfilestoload*/
publicstaticfinalStringSTRUTS_CUSTOM_PROPERTIES="struts.custom.properties";
/**Locationofadditionallocalizationpropertiesfilestoload*/
publicstaticfinalStringSTRUTS_CUSTOM_I18N_RESOURCES="struts.custom.i18n.resources";
/**Theorg.apache.struts2.dispatcher.mapper.ActionMapperimplementationclass*/
publicstaticfinalStringSTRUTS_MAPPER_CLASS="struts.mapper.class";
/**
*Aprefixbasedactionmapperthatiscapableofdelegatingtoother
*{@linkorg.apache.struts2.dispatcher.mapper.ActionMapper}sbasedontherequest'sprefix
*Youcanspecifydifferentprefixesthatwillbehandledbydifferentmappers
*/
publicstaticfinalStringPREFIX_BASED_MAPPER_CONFIGURATION="struts.mapper.prefixMapping";
/**WhethertheStrutsfiltershouldservestaticcontentornot*/
publicstaticfinalStringSTRUTS_SERVE_STATIC_CONTENT="struts.serve.static";
/**IfstaticcontentservedbytheStrutsfiltershouldsetbrowsercachingheaderpropertiesornot*/
publicstaticfinalStringSTRUTS_SERVE_STATIC_BROWSER_CACHE="struts.serve.static.browserCache";
/**AllowsonetodisabledynamicmethodinvocationfromtheURL*/
publicstaticfinalStringSTRUTS_ENABLE_DYNAMIC_METHOD_INVOCATION="struts.enable.DynamicMethodInvocation";
/**Whetherslashesinactionnamesareallowedornot*/
publicstaticfinalStringSTRUTS_ENABLE_SLASHES_IN_ACTION_NAMES="struts.enable.SlashesInActionNames";
/**Prefixusedby{@linkCompositeActionMapper}toidentifyitscontaining{@linkorg.apache.struts2.dispatcher.mapper.ActionMapper}class.*/
publicstaticfinalStringSTRUTS_MAPPER_COMPOSITE="struts.mapper.composite";
publicstaticfinalStringSTRUTS_ACTIONPROXYFACTORY="struts.actionProxyFactory";
publicstaticfinalStringSTRUTS_FREEMARKER_WRAPPER_ALT_MAP="struts.freemarker.wrapper.altMap";
/**Thenameofthexworkconverterimplementation*/
publicstaticfinalStringSTRUTS_XWORKCONVERTER="struts.xworkConverter";
publicstaticfinalStringSTRUTS_ALWAYS_SELECT_FULL_NAMESPACE="struts.mapper.alwaysSelectFullNamespace";
/**XWorkdefaulttextprovider*/
publicstaticfinalStringSTRUTS_XWORKTEXTPROVIDER="struts.xworkTextProvider";
/**The{@linkcom.opensymphony.xwork2.LocaleProvider}implementationclass*/
publicstaticfinalStringSTRUTS_LOCALE_PROVIDER="struts.localeProvider";
/**Thenameoftheparametertocreatewhenmappinganid(usedbysomeactionmappers)*/
publicstaticfinalStringSTRUTS_ID_PARAMETER_NAME="struts.mapper.idParameterName";
/**ThenameoftheparametertodeterminewhetherstaticmethodaccesswillbeallowedinOGNLexpressionsornot*/
publicstaticfinalStringSTRUTS_ALLOW_STATIC_METHOD_ACCESS="struts.ognl.allowStaticMethodAccess";
/**Thecom.opensymphony.xwork2.validator.ActionValidatorManagerimplementationclass*/
publicstaticfinalStringSTRUTS_ACTIONVALIDATORMANAGER="struts.actionValidatorManager";
/**The{@linkcom.opensymphony.xwork2.util.ValueStackFactory}implementationclass*/
publicstaticfinalStringSTRUTS_VALUESTACKFACTORY="struts.valueStackFactory";
/**The{@linkcom.opensymphony.xwork2.util.reflection.ReflectionProvider}implementationclass*/
publicstaticfinalStringSTRUTS_REFLECTIONPROVIDER="struts.reflectionProvider";
/**The{@linkcom.opensymphony.xwork2.util.reflection.ReflectionContextFactory}implementationclass*/
publicstaticfinalStringSTRUTS_REFLECTIONCONTEXTFACTORY="struts.reflectionContextFactory";
/**The{@linkcom.opensymphony.xwork2.util.PatternMatcher}implementationclass*/
publicstaticfinalStringSTRUTS_PATTERNMATCHER="struts.patternMatcher";
/**The{@linkorg.apache.struts2.dispatcher.StaticContentLoader}implementationclass*/
publicstaticfinalStringSTRUTS_STATIC_CONTENT_LOADER="struts.staticContentLoader";
/**The{@linkcom.opensymphony.xwork2.UnknownHandlerManager}implementationclass*/
publicstaticfinalStringSTRUTS_UNKNOWN_HANDLER_MANAGER="struts.unknownHandlerManager";
/**ThrowRuntimeExceptionwhenapropertyisnotfound,ortheevaluationoftheespressionfails*/
publicstaticfinalStringSTRUTS_EL_THROW_EXCEPTION="struts.el.throwExceptionOnFailure";
/**Logspropertiesthatarenotfound(veryverbose)**/
publicstaticfinalStringSTRUTS_LOG_MISSING_PROPERTIES="struts.ognl.logMissingProperties";
/**EnablescachingofparsedOGNLexpressions**/
publicstaticfinalStringSTRUTS_ENABLE_OGNL_EXPRESSION_CACHE="struts.ognl.enableExpressionCache";
/**EnablesevaluationofOGNLexpressions**/
publicstaticfinalStringSTRUTS_ENABLE_OGNL_EVAL_EXPRESSION="struts.ognl.enableOGNLEvalExpression";
/**Disables{@linkorg.apache.struts2.dispatcher.StrutsRequestWrapper}requestattributevaluestacklookup(JSTLaccessibility)**/
publicstaticfinalStringSTRUTS_DISABLE_REQUEST_ATTRIBUTE_VALUE_STACK_LOOKUP="struts.disableRequestAttributeValueStackLookup";
/**The{@linkorg.apache.struts2.views.util.UrlHelper}implementationclass**/
publicstaticfinalStringSTRUTS_URL_HELPER="struts.view.urlHelper";
/**{@linkcom.opensymphony.xwork2.conversion.impl.XWorkBasicConverter}**/
publicstaticfinalStringSTRUTS_CONVERTER_COLLECTION="struts.converter.collection";
publicstaticfinalStringSTRUTS_CONVERTER_ARRAY="struts.converter.array";
publicstaticfinalStringSTRUTS_CONVERTER_DATE="struts.converter.date";
publicstaticfinalStringSTRUTS_CONVERTER_NUMBER="struts.converter.number";
publicstaticfinalStringSTRUTS_CONVERTER_STRING="struts.converter.string";
/**EnablehandlingexceptionsbyDispatcher-truebydefault**/
publicstaticfinalStringSTRUTS_HANDLE_EXCEPTION="struts.handle.exception";
publicstaticfinalStringSTRUTS_CONVERTER_PROPERTIES_PROCESSOR="struts.converter.properties.processor";
publicstaticfinalStringSTRUTS_CONVERTER_FILE_PROCESSOR="struts.converter.file.processor";
publicstaticfinalStringSTRUTS_CONVERTER_ANNOTATION_PROCESSOR="struts.converter.annotation.processor";
publicstaticfinalStringSTRUTS_CONVERTER_CREATOR="struts.converter.creator";
publicstaticfinalStringSTRUTS_CONVERTER_HOLDER="struts..converter.holder";
publicstaticfinalStringSTRUTS_EXPRESSION_PARSER="struts.expression.parser";
/**actionsnames'whitelist**/
publicstaticfinalStringSTRUTS_ALLOWED_ACTION_NAMES="struts.allowed.action.names";
/**enablesaction:prefix**/
publicstaticfinalStringSTRUTS_MAPPER_ACTION_PREFIX_ENABLED="struts.mapper.action.prefix.enabled";
/**enablesaccesstoactionsinothernamespacesthancurrentwithaction:prefix**/
publicstaticfinalStringSTRUTS_MAPPER_ACTION_PREFIX_CROSSNAMESPACES="struts.mapper.action.prefix.crossNamespaces";
publicstaticfinalStringDEFAULT_TEMPLATE_TYPE_CONFIG_KEY="struts.ui.templateSuffix";
/**AllowsoverridedefaultDispatcherErrorHandler**/
publicstaticfinalStringSTRUTS_DISPATCHER_ERROR_HANDLER="struts.dispatcher.errorHandler";
/**Commadelimitedsetofexcludedclassesandpackagenameswhichcannotbeaccessedviaexpressions**/
publicstaticfinalStringSTRUTS_EXCLUDED_CLASSES="struts.excludedClasses";
publicstaticfinalStringSTRUTS_EXCLUDED_PACKAGE_NAME_PATTERNS="struts.excludedPackageNamePatterns";
/**Dedicatedservicestocheckifpassedstringisexcluded/accepted**/
publicstaticfinalStringSTRUTS_EXCLUDED_PATTERNS_CHECKER="struts.excludedPatterns.checker";
publicstaticfinalStringSTRUTS_ACCEPTED_PATTERNS_CHECKER="struts.acceptedPatterns.checker";
/**Constantisusedtooverrideframework'sdefaultexcludedpatterns**/
publicstaticfinalStringSTRUTS_OVERRIDE_EXCLUDED_PATTERNS="struts.override.excludedPatterns";
publicstaticfinalStringSTRUTS_OVERRIDE_ACCEPTED_PATTERNS="struts.override.acceptedPatterns";
publicstaticfinalStringSTRUTS_ADDITIONAL_EXCLUDED_PATTERNS="struts.additional.excludedPatterns";
publicstaticfinalStringSTRUTS_ADDITIONAL_ACCEPTED_PATTERNS="struts.additional.acceptedPatterns";
}
其中
/**Commaseparatedlistofpatterns(java.util.regex.Pattern)tobeexcludedfromStruts2-processing*/ publicstaticfinalStringSTRUTS_ACTION_EXCLUDE_PATTERN="struts.action.excludePattern";
保存了不由struts2处理的路径,我们在struts.properties或者struts.xml中配置即可.
struts.action.excludePattern=/dwr/.*,/dwr/test/.*
正则表达式,并非URL匹配地址
总结
以上就是本文关于struts2配置静态资源代码详解的全部内容,希望对大家有所帮助。感兴趣的朋友可以参阅:struts2静态资源映射代码示例 Struts2通过ognl表达式实现投影 Struts2修改上传文件大小限制方法解析 等,有什么问题可以随时留言,小编会及时回复大家的。感谢朋友们对本站的支持。