日期:2014-05-16 浏览次数:20340 次
应用springMVC时如果配置URL映射时如下配置
<servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
方法一:在web.xml中添加
<servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.css</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.gif</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.jpg</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.js</url-pattern> </servlet-mapping>指明对于如上资源文件不采用spring的过滤器
关于default是tomcat配置的一个servlet,“DefaultServlet被定义在$CATALINA_HOME/conf/web.xml中,配置文件中被定义的东西会在Tomcat启动的时候
被加载,对所有的webapp都有效。DefaultServlet在Tomcat中主要是做目录列表(Directory Listing)用 ”
<servlet> <servlet-name>default</servlet-name> <servlet-class> org.apache.catalina.servlets.DefaultSe