<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/springmvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<url-pattern>/</url-pattern>
会匹配到/login这样的路径型的url,不会匹配到模式为*.jsp这样的后缀型url。故经过视图解析器后返回jsp视图时不会再进入DispatcherServlet。说到为什么JSP页面的请求并不会命中这个Servlet,那是因为servlet容器内建的JSP Servlet将会被调用,而这个容器内建的JSP Servlet已经默认地映射在了*.jsp上。但还是能拦截到静态资源,如*.js,*.css。
<url-pattern>/*</url-pattern>
会匹配所有的url:路径型的和后缀型的url(包括/login,*.jsp,*.js和*.html等)。故经过视图解析器后返回jsp视图时会再进入DispatcherServlet,导致找不到对应的controller所以报404错。
No mapping found for HTTP request with URI [/Shiro-Spring/WEB-INF/jsp/login.jsp] in DispatcherServlet with name ‘springmvc’