1 /*
2 * $Id$
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
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 * Example DispatchAction.
36 *
37 * @version $Rev$ $Date$
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 * Execute method.
51 *
52 * @param mapping The ActionMapping used to select this instance
53 * @param form The optional ActionForm bean for this request
54 * @param request The servlet request we are processing
55 * @param response The servlet response we are creating
56 *
57 * @exception Exception if business logic throws an exception
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 * Example "foo" method.
71 *
72 * @param mapping The ActionMapping used to select this instance
73 * @param form The optional ActionForm bean for this request
74 * @param request The servlet request we are processing
75 * @param response The servlet response we are creating
76 *
77 * @exception Exception if business logic throws an exception
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 * Example "bar" method.
97 *
98 * @param mapping The ActionMapping used to select this instance
99 * @param form The optional ActionForm bean for this request
100 * @param request The servlet request we are processing
101 * @param response The servlet response we are creating
102 *
103 * @exception Exception if business logic throws an exception
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 }