getRequestDispatcher_html


 

try {
Object user = request.getSession().getAttribute("username");

if (user == null) {
request.setAttribute("msg", "无权限,请先登录!");
response.sendRedirect(request.getContextPath()+"/system/login");
return false;
}
} catch (IOException e) {
e.printStackTrace();
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
//注册TestInterceptor拦截器
InterceptorRegistration registration = registry.addInterceptor(new LoginInterceptor());
registration.addPathPatterns("/**"); // 拦截所有路径
registration.excludePathPatterns(
"/**/*.html",
"/**/*.js",
"/**/*.css",
"/**/*.woff",
"/**/*.ttf"
);
}

解析:


  1. 首次登录:http://localhost:8091/system/login 2. 拦截器会拦截/system/login 3.  1-2-1死循环   解决方案:

 

@Override
public void addInterceptors(InterceptorRegistry registry) {
//注册TestInterceptor拦截器
InterceptorRegistration registration = registry.addInterceptor(new LoginInterceptor());
registration.addPathPatterns("/**"); // 拦截所有路径
registration.excludePathPatterns(
"/system/**", // 排除system路径下所有文件
"/**/*.html",
"/**/*.js",
"/**/*.css",
"/**/*.woff",
"/**/*.ttf"
);
}

 


参考链接: