When you enable the STRUTS2 core filter in Web. XML, you basically follow this notation:
<filter><filter-name>struts2</filter-name><filter-class> org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter</filter-class></filter>< filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></ Filter-mapping>
This indicates that for the context of the project, allSubmit Requestare transferred to STRUTS2, and since it is a filter, the same request will be prioritized over the other servlet.
(Note that the dispatcher of filter defaults to request ( submitting requests ), and redirects are counted as such.) If filter adds forward dispatcher, the forwarding request is also included)
So here's the question:
1. Although all requests are transferred to STRUTS2 processing, why does the "only" request end with a. Action require an action mapping, and requests such as *.jsp, *.html,*.css, *.js, and so on, do not have to be accessed normally without an action mapping?
2. Why do I need action mapping for requests such as SERVLET,*?WSDL, or will Struts2 report "Could not find action or result ..." error?
3. Why does the Struts2 tag in the JSP expire after changing the Struts2 url-pattern to "*.action" in Web. xml?
In fact, under the url-pattern= "/*", Struts2 really will stop all requests, whether *.action,*.jsp, *.html,*.css, *.js or servlet,*?wsdl, which means that these intercepted requests,
1. If the STRUTS2 label is used inside, it can be parsed by Struts2. (this explains the question 3, if *.jsp is not controlled by Struts2, then of course it is not possible to use the STRUTS2 label)
2. The action mapping may be required.
So what exactly is the request for action mapping? There is a default.properties under the ORG.APACHE.STRUTS2 package, which has a default configuration:
# # used by the defaultactionmapper### provide a comma separated list, e.g. Struts.action.extension=action,jnlp,do <span style= "color: #FF0000;" >### The blank extension allows you to match directory listings as well as pure action names### without interfering wit h static resources, which can be specified as an empty string### prior to a comma</span> e.g. Struts.action.extensio N=, or Struts.action.extension=x,y,z,,struts.action.extension=action,,
The original Struts2 to determine what kind of interception request to do the action map is specified by this configuration, the default includes the extension". Action"The request and"Empty extension"The request.
Thus, although *.jsp, *.html,*.css, *.js were intercepted, they all have their own non-". Action" extension, so they do not meet the requirements of participating in the action map, and therefore can be accessed normally.
As for requests such as SERVLET,*?WSDL, they are "empty extensions", so Struts2 require them to participate in the action map, otherwise they will report "Could not find action or result ..." error.
In addition, when developing Struts2, there are sometimes "cyclic forwarding" or "cyclic redirection" errors, such as the following misconfiguration:
Xml:
<filter><filter-name>struts2</filter-name><filter-class> org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter</filter-class></filter>< filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern>< dispatcher>request</dispatcher> <span style= "color: #FF0000;" ><dispatcher>FORWARD</dispatcher></span></filter-mapping>
Struts.xml
<package name= "defaultmapping" ><action name= "*" ><result>{1}</result><!--cycle Forward-- <!--cyclic redirection <result type= "redirect" >{1}</result>--></action></package>
If a commit request needs to be similar to the default forwarding above (implementing action release), However, due to the STRUTS2 core filter in Web. XML, the forwarding request was also intercepted, so Struts2 again captured the request forwarded by Struts2 himself, then mapped and forwarded out, and again captured ... thus causing cyclic forwarding. (The process of cyclic redirection is similar to cyclic forwarding, no longer described)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
What types of requests do Struts2 handle?