Spring 3.0 unable to forward request from HandlerInterceptorAdapter

﹥>﹥吖頭↗ 提交于 2020-01-03 02:24:27

问题


I want to redirect to home page if session get invalid. My spring-servlet.xml is

<mvc:interceptors>
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
    <mvc:interceptor>
        <mvc:mapping path="/**" />
        <bean class="com.xxx.MyInterceptor" />
    </mvc:interceptor>
</mvc:interceptors>

Interceptor :

public boolean preHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler) throws Exception {
        if ((null == request.getSession(false))
                || (null == request.getSession(false).getAttribute(
                        "user"))) {
            System.out.println("user logged out...");
            RequestDispatcher rd = request.getRequestDispatcher("loginForm.htm");
            rd.forward(request, response);
            return false;
        }
        return super.preHandle(request, response, handler);
    }

But its not working... Whenever application get started, the message get printed multiple times and at the end it gives stack overflow..

Thank You.


回答1:


It seems like the problem is in your mapping path. Since its mapped with /** your loginForm.htm is also getting intercepted. You have two solutions available to resolve this problem.

Either define <mvc:resources location="/resources/" mapping="/resources/**" /> so that the *.htm requests will not be intercepted. Replace the location and mapping values as per your path where the *.htm files are.

And another option is to change your mapping in intercepter with something like /*.do or something else.

Hope this helps you. Cheers.



来源:https://stackoverflow.com/questions/11132653/spring-3-0-unable-to-forward-request-from-handlerinterceptoradapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!