使用spring3里的过滤器

修改mvc-config.xml
[ccn lang="xml" tab_size="4" theme="blackboard" width="550" ]








[/ccn]
[ccn lang="java" tab_size="4" theme="blackboard" width="550" ]
/**
* 过滤器 自动用cookie登录
* @author ohergal
* create date: 2010-12-28
*/
public class AutoCookieLoginInterceptor implements HandlerInterceptor {
@Autowired
private IDiscuzUserDao discuzUserDao;

@Autowired
private ConstantBean constant;

@Override
public void afterCompletion(HttpServletRequest arg0,
HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
// TODO Auto-generated method stub

}

@Override
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
Object arg2, ModelAndView arg3) throws Exception {

}

@SuppressWarnings("deprecation")
@Override
public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1,
Object arg2) throws Exception {
// 如果session里面没有用户
HttpSession session = arg0.getSession();
if ( session.getAttribute("loginuser") == null ) {
// 看cookie里有没有 如果有,就给他自动登录了
Cookie cookies[] = arg0.getCookies();
Cookie userCookie = null;
for (int i = 0; i < cookies.length; i++) { ...... break; } } // 如果cookie里也没有 就算了 } return true; } } [/ccn]