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 jakarta.servlet.http.HttpServletRequest;
25 import jakarta.servlet.http.HttpServletResponse;
26 import jakarta.servlet.http.HttpSession;
27
28 import org.apache.struts.action.Action;
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.ActionMessages;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36
37
38
39
40
41 public final class MultiRegistrationAction extends Action {
42 private static final long serialVersionUID = -4985230580396174675L;
43
44
45
46
47 private final static Logger LOG =
48 LoggerFactory.getLogger(MultiRegistrationAction.class);
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 public ActionForward execute(
65 ActionMapping mapping,
66 ActionForm form,
67 HttpServletRequest request,
68 HttpServletResponse response)
69 throws Exception {
70
71
72 RegistrationForm info = (RegistrationForm) form;
73
74
75
76 if (isCancelled(request)) {
77 LOG.info(" {} - Registration transaction was cancelled",
78 mapping.getAttribute());
79
80 removeFormBean(mapping, request);
81
82 return mapping.findForward("success");
83 }
84
85 ActionMessages errors = info.validate(mapping, request);
86
87 if (errors != null && errors.isEmpty()) {
88 if (info.getPage() == 1)
89 return mapping.findForward("input2");
90
91 if (info.getPage() == 2)
92 return mapping.findForward("success");
93
94 } else {
95 this.saveErrors(request, errors);
96
97 if (info.getPage() == 1){
98 return mapping.findForward("input" + info.getPage());
99 }
100
101 if (info.getPage() == 2){
102 return mapping.findForward("input" + info.getPage());
103 }
104 }
105
106 return mapping.findForward("input1");
107 }
108
109
110
111
112
113
114
115 protected void removeFormBean(
116 ActionMapping mapping,
117 HttpServletRequest request) {
118
119
120 if (mapping.getAttribute() != null) {
121 if ("request".equals(mapping.getScope())) {
122 request.removeAttribute(mapping.getAttribute());
123 } else {
124 HttpSession session = request.getSession();
125 session.removeAttribute(mapping.getAttribute());
126 }
127 }
128 }
129 }