UseFilter.java
import java.io.IOException;
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;
@WebFilter("/*")
public class UseFilter implements Filter{
//private FilterConfig filterConfig;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
//this.filterConfig = filterConfig;
}
@Override
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain filterChain) throws IOException, ServletException {
try {
System.out.println("客户端的请求经过这里!");
filterChain.doFilter(req, resp);
System.out.println("账号和密码请求处理经过这里!");
HttpServletRequest request=(HttpServletRequest) req;
HttpServletResponse response=(HttpServletResponse) resp;
request.getRequestDispatcher("index.jsp").forward(request, response);
} catch (ServletException e) {
System.out.println("客户端请求失败!");
}catch(IOException io){
System.out.println("账号和密码请求失败!");
}
}
@Override
public void destroy() {
}
}
index.jsp
<body>
哈哈
</body>
5.PNG
6.PNG
网友评论