It's a nifty little app.
See, our web server is required to have a 60 minute timeout. Sometimes users will be taking a call, an affidavit, and they'll be talking and writing in the NOTES app for more than 60 minutes. They're typing, but they're not making any web server calls. So essentially the web server doesn't know they're still working.
Suddenly, much to their horror, a "the server timed out" popup box appears. When they click OK, they are logged out of the system and they lose all their notes.
It sucks, as you can imagine. They can't periodically save their note, because for legal reasons no note can be edited, and it can only be saved when it is complete. For the same legality, we really shouldn't save auto-drafts... although we may revisit that idea later on.
Why do we use Ajax? A "regular" action won't work, because we don't want the user to switch or refresh screens. We just want to tell the server that we're still using it.
Anyway my server ping is a Struts action. It supplies a short XML file into the response's OutputStream then returns null. (Interesting side note: just calling an action wasn't sufficient. I had to actually put something into the HttpServletResponse to get this to work consistently.
There is no need to return an ActionForward, because Ajax just want to update a piece of an existing web page, not go to a new one. (There is even a nice 2-part JUnit test around this action, although I confess I didn't write it first.)
If the XML data does NOT contain what we were looking for, then the server really did timeout. The user walked away, had another window on top, was at lunch, whatever -- they didn't click OK within the required 5 minutes. So we pop up an apologetic message, log them out, and send them back to the login screen.
Short and sweet! There are fancier solutions out there, but I think this minimal one will take care of things for now. (I can provide code samples to the curious reader, if this quick summary interested anyone.)
Sometimes I wonder if I shouldn't make myself a techie blog, to keep track of random little projects like this....