1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts.webapp.dispatch;
22
23 import jakarta.servlet.http.HttpServletRequest;
24 import jakarta.servlet.http.HttpServletResponse;
25
26 import org.apache.struts.action.Action;
27 import org.apache.struts.action.ActionForm;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMapping;
30 import org.apache.struts.action.ActionMessage;
31 import org.apache.struts.action.ActionMessages;
32 import org.apache.struts.extras.actions.ActionDispatcher;
33 import org.apache.struts.extras.actions.EventActionDispatcher;
34
35
36
37
38
39
40 public class EventActionDispatcherExample extends Action {
41 private static final long serialVersionUID = 2358187973741752216L;
42
43 private ActionDispatcher dispatcher
44 = new EventActionDispatcher(this);
45
46 private int fooCount;
47 private int barCount;
48
49
50
51
52
53
54
55
56
57
58
59 public ActionForward execute(ActionMapping mapping,
60 ActionForm form,
61 HttpServletRequest request,
62 HttpServletResponse response)
63 throws Exception {
64
65 return dispatcher.execute(mapping, form, request, response);
66
67 }
68
69
70
71
72
73
74
75
76
77
78
79 public ActionForward doFoo(ActionMapping mapping,
80 ActionForm form,
81 HttpServletRequest request,
82 HttpServletResponse response)
83 throws Exception {
84
85 fooCount++;
86
87 ActionMessages messages = new ActionMessages();
88 messages.add("foo", new ActionMessage("count.foo.message", fooCount+""));
89 saveMessages(request, messages);
90
91 return (mapping.findForward("success"));
92
93 }
94
95
96
97
98
99
100
101
102
103
104
105 public ActionForward doBar(ActionMapping mapping,
106 ActionForm form,
107 HttpServletRequest request,
108 HttpServletResponse response)
109 throws Exception {
110 barCount++;
111
112 ActionMessages messages = new ActionMessages();
113 messages.add("bar", new ActionMessage("count.bar.message", barCount+""));
114 saveMessages(request, messages);
115
116 return (mapping.findForward("success"));
117 }
118 }