The web system often uses interceptors or filters to implement permission interception, to determine whether the user login, if not logged, jump to the landing page, but when the browser is the AJAX request, the browser will not jump normally, but return to the landing page of the HTML source to the Ajax callback function (when the Jump landing page cross-domain, 302 errors will occur), the solution is as follows: Front end://If the session is timed out or not logged in, jump to the landing page
$ (document). Ajaxcomplete (function(event,request, settings) { var data= Request.responsejson; if (data.ret!=null&&data.ret==302) // Judging by the data returned by the server side { window.location=data.redirecturl; }});
Server:
@RequestMapping (value = "/nologin") public void Login (httpservletrequest request,httpservletresponse response, Model Model) throws Exception { if (Request.getheader ("X-requested-with")!=null&&request.getheader (" X-requested-with "). Equals (" XMLHttpRequest ")) { response.getwriter (). Write ({" ret ": 302," MSG ":" "," RedirectURL ":"} "); else { Response.sendredirect (applicationprops.getproperty ("Oauth.ucenter.url"));} }
The server depends on whether the request header X-requested-with has a value and whether it is XMLHttpRequest (which represents an AJAX request) to determine if it is an AJAX request, and if so, to return the JSON data, if not the normal jump; The front end is the global complete method added to the AJAX request, which is triggered when the AJAX request completes (regardless of the success of the request), where Var Data=request.responsejson; is the Jason data returned by the server, which completes the jump based on the JSON data.
The session expired processing scenario when the AJAX request was made