本文实例为大家分享了jsp实现登录验证的过滤器,供大家参考,具体内容如下
1.新建一个Dynamic Web Project项目,里面新建1个filter文件、1个servlet文件和2个jsp文件,整体的框架如图所示:
2.LoginFilter.java里面的代码如下所示:
package filter;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebFilter(filterName = "loginFi