The Ajax commit session Timeout jump page uses a global method to process

Source: Internet
Author: User

From: http://www.jb51.net/article/43770.htm

If it is an Ajax commit, the jump command from the server will not work, so if it is a session timeout, and is in the AJAX request, in the response header, and then a global method to handle the session timeout to jump page.

Write the following method in the filter: (not tested)

 Publicvoid DoFilter (ServletRequest request, servletresponse response,Filterchain chain) throws IOException,servletexception {httpservletrequest HttpRequest=(httpservletrequest) request; HttpServletResponse HttpResponse=(httpservletresponse) response;Stringurl = Httprequest.getrequesturl ().toString ();if(httprequest.getsession () = =NULL) { if(Httprequest.getheader ("X-requested-with")! =NULL&& Httprequest.getheader ("X-requested-with").Equals ("XMLHttpRequest")) {//Ajax RequestsHttpresponse.setheader ("Sessionstatus", "timeout"); } Else{HttpResponse. Sendredirect ("/test/index.jsp"); return; } } Else{chain. DoFilter (Request,response); } } 

Thus, if the session times out and is an AJAX request, it will be in the response header, Sessionstatus has a timeout, and a global method to process the session timeout to jump to the page

jquery can be used $.ajaxsetup method, ext also has a similar method: (Test effective)

"Application/x-www-form-urlencoded;charset=utf-8 "   function   var //  If (sessionstatus = = "Timeout"//window.location.replace ("/test /index.jsp "

The Ajax commit session Timeout jump page uses a global method to process

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.