How can Struts check for a set of global conditions before processing an action?

Ted Husted

This often comes up in the context of authenticating users or with other control flow issues. 

The direct approach would be to subclass the ActionServlet controller servlet, and override a method like processActionPerform (which actually calls the selected Action) or processActionForward (which forwards control to the returned logical page name). You could then inspect the current state of the world, and inject flow-of-control changes like this still utilizing the superclass's basic functionality.

To make the types of things you inject somewhat configurable, you might also want to use your own custom ActionMapping subclass, with extra bean properties that describe (to your override method) what exceptional things to do and when to do them -- the selected ActionMapping instance is made available to most of the processing calls, so this information would be easily accessible.

If, as part of injecting control follow changes, you need to track where the user was in your application, you might have your ActionServlet subclass maintain a request-scope attribute with a well-known name, containing the value returned by request.getServletPath(). This would act something like the "referer" header in an HTTP request, and provide some history tracking.