public @ResponseBody String handleRequest() {
if (null == currentUser) {
return new ResponseEntity<String>(HttpStatus.UNAUTHORIZED);
} else {
// do stuff…
return “blahblah…”;
}
}
In the ajax function, when detect unauthorized header then re-direct to log in page:
if (responseStatus == 401) {
window.location.href=”/login”;
}