Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to do login check and page jump by springMVC interceptor

Shulou Source: shulou.com Published: 2022-06-03 07:27:58 11月22日 Update

A very simple login permission interceptor

Question 1: login page submission request must be filtered out, currently configured in xml to filter, can you configure not to intercept certain requests. If you need to intercept requests in this configuration, it's too much trouble when there are too many requests.

Question 2: I simply determine whether the session has a value in the interceptor, if there is a login, if not jump to the login page. The way I do it is not good. Is there a correct and effective method?

Question 3: If you can give a solution to jump pages in the interceptor, my login.jsp is placed under WEB-INF. When jumping through ModelAndView, the view parser will jump to/WEB-INF/login.jsp, which is definitely not the page. But if I put it in this folder, the browser won't be able to access the login.jsp page.

public class UserInterceptor implements HandlerInterceptor{ @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object obj, Exception err) throws Exception { } @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object obj, ModelAndView mav) throws Exception { response.sendRedirect("/login.jsp"); } @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception { String str = (String) request.getSession().getAttribute("isLogin"); System.out.println("str=========>"+str); if(str!= null){ return true; } return false; } }

Get [Download address]

Tags: Page login interceptor problem configuration face-to-face affirmative no valid but not practice address file folder scheme method time permission browser view Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology vpn Apple Redmi MySQL