Built an action base class tokenaction, use the template method, as follows:
public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {ActionForward forward = null; if (isTokenValid (request, true)) {forward = doExecute (mapping, form, request, response);} else { saveToken (request); throw new TokenRepeatException (MessageLocator.getMessage ( "error.token"));} return forward;} public abstract ActionForward doExecute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception;
Note: TokenRepeTexception is a custom exception, its parent class ApplicationException is declared in Struts-Config.xml to capture the Action. As (my error message resource is used by Spring, there is no Struts):
There are several precautions: 1. Regarding the abnormal information Where is the display: Anomaly display certainly can't be on the form page, for example, after you have successfully updated a record, return the list of list, when the user returns repeatedly, Returning this list page and displays the prompt information is reasonable. It is best to define another Forward. I unified to the Forward name "tokenrepet", each need to control the Action that needs to be submitted must be defined. Finally, add exception display on the JSP page:
< / Logic: Present>
2. You must forward instead of directly enter the JSP page, because you have to call the SaveToken method to record the token word.