How To Save Struts Messages After a Redirect
If you’ve got an Action in Struts 1 that leaves an error or message for the view, it does it somewhere in the class like this:
ActionMessages messages = getMessages(request);
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.detail", "Normality has been restored."));
saveMessages(request, messages);
However if your Action later selects an ActionForward that redirects (possibly unbeknownst to the Action, since that is configured elsewhere), the Controller will redirect the browser to that new location and Struts will see that redirected call as an entirely new request, having lost anything in the request attributes (such as the message you just saved).
There are some other ways to do it, but here’s a really simple way to do it:
saveMessages(request.getSession(), messages);
Once they’re displayed in the view once they will automatically be removed from the session. In this fashion, it behaves like a Flash scoped variable in JSF, except you can be sure it’s displayed even if the next request fails, which is probably a good thing.