In my application, I would know when the session has expired by doing Ajax calls every 30 seconds, but the problem is that when I can controller method, HttpSession refresh and lastaccessedtime changed. So have you any idea how to know the status of the session without changing it's behaviour. I'm using Jquery and SpringMVC 2.5
@RequestMapping(value = "/consultForm.htm", params = "verifySession", method = RequestMethod.GET)
public ModelAndView verifySessionStatus(WebRequest webRequest, Model model, HttpServletRequest request, HttpServletResponse response) {
boolean isValid = true;
HttpSession session = request.getSession(false);
if (session.getAttribute("user") == null) {
isValid = false;
}
ModelAndView modelAndView = new ModelAndView("jsonView");
model.addAttribute("sessionValid", isValid);
modelAndView.addObject(model);
return modelAndView;
}
$.ajax({
url : "search.htm?verifySession=1",
type : "GET",
async : false,
cache : false,
success : function(data) {
valid = data.sessionValid;
if (!valid) {
showPopinExpire = true;
$("#dialog-session-expired").dialog("open");
}
},
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
}
});
Even with request.isRequestedSessionIdValid()
, everytime I call controller method, the session was refreshed.
Thank you