springMvc is configured as follows. You can access index.jsp and fail.html, directly, but you cannot access the user/login method.
<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>
the Controller code is as follows
@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;
}
the interceptor class blocks the request when logging in, but mvc has configured the Filter path. Ask the great god for advice, the interceptor code:
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;
}
}
result: