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
34
35
36
37
38
39 public class ActionDispatcherExample extends Action {
40 private static final long serialVersionUID = -5974809892927967588L;
41
42 private ActionDispatcher dispatcher
43 = new ActionDispatcher(this,
44 ActionDispatcher.DISPATCH_FLAVOR);
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 }
119
120 }