public class ValidateSession extends HandlerInterceptorAdapter {
//before the actual handler will be executed
public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
HttpSession session = request.getSession();
if(session.getAttribute("user")==null){
/*ModelAndView mav = new ModelAndView("/login/index");
throw new ModelAndViewDefiningException(mav);*/
ModelAndView mav = new ModelAndView();
mav.setViewName("redirect:/login/index.mars");
throw new ModelAndViewDefiningException(mav);
}
return true;
}
}
在我的情況下,如果會話過期,則用戶無法訪問我的應用程序,但我堅持重定向循環。雖然我已經嘗試了許多可能的方式,但沒有運氣:(如何避免在春季web重定向循環mvc
感謝稔,但攔截器沒有與路徑工作=追加「/ *」,任何想法我怎麼可以啓用整個應用程序的攔截器。 –
它通過添加 –