I used *. Do all the time, but *. Do is ugly, so I used "/" to configure it:
<Servlet> <servlet-Name> dispatcherservlet </servlet-Name> <servlet-class> Org. springframework. web. servlet. dispatcherservlet </servlet-class> <load-on-startup> 1 </load-on-startup> </servlet> <servlet-mapping> <servlet-Name> dispatcherservlet </ servlet-Name> <URL-pattern>/</url-pattern> </servlet-mapping>
But the problem isHow can I access static files, such as JPG, JS, and CSS?
If your dispatcherservlet intercepts a URL with a suffix such as "*. Do", you will not be able to access static resources.
If your dispatcherservlet intercepts "/" and intercepts all requests in order to implement the REST style, access to static files such as *. js and *. jpg will also be blocked.
We need to solve this problem.
Purpose: To access a static file normally. If the static file cannot be found, the Error 404 is returned.
Solution 1: Activate Tomcat's defaservlet servlet to process static files
<Servlet-mapping> <servlet-Name> default </servlet-Name> <URL-pattern> *. JPG </url-pattern> </servlet-mapping> <servlet-Name> default </servlet-Name> <URL-pattern> *. JS </url-pattern> </servlet-mapping> <servlet-Name> default </servlet-Name> <URL-pattern> *. CSS </url-pattern> </servlet-mapping>
Before dispatcherservlet, let DefaultServlet intercepts the request first so that the request will not enter spring. I think the performance is the best.
Tomcat, Jetty, JBoss, and glassfish default servlet name -- "default"
Google App EngineBuilt-in Default servlet name -- "_ ah_default"
ResinBuilt-in Default servlet name -- "Resin-file"
WebLogic Built-in Default servlet name -- "fileservlet"
WebSphereBuilt-in Default servlet name -- "simplefileservlet"
There are two other solutions, you can refer to: http://blog.csdn.net/this_super/article/details/7884383