07.SpringMVC of static resources

How do you DispatcherServlet intercept * .do this URL, there is no problem of access than static resources. If your DispatcherServlet block "/", to intercept all requests, while the * .js, *. Jpg access will be blocked.

Option One: Activate the Tomcat defaultServlet static files

 

 To configure multiple, each a configuration file. Write in front DispatcherServlet, so defaultServlet first interception, this will not enter the Spring, I think it is the best performance.

Scheme II using <mvc: default-servlet-handler />

<mvc:default-servlet-handler />

Disposed in springMVC-servlet.xml: after <mvc default-servlet-handler />, defines a org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler in Spring MVC context, it will be like an inspector, entering DispatcherServlet the URL screening, if found to be a static resource request, it forwards the request is handled by the default Web application server Servlet, if the request is not static resources before continuing to process the DispatcherServlet.

General Servlet Web application server default name is "default", thus DefaultServletHttpRequestHandler can find it. If the default Servlet names of all of your Web application server is not a "default", you need to display specified by default-servlet-name attribute:

< MVC: default the servlet-Handler- default-the servlet-name = "name of the Servlet Web server uses the default"  />

Scheme III: in the spring <mvc: resources />

<mvc: default-servlet-handler /> will be returned to deal with static resources Web application server process via the Spring MVC framework. The <mvc: resources /> Furthermore, by the Spring MVC framework to handle their own static resources, and add some useful value-added features.
<mvc: resources /> allows static resources placed anywhere, such as the WEB-INF directory, class path and the like. Static resources specified location by the location attribute, since the location attribute is Resources type, can be used as "classpath:" prefix specifies resources such as resource location. Web container traditional static resources can only be placed in the root path of the Web container, <mvc: resources /> completely eliminates this restriction.
<mvc: resources /> optimized for static resources based on currently known Page Speed, YSlow and other browser optimization principles. You can specify static resources by cacheSeconds property at the time the browser cache, and can be set for one year the time to take advantage of the browser's cache. When the output of static resources, will be a good response packet header Expires and Cache-Control value according to configuration settings.

<mvc:resources location="classpath:/META­INF/publicResources/" mapping="/resources/**"/>

 

Guess you like

Origin www.cnblogs.com/deityjian/p/11495059.html