write the following method in the filter:
Copy Code code as follows:
public void Dofilter (ServletRequest request, servletresponse response,
Filterchain chain) throws IOException, Servletexception {
HttpServletRequest HttpRequest = (httpservletrequest) request;
HttpServletResponse HttpResponse = (httpservletresponse) response;
String URL = Httprequest.getrequesturl (). toString ();
if (httprequest.getsession () = null) {
if (Httprequest.getheader ("X-requested-with")!= null
&& Httprequest.getheader ("X-requested-with"). Equals (
"XMLHttpRequest")) {//Ajax request
Httpresponse.setheader ("Sessionstatus", "timeout");
} else {
Httpresponse.sendredirect ("/test/index.jsp");
Return
}
} else {
Chain.dofilter (request, response);
}
}
This way, if the session times out and is an AJAX request, there is a timeout in the response, Sessionstatus
again in a global way to deal with the session timeout to jump to the page.
jquery can use the $.ajaxsetup method, ext also has a similar method:
Copy Code code as follows:
Global AJAX access, processing Ajax sesion Timeout
$.ajaxsetup ({
ContentType: "Application/x-www-form-urlencoded;charset=utf-8",
Complete:function (XMLHttpRequest, Textstatus) {
var sessionstatus = Xmlhttprequest.getresponseheader ("Sessionstatus"); Get the response head through XMLHttpRequest, Sessionstatus,
if (Sessionstatus = = "Timeout") {
If the timeout is processed, specify the page to jump
Window.location.replace ("/test/index.jsp");
}
}
});