0
我試圖在cookie中保存最新的時間。所以在每次控制器調用之後,我都使用HandlerInterceptor的postHandle攔截了調用。我正在更新cookie中的值。但值不更新。任何人都知道爲什麼它不起作用。Spring mvc:更改HandlerInterceptor中postHandle中的響應對象
代碼:
@Override
public void postHandle(HttpServletRequest request,
HttpServletResponse response, Object handler, ModelAndView ex)
throws Exception {
boolean isSet = true;
if (request.getSession().getAttribute("userId") != null){
for (Cookie cookies: request.getCookies()) {
if ("RequestTime".equals(cookies.getName())) {
isSet = false;
cookies.setValue(Long.toString(System.currentTimeMillis()));
response.addCookie(cookies);
}
}
if(isSet){
Cookie cookie = new Cookie("RequestTime", Long.toString(System.currentTimeMillis()));
response.addCookie(cookie);
}
}
}
嗨,大家好, 中來認識,如果我們在設定的postHandle然後餅乾它不會正常工作,閱讀一些文章之後。所以我將我的代碼從posthandle移動到preHandle塊。 謝謝 桑迪 – Sandy 2012-07-11 04:47:22