登录拦截器 500错误

新手上路看视频整个登录拦截器,发现中英切换、其他登录都报500错误,登录拦截器 500错误_第1张图片
登录拦截器 500错误_第2张图片
屏蔽掉新添加的拦截代码

 @Override//拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("index.html","/","user/login","/css/*","/js/**","/img/**");
    }

发现功能正常,捣鼓半天是“index.html”忘记“/”,修改即可正常

 @Override//拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/index.html","/","/user/login","/css/*","/js/**","/img/**");
    }

贴上拦截器相关代码:

//登录拦截
public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
       //登录成功有用户的session
       Object loginUser= request.getSession().getAttribute("loginUser");
       if(loginUser==null){
           request.setAttribute("msg","没有操作权限,请先登录!");
           request.getRequestDispatcher("index.html").forward(request,response);
           return false;
       }
       else {
           return true;
       }
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}

 @Override//拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/index.html","/","/user/login","/css/*","/js/**","/img/**");
    }

你可能感兴趣的:(菜鸟上路)