为什么我的拦截器无法阻止某些URL?

时间:2018-08-05 02:49:31

标签: java spring spring-boot tomcat java-ee

/** WebMvcConfig.class */
@Override
public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(new WebSecurityConfig())
            .addPathPatterns("/**")
            .excludePathPatterns("/login","/loginPost");
    super.addInterceptors(registry);
}
/** WebSecurityConfig.class */
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    boolean flag =true;
    User user=(User)request.getSession().getAttribute("user");
    if(null==user){
        response.sendRedirect("/login");
        flag = false;
    }
    return flag;
}

我添加了一个拦截器,该拦截器在用户未登录时跳至登录页面。当我输入“ http://localhost:8011/git/vision”时,该拦截器将起作用。但是,当我键入此URL'http://localhost:8011/git/vision/index.html'时,拦截器不起作用。这意味着我无需登录即可访问此资源。您能帮助我解决此问题吗?

0 个答案:

没有答案