Spring 3.0无法转发来自HandlerInterceptorAdapter的请求 [英] Spring 3.0 unable to forward request from HandlerInterceptorAdapter
问题描述
如果会话无效,我想重定向到主页. 我的spring-servlet.xml是
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>
拦截器:
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..
谢谢.
推荐答案
问题似乎出在您的映射路径中.由于其映射为/**
,因此您的loginForm.htm也将被拦截.您可以使用两种解决方案来解决此问题.
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.
都可以定义<mvc:resources location="/resources/" mapping="/resources/**" />
,以便不会截获* .htm请求.根据您的* .htm文件所在的路径替换位置和映射值.
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.
另一种选择是使用/*.do
之类的东西来更改拦截器中的映射.
And another option is to change your mapping in intercepter with something like /*.do
or something else.
希望这对您有所帮助.干杯.
Hope this helps you. Cheers.
这篇关于Spring 3.0无法转发来自HandlerInterceptorAdapter的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!