IPFilter.java
上传用户:lsj999sz
上传日期:2022-06-15
资源大小:4717k
文件大小:1k
源码类别:

ICQ/即时通讯

开发平台:

Java

  1. package com.bjsxt.shopping.util.filter;
  2. import java.io.IOException;
  3. import java.io.PrintWriter;
  4. import javax.servlet.Filter;
  5. import javax.servlet.FilterChain;
  6. import javax.servlet.FilterConfig;
  7. import javax.servlet.ServletException;
  8. import javax.servlet.ServletRequest;
  9. import javax.servlet.ServletResponse;
  10. public class IPFilter implements Filter {
  11. FilterConfig fc = null;
  12. public void destroy() {
  13. System.out.println("IPFilter destroy");
  14. }
  15. public void doFilter(ServletRequest req, ServletResponse resp,
  16. FilterChain chain) throws IOException, ServletException {
  17. //System.out.println("IPFilter dofilter");
  18. String ip = req.getRemoteAddr();
  19. String strIPBlackList = fc.getInitParameter("IPBlackList");
  20. if(strIPBlackList.indexOf(ip) != -1) {
  21. PrintWriter out = resp.getWriter();
  22. out.println("Your IP is not welcome!");
  23. return;
  24. }
  25. chain.doFilter(req, resp);
  26. }
  27. public void init(FilterConfig fc) throws ServletException {
  28. System.out.println("IPFilter init");
  29. this.fc = fc;
  30. }
  31. }