1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts.webapp.validator;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26 import javax.servlet.http.HttpSession;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.struts.action.Action;
31 import org.apache.struts.action.ActionForm;
32 import org.apache.struts.action.ActionForward;
33 import org.apache.struts.action.ActionMapping;
34
35 /**
36 * Implementation of <strong>Action</strong> that validates a registration form.
37 *
38 */
39 public final class RegistrationAction extends Action {
40
41 /**
42 * Commons Logging instance.
43 */
44 private Log log = LogFactory.getFactory().getInstance(this.getClass().getName());
45
46 /**
47 * Process the specified HTTP request, and create the corresponding HTTP
48 * response (or forward to another web component that will create it).
49 * Return an <code>ActionForward</code> instance describing where and how
50 * control should be forwarded, or <code>null</code> if the response has
51 * already been completed.
52 *
53 * @param mapping The ActionMapping used to select this instance
54 * @param form The optional ActionForm bean for this request (if any)
55 * @param request The HTTP request we are processing
56 * @param response The HTTP response we are creating
57 *
58 * @return Action to forward to
59 * @exception Exception if an input/output error or servlet exception occurs
60 */
61 public ActionForward execute(
62 ActionMapping mapping,
63 ActionForm form,
64 HttpServletRequest request,
65 HttpServletResponse response)
66 throws Exception {
67
68
69 if (isCancelled(request)) {
70 if (log.isInfoEnabled()) {
71 log.info(
72 " "
73 + mapping.getAttribute()
74 + " - Registration transaction was cancelled");
75 }
76
77 removeFormBean(mapping, request);
78
79 return (mapping.findForward("success"));
80 }
81
82 return mapping.findForward("success");
83 }
84
85 /**
86 * Convenience method for removing the obsolete form bean.
87 *
88 * @param mapping The ActionMapping used to select this instance
89 * @param request The HTTP request we are processing
90 */
91 protected void removeFormBean(
92 ActionMapping mapping,
93 HttpServletRequest request) {
94
95
96 if (mapping.getAttribute() != null) {
97 if ("request".equals(mapping.getScope())) {
98 request.removeAttribute(mapping.getAttribute());
99 } else {
100 HttpSession session = request.getSession();
101 session.removeAttribute(mapping.getAttribute());
102 }
103 }
104 }
105 }