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