代码结构如下:
web.xml的配置如下(
loginFilter
*.do
)的配置要小心我被卡住过,静态资源被拦截:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1" metadata-complete="true">
<servlet >
<servlet-name>DispatcherServlet</servlet-name >
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class >
<init-param>
<param-name>contextConfigLocation</param-name >
<param-value>classpath:spring/spring-*.xml</param-value >
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name >
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- 检查用户是否登录过的web.xml配置 -->
<filter>
<filter-name>loginFilter</filter-name>
<filter-class>com.soecode.lyf.filter.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>loginFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>
<