IPFilter.java
资源名称:JAVAshop.rar [点击查看]
上传用户:sxychgz
上传日期:2019-04-21
资源大小:4772k
文件大小:1k
源码类别:
电子政务应用
开发平台:
Java
- package com.bjsxt.shopping.util.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;
- public class IPFilter implements Filter {
- FilterConfig fc = null;
- public void destroy() {
- System.out.println("IPFilter destroy");
- }
- public void doFilter(ServletRequest req, ServletResponse resp,
- FilterChain chain) throws IOException, ServletException {
- //System.out.println("IPFilter dofilter");
- String ip = req.getRemoteAddr();
- String strIPBlackList = fc.getInitParameter("IPBlackList");
- if(strIPBlackList.indexOf(ip) != -1) {
- PrintWriter out = resp.getWriter();
- out.println("Your IP is not welcome!");
- return;
- }
- chain.doFilter(req, resp);
- }
- public void init(FilterConfig fc) throws ServletException {
- System.out.println("IPFilter init");
- this.fc = fc;
- }
- }