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.
So I'd like to handle this situation. I would like to just write a global handler for all ajax responses that will do window.location.reload() if we need to authenticate.
I'd faced the same problem. Please see the solution I adopted and check whether it is useful for you.
My log-page used a old model controller instead of spring 3.0 annotation model.
I registered a global ajax error handler as follows
Then in my log-in controller, I checks whether the original request was a ajax request or not using the
x-requested-with
header. If it was a ajax request then I returns a json response saying{"timeout" : true}
.Sample implementation of JSONView
This uses the json-lib library to convert the objects to json format.
Spring 3.0 has very good support for jackson library, you can try to use it.