会话的getAttribute在拦截器中返回null

时间:2019-02-15 03:01:13

标签: spring session authentication interceptor

拦截登录时出现问题。 登录时,LoginController中的登录成功,但是Interceptor阻塞,因为会话为空。

在LoginController中 ModelMap model, @Valid LoginForm loginForm, BindingResult bindingResult, @SessionAttribute("LOGGED_IN_USER_DTO") LoginForm loginUserDto

在拦截器中 LoginForm loginUserDto = (LoginForm) request.getSession().getAttribute("LOGGED_IN_USER_DTO"); if (loginUserDto == null || StringUtils.isEmpty(loginUserDto.getUsername())) { request.getSession().setAttribute("LOGGED_IN_USER_DTO", new LoginForm()); response.sendRedirect(request.getContextPath() + "/auth/login"); return false; }

interceptor loginController

0 个答案:

没有答案
相关问题