Struts2 no extension
Many of struts2's friends want to modify or remove the action extension. This article helps you implement
Struts2-core-2.3.16.jar,: http://repo1.maven.org/maven2/org/apache/struts/struts2-core/2.3.16/
Org. apache. struts2.dispatcher. ng. filter. strutsPrepareAndExecuteFilter, which is the doFilter function used by struts2 to process requests. prepare is used here. isUrlExcluded to determine whether to exclude the request. If yes, the chain is executed directly. doFilter (request, response); to other filters; otherwise, you can process the action yourself.
//... // Protected PrepareOperations prepare; public void doFilter (ServletRequest req, res, FilterChain chain) throws IOException, response {HttpServletRequest request = (HttpServletRequest) req; response = (response) res; try {if (excludedPatterns! = Null & prepare. isUrlExcluded (request, excludedPatterns) {// check the chain here. doFilter (request, response);} else {prepare. setEncodingAndLocale (request, response); prepare. createActionContext (request, response); prepare. assignDispatcherToThread (); request = prepare. wrapRequest (request); ActionMapping mapping = prepare. findActionMapping (request, response, true); if (mapping = null) {boolean handled = Execute.exe cuteStaticResourceRequest (request, response); if (! Handled) {chain. doFilter (request, response) ;}} else {execute.exe cuteAction (request, response, mapping) ;}} finally {prepare. cleanupRequest (request );}}//...
Org. apache. struts2.dispatcher. ng. PrepareOperations
/** * Check whether the request matches a list of exclude patterns. * * @param request The request to check patterns against * @param excludedPatterns list of patterns for exclusion * * @return true if the request URI matches one of the given patterns */ public boolean isUrlExcluded( HttpServletRequest request, List
excludedPatterns ) { if (excludedPatterns != null) { String uri = RequestUtils.getUri(request); for ( Pattern pattern : excludedPatterns ) { if (pattern.matcher(uri).matches()) { return true; } } } return false; }
After the above analysis, now look at the struts2 default configuration file default. properties, in the struts2-core-2.3.16.jar, org. apache. truts2 below
### Used by the DefaultActionMapper### You may provide a comma separated list, e.g. struts.action.extension=action,jnlp,do### The blank extension allows you to match directory listings as well as pure action names### without interfering with static resources, which can be specified as an empty string### prior to a comma e.g. struts.action.extension=, or struts.action.extension=x,y,z,,struts.action.extension=action,,
According to the description, you can set the value of struts. action. extension to a comma to support actions without an extension. If you want to be compatible with the previous one, you can add the preceding values, for example:
struts.action.extension=do,action,jspt,,
In addition, if the struts2 version you are using is earlier than 2.3.16 (as for the specific version, I did not test it), the static resource js and css may be eaten, you can add the following attributes:struts.action.excludePattern=/css,/javascript
In some projects, JavaScript and css are compressed by servlets such:
<script src="/compressor?v=${globalVersion}&type=js&munge=true&files=/javascript/lib/json2/json2.js,/javascript/lib/jquery/1.7.2/jquery.js,/javascript/lib/jquery/jquery.ext.js,/javascript/lib/juicer/0.6.1/juicer-min.js,/javascript/lib/underscore/1.3.3/underscore-min.js,/javascript/lib/cookie/cookie.min.js,/javascript/core/core.js,/javascript/core/toptips.js,/javascript/core/selectBankCard.js,/javascript/core/dialog.js,/javascript/core/page.js,/javascript/core/regex.js,/javascript/core/topLogRegister.js"type="text/javascript"></script>
That is, use servlet compressor to output js and css files. The configuration should be as follows:struts.action.excludePattern=/compressor
Note: It is best to use struts When configuring struts2. properties. using the same configuration in xml is not compatible with the previous ". do ", if struts. properties and struts. xml exists at the same time, struts. properties has a higher priority than struts. xml