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