Springmvc Configure Dispatchservlet to filter all requests:
<servlet> <Servlet-name>Mvc-dispatcher</Servlet-name> <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class> <Load-on-startup>1</Load-on-startup> </servlet> <servlet-mapping> <Servlet-name>Mvc-dispatcher</Servlet-name> <Url-pattern>/</Url-pattern> </servlet-mapping>
will cause all static resources such as: JS, CSS, PNG, GIF and other pages interception, this is not what we expected.
Workaround:
1. Take advantage of Spring's features:
<mapping= "/skins/**" location= "/skins/"/>
For access to files under the mapping path, direct to location.
Problem: Introducing static resources requires knowing that content Path cannot be introduced in content Path,css
2. Use the default servlet to filter static resources without using Dispatchservlet
Configure in Web. xml
< servlet-mapping > < Servlet-name >default</servlet-name> <Url-pattern >/skins/*</url-pattern></ Servlet-mapping>
For resources that have skins in access routes, use the default servlet
3. Use the default servlet to filter specific file name extensions
Configure in Web. xml
<servlet-mapping> <Servlet-name>Default</Servlet-name> <Url-pattern>*.png</Url-pattern> <Url-pattern>*.js</Url-pattern> <Url-pattern>*.css</Url-pattern> </servlet-mapping>
Similar to Method 2
We can choose the most suitable method according to their actual situation.
Springmvc static resource processing [go]