spingmvc <mvc:exclude-mapping path=""/>不起作用

springMvc的配置如下,可以直接访问index.jsp 和fail.html,但是无法访问user/login方法。

<mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**"/>
            <mvc:exclude-mapping path="/user/login"/>
            <mvc:exclude-mapping path="/fail.html"/>
            <mvc:exclude-mapping path="/index.jsp"/>
            <bean class="com.kpr.interceptor.Authority"/>
        </mvc:interceptor>
    </mvc:interceptors>

Controller代码如下

@RequestMapping(value = "user/login", method = RequestMethod.POST)
    public ModelAndView login(HttpSession session, @RequestParam("form-username") String name,
                              @RequestParam("form-password") String pw) {
        ModelAndView mav = new ModelAndView();
        if (userService.confirmUser(name, pw)) {
            session.setMaxInactiveInterval(1800);
            session.setAttribute("Status", "online");
            mav.setViewName("redirect:/manage/set");
        } else {
            mav.setViewName("redirect:/index.jsp");
        }
        return mav;
    }

当登陆的时候,拦截类就会拦住这个请求,可是mvc已经配置了过滤这个路径。求大神指点一下,那个interceptor的代码:

public class Authority implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        if (httpServletRequest.getSession(false) != null) {
            if (httpServletRequest.getSession(false).getAttribute("Status") != null)
                return true;
        }
        String s=httpServletRequest.getContextPath();
        System.out.println(httpServletRequest.getRequestURI()+"---被拦截---");
        httpServletResponse.sendRedirect(s+"/index.jsp");
        return false;
    }
   }

结果:
clipboard.png

阅读 6.4k
2 个回答

web.xml的配置org.springframework.web.servlet.DispatcherServlet的url-pattern配置为:

<url-pattern>/</url-pattern>

今天又能拦截了,莫名其妙的,也许是缓存什么的问题。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题