日期:2014-05-18 浏览次数:20997 次
<!-- 拦截器设置,处理session超时,自动跳转到登录页面 -->
<context:annotation-config />
<context:component-scan base-package="com"/>
<mvc:interceptors>
<bean class="com.web.controller.newController.sessionController" />
</mvc:interceptors>
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
package com.web.controller.newController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.web.vo.UserSessionDto;
public class sessionController extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
UserSessionDto session = (UserSessionDto) request.getSession()
.getAttribute("user");
System.out.println("pre Handle-->"+(null != session));
if (null != session) {
//request.getRequestDispatcher("/login.html").forward(request, response);
response.sendRedirect("/login.html");
return false;
}
return super.preHandle(request, response, handler);
}
}