I am using SpringMVC and trying to use pure HTML + JS as the view. I noticed that there are potentially 3 possible places that could handle a static resource like login.html. They are:
The controller handler method which is mapped to a
seeminglystatic resource URL.@RequestMapping(value = "login.html") public String doLogin(Model model) { return "login"; }The
addResourceHandlerswhich designates the static resource type and location:public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("*.html").addResourceLocations(("/static/")); }And Tomcat's
DefaultServlet, which by definition, is meant toserve static resources. And can be enabled in SpringMVC as below:@Override public void configureDefaultServletHandling( DefaultServletHandlerConfigurer configurer) { // TODO Auto-generated method stub configurer.enable(); }
My questions are:
- How does a servlet container like Tomcat determine a resource is static or not? Is it based on some well-known file name extension?
- What's the precedence of the 3 options above?
- What's the relationship between the Spring configuration method
addResourceHandler()and the TomcatDefaultServlet? My guess isaddResourceHandler()tellsDefaultServletwhere to find certain type of static resources.
Some related links:
Resource served by SpringMVC's ResourceHttpRequestHandler.
21.16.10 Falling Back On the "Default" Servlet To Serve Resources
Resource served by servlet container's DefaultServet via SpringMVC's DefaultServletHttpRequestHandler