I want to achieve this function:when user login the system,if he hasn't operated a long time,how to logout the system and skip to login page?I use a filter class which implements Filter,and when satisfy a certain condition,then sendRedirect() to login page. But when i deploy the project and run it,the following issue have occurred: because the expired parameter i set is 45s,so ,after i logining into the system for 45 seconds,the request "http://localhost:8082/login" which report 200,but it doesn't skip to login page and others requests reported 302.Here is the code :
@Component@WebFilter(urlPatterns = {"/com/jeeplus/*"})public class SessionFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest req=(HttpServletRequest)servletRequest; HttpServletResponse res=(HttpServletResponse)servletResponse; HttpSession session = req.getSession(); String name =(String) session.getAttribute("name"); String url=req.getRequestURI(); //获取请求相对路径 if(!req.getRequestURI().equals("/sys/login") && !req.getRequestURI().equals("/sys/sysConfig/getConfig") && !req.getRequestURI().equals("/sys/getCode")){ if(Objects.isNull(name)){// 返回登录界面 res.sendRedirect("http://localhost:8082/login"); return; } } filterChain.doFilter(servletRequest,servletResponse); }}
After i login into the system for 45 seconds,i wish to jump to login page which is "http://localhost:8082/login".