title: How to handle expired session using Spring Security and jQuery?
body: <p>I'm using Spring Security and jQuery in my application. Main page uses loading content dynamically into tabs via AJAX. And all is OK, however sometimes I've got the login page inside my tab and if I type credentials I will be redirected to the content page without tabs.</p>
  
  <p>So I'd like to handle this situation. I know some of the people use AJAX authentication, but I'm not sure it's suitable for me because it looks quite complicated for me and my application doesn't allow any access without log into before. I would like to just write a global handler for all AJAX responses that will do <code>window.location.reload()</code> if we need to authenticate. I think in this case it's better to get <code>401</code> error instead of standard login form because it's easier to handle.</p>
  
  <p>So,</p>
  
  <p>1) Is it possible to write <em>global error handler</em> for all jQuery AJAX requests?</p>
  
  <p>2) How can I customize behavior of Spring Security to send 401 error for AJAX requests but for regular requests to show standard login page as usual?</p>
  
  <p>3) May be you have more graceful solution? Please share it.</p>
  
  <p>Thanks.</p>