当前位置 : 主页 > 编程语言 > c++ >

过滤器 过滤同一文件甲

来源:互联网 收集:自由互联 发布时间:2021-07-03
gistfile1.txt package com.fz.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.serv
gistfile1.txt
package com.fz.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("/admin/*")
public class AuthFilter implements Filter {

	@Override
	public void destroy() {
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse res, FilterChain c) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest)req;
		HttpServletResponse response = (HttpServletResponse) res;
		HttpSession s = request.getSession();
		String url = request.getRequestURI();
		//System.out.println(url);
		if(!url.endsWith("login.jsp") && s.getAttribute("admin")==null){			
			if(req.getParameter("type")!=null && req.getParameter("type").equals("login")){
			}else{
				response.setCharacterEncoding("utf-8");
				PrintWriter out = response.getWriter();
				out.print("");
				out.flush();
				out.close();
			}
			
			//response.sendRedirect("adminlogin.jsp");
		}
		c.doFilter(req, res);
	}

	@Override
	public void init(FilterConfig cfg) throws ServletException {
	}

}
网友评论