1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package examples.token;
20
21 import javax.servlet.http.HttpServletRequest;
22 import javax.servlet.http.HttpServletResponse;
23
24 import org.apache.struts.action.Action;
25 import org.apache.struts.action.ActionErrors;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29 import org.apache.struts.action.ActionMessage;
30 import org.apache.struts.action.ActionMessages;
31
32 /***
33 * Retrieve and process data from the submitted form
34 *
35 * @version $Rev: 421486 $ $Date: 2006-07-12 20:37:08 -0700 (Wed, 12 Jul 2006) $
36 */
37 public class ProcessTokenAction extends Action {
38
39
40
41 /***
42 * Constructor for ProcessOptionsAction.
43 */
44 public ProcessTokenAction() {
45 super();
46 }
47
48
49
50 /***
51 * Process the request and return an <code>ActionForward</code> instance
52 * describing where and how control should be forwarded, or
53 * <code>null</code>if the response has already been completed.
54 *
55 * @param mapping The ActionMapping used to select this instance
56 * @param form The optional ActionForm bean for this request (if any)
57 * @param request The HTTP request we are processing
58 * @param response The HTTP response we are creating
59 *
60 * @exception Exception if the application logic throws an exception
61 *
62 * @return the ActionForward for the next view
63 */
64 public ActionForward execute(
65 ActionMapping mapping,
66 ActionForm form,
67 HttpServletRequest request,
68 HttpServletResponse response)
69 throws Exception {
70
71
72
73 if (isCancelled(request)) {
74 return mapping.findForward("home");
75 }
76
77 ActionErrors errors = new ActionErrors();
78
79
80
81 if (!isTokenValid(request)) {
82 errors.add(
83 ActionMessages.GLOBAL_MESSAGE,
84 new ActionMessage("errors.token"));
85 }
86 resetToken(request);
87
88
89 if (!errors.isEmpty()) {
90 saveErrors(request, errors);
91 saveToken(request);
92 return (mapping.getInputForward());
93 }
94
95
96 return mapping.findForward("success");
97 }
98
99 }