package com.mingrisoft.filter; 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; import com.mingrisoft.Function; /** * Created by Administrator on 2018/11/6 */ @WebFilter(urlPatterns = "/admin/*") public class AdminFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { Function Function1 = new Function(); HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; boolean isLogin = Function1.StringToBoolean((String) request.getSession().getAttribute("Login")); if (!isLogin) { response.sendRedirect(request.getContextPath() + "/front/login"); }else { filterChain.doFilter(servletRequest,servletResponse); } } @Override public void destroy() { } }