SpringMVC deal with static resources

SpringMVC deal with static resources: 

1. Why is there such a problem: 

Elegant REST-style URL resources such as .html or do not want to bring .do suffix 

If the request DispatcherServlet configure the mapping /, 

SpringMVC will capture all the requests WEB container, including requests for static resources, they will be treated as an ordinary SpringMVC request processing, 

Could not find the corresponding processor will result in an error. 

2. Solution: Configure the SpringMVC configuration file <mvc: default-servlet-handler /> way to solve the problem of static resources.


default-servlet-handler defined in SpringMVC DefaultServletHttpRequestHandler a context, it would be screened for incoming requests DispatcherServlet 

If the request has not been found to be mapping process, the request referred WEB application server default Servlet process. If it is not a static resource request before continuing to process the DispatcherServlet 

General WEB application server Servlet default name is default. 

If the WEB server uses the default name is not Servlet default, then by the need to explicitly specify the default-servlet-name attribute


In fact, only the configuration <mvc: default-servlet-handler /> is not enough, but also the distribution <mvc: annotation-driven> </ mvc: annotation-driven>

20161111085151372

Guess you like

Origin blog.51cto.com/14028890/2425543