UseFilter.java
@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 {
HttpServletRequest request=(HttpServletRequest) req;
HttpServletResponse response=(HttpServletResponse) resp;
String imurl = request.getHeader("imurl");//连接的来源地址
if(imurl==null||!imurl.contains(request.getServerName())){//判断访问来源
request.getRequestDispatcher("/images/a.PNG").forward(request, response);
}else {
filterChain.doFilter(request, response);
request.getRequestDispatcher("index.jsp").forward(request, response);
}
}
@Override
public void destroy() {
}
}
7.PNG
8.PNG
网友评论