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.ActionForm;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29 import org.apache.struts.action.ActionMessage;
30 import org.apache.struts.action.ActionMessages;
31 import org.apache.struts.extras.actions.DispatchAction;
32
33
34
35
36
37
38 public class DispatchExampleAction extends DispatchAction {
39 private static final long serialVersionUID = -2683477831602712612L;
40
41 private int fooCount;
42 private int barCount;
43
44
45
46
47
48
49
50
51
52
53
54 public ActionForward doFoo(ActionMapping mapping,
55 ActionForm form,
56 HttpServletRequest request,
57 HttpServletResponse response)
58 throws Exception {
59
60 fooCount++;
61
62 ActionMessages messages = new ActionMessages();
63 messages.add("foo", new ActionMessage("count.foo.message", fooCount+""));
64 saveMessages(request, messages);
65
66 return (mapping.findForward("success"));
67
68 }
69
70
71
72
73
74
75
76
77
78
79
80 public ActionForward doBar(ActionMapping mapping,
81 ActionForm form,
82 HttpServletRequest request,
83 HttpServletResponse response)
84 throws Exception {
85 barCount++;
86
87 ActionMessages messages = new ActionMessages();
88 messages.add("bar", new ActionMessage("count.bar.message", barCount+""));
89 saveMessages(request, messages);
90
91 return (mapping.findForward("success"));
92 }
93 }