To configure the front controller of springmvc, you need to configure the intercepted path name in web.xml.
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--tomcat启动的时候 就加载这个数字-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
Here I am using .action to intercept paths ending with .action, but there are two ways of / and /*
*.action
<url-pattern>*.action</url-pattern>
- 1
The representative is to intercept the url with the suffix name ending in .action
/
<url-pattern>/</url-pattern>
- 1
Represents intercepting all urls but excluding .jsp urls
/*
<url-pattern>/*</url-pattern>
- 1
Represents interception of all urls and also includes urls with .jsp suffix
Summarize
In our project development, it is generally required to comply with restful .action. It is definitely not possible, because restful does not allow .action. Generally speaking, we also write .jsp pages in the WEB-INF directory, which does not allow direct access and does not require configuration/ * All in general I use / to intercept
This is generally used in development
<url-pattern>/</url-pattern>
- 1
additional
**(It should be noted) The interceptor configuration method in springMVC is different from that in web.xml.
We need to use "/ **" to represent intercepting all
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="com.guxiang.interceptor.Interceptor1"></bean>
</mvc:interceptor>
</mvc:interceptors>