With Struts2 small partners very much want to change or remove the action extension, this article will help you implement
Struts2-core-2.3.16.jar, download Link: http://repo1.maven.org/maven2/org/apache/struts/struts2-core/2.3.16/
Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter, this struts2 the function that handles the request dofilter. Here, prepare.isurlexcluded is used to infer whether the request was excluded. Assume that you are running Chain.dofilter directly (request, response), to other filter processing, or you are handling this action yourself
...//protected prepareoperations prepare; public void DoFilter (ServletRequest req, servletresponse Res, Filterchain chain) throws IOException, Servletexception { HttpServletRequest request = (httpservletrequest) req; HttpServletResponse response = (httpservletresponse) res; try {if (excludedpatterns! = null && prepare.isurlexcluded (Request, Excludedpatterns)) {//See here Chain.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.executestaticresourcerequest (request, response); if (!handled) { Chain.dofilter (request, response); }} else {execute.executeaction (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 Exclus Ion * * @return <tt>true</tt> if the request URI matches one of the given patterns */public B Oolean isurlexcluded (httpservletrequest request, list<pattern> 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 default configuration file for Struts2 default.properties, Struts2-core-2.3.16.jar, org.apache.truts2 below
# # used by the defaultactionmapper### 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 St atic resources, which can be specified as an empty string### prior to a comma e.g. struts.action.extension=, or Struts.act Ion.extension=x,y,z,,struts.action.extension=action,,
According to descriptive narration. The ability to set the value of Struts.action.extension to a comma can support an action with no extension. If you want to be compatible, you can join in between, such as:
<pre name= "code" class= "plain" >struts.action.extension=<span style= "font-family:arial, Helvetica, Sans-serif; " >DO,ACTION,JSPT,, </span>
Other than that. Assume that you are using a struts2 version number below 2.3.16 (as far as the detail that version number is excessive.) I did not test), static resources js,css may be eaten, can be added for example, one of the following properties
Struts.action.excludepattern=/css,/javascript
Some projects to deal with JS and CSS in the way is the JS, CSS compression servlet, such as:
<link type= "Text/css" rel= "stylesheet" href= "/compressor?v=${globalversion}&type=css&munge=true&files=/cssstyle/index.css,/cssstyle/dialog.css,/cssstyle/ Jbox/gray/jbox.css,/cssstyle/home.css "><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>
Even if you output JS and CSS files with servlet compressor, the configuration should be as follows
Struts.action.excludepattern=/compressor
To filter requests that begin with "/druid" and "/compressor", the pattern is as follows ( Note that ". *" is added.) And not just "*")
struts.action.excludepattern=/compressor.*,/druid.*
Note: When setting the Struts2 configuration. It is best to use struts.properties, because I use the same configuration in Struts.xml, it is not compatible with the ". Do". Assuming that struts.properties and struts.xml exist at the same time, Struts.properties will have a higher priority than struts.xml
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
Struts2 no extension (Excludepattern)