当前位置: 代码迷 >> J2EE >> SpringMVC 拦截器exclude-地图ping 重定向
  详细解决方案

SpringMVC 拦截器exclude-地图ping 重定向

热度:804   发布时间:2016-04-17 23:00:38.0
SpringMVC 拦截器exclude-mapping 重定向

<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<mvc:exclude-mapping path="/login"/>
<mvc:exclude-mapping path="/index"/>
<bean class="com.xl.interceptor.MyInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>

xml配置是这样的。

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if(null != request.getSession().getAttribute(Constant.IDENTIFICATION)) {

return true;
}
response.sendRedirect(request.getContextPath() + "/login"); 
return false;
}

/login 貌似还是被拦截了,chrome显示循环重定向了
------解决思路----------------------
你mapping  "/**"的时候估计就拦截了

看看吧
------解决思路----------------------
<mvc:mapping?path="/**"/>改成?<mvc:mapping?path="/"/>试试
------解决思路----------------------
mvc-config-interceptors

15.12.2 mvc:interceptors

This tag allows you to register custom HandlerInterceptors or WebRequestInterceptors that should be applied to all HandlerMapping beans. You can also restrict the URL paths specifc interceptors apply to.

An example of registering an interceptor applied to all URL paths:

<mvc:interceptors>
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
</mvc:interceptors>

An example of registering an interceptor limited to a specific URL path:

<mvc:interceptors>
    <mvc:interceptor>
        <mapping path="/secure/*"/>
        <bean class="org.example.SecurityInterceptor" />
    </mvc:interceptor>
</mvc:interceptors>


得根据你的路径看,


  相关解决方案