If your dispatcherservlet intercepts URLs such as *.do, there is no problem accessing static resources . If your dispatcherservlet intercepts "/", all requests are intercepted, and access to *.js,*.jpg is intercepted.
Purpose: Normal access to static files, do not find static file 404.
Scenario One: Activate Tomcat's defaultservlet to handle static files
<servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.jpg</ Url-pattern></servlet-mapping><servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.js</url-pattern></servlet-mapping><servlet-mapping> <servlet-name> Default</servlet-name> <url-pattern>*.css</url-pattern></servlet-mapping>
To configure multiple, each file is configured with a
To write in front of the Dispatcherservlet, let Defaultservlet first intercept, this will not enter Spring , I think the performance is the best bar.
Tomcat, Jetty, JBoss, and GlassFish the name of the default servlet-the name of the default servlet for the "default" Google App Engine-"_ah_default" Resin default Se Rvlet's name--"Resin-file" WebLogic default servlet name--"Fileservlet" WebSphere default servlet name--"Simplefileservlet"
Scenario two: After the Spring3.0.4 release, MVCis available: resources
<MVC: How to use resources:
<!--access to static resource files--><MVC: Resources mapping= "/images/**" location= "/images/"/>
The/images/** maps to Resourcehttprequesthandler for processing, and location specifies the position of the static resource . Can be the Web application root directory, the jar package inside, this can put Static resources are compressed into the jar package. Cache-period allows static resources to be Web cache
If the following error occurs, there may be no configuration <MVC: Reason for Annotation-driven/>.
Error warning:no mapping found for HTTP request with URI [/MVC/user/finduser/lisi/770] in Dispatcherservlet with Nam E ' Springmvc '
Using the <MVC:resources/> element, register the mapping URI with the simpleurlhandlermapping UrlMap,
Key is the URI pattern value of mapping, and value is Resourcehttprequesthandler,
In this way, the access to static resources is cleverly transferred from handlermapping to Resourcehttprequesthandler processing and returned, so it supports the Classpath directory, the static resources inside the jar package. The access.
It is also important to note that you do not set DefaultHandler on simpleurlhandlermapping. Because the DefaultHandler to the static URI is Resourcehttprequesthandler,
Otherwise, the static resources request cannot be processed.
Scenario three, using <MVC:d efault-servlet-handler/>
This article original link: http://unmi.cc/Spring-MVC-access-static-resources-jpgjscss, from: Yehuang Unmi Blog
<MVC:d efault-servlet-handler/>
The "/**" URL will be registered to the Simpleurlhandlermapping UrlMap, and the access to the static resource is transferred from Handlermapping to Org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler processed and returned.
Defaultservlethttprequesthandler use is the default servlet for each servlet container.
Additional note: The order of execution of multiple handlermapping issues:
The Defaultannotationhandlermapping Order property value is: 0
<MVC: resources/> Autoenroll simpleurlhandlermapping The Order property value is: 2147483646
<MVC:d efault-servlet-handler/> Auto-registered Simpleurlhandlermapping's Order property value is: 2147483647
Spring executes a smaller order value first. When access to a a.jpg picture file, first through the defaultannotationhandlermapping to find the processor, must not be found, we do not call a.jpg Action. And then the order value in ascending, because the last simpleurlhandlermapping is a match "/**", so will definitely match, and then respond to the picture.
Access to a picture, but also to go layer-by-layer matching. I don't know how it's performing. Another day to do a stress test, compared to Apache.
Finally, how do you dispatcherservlet intercept *.do such a URL, do not save the above problem.
Transferred from: http://lzy83925.iteye.com/blog/1186609
SPRINGMVC three ways to access static resources