The AJAX submission Session Timeout jump page uses a global approach to handle _AJAX related

Source: Internet
Author: User
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");
}
}
});
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.