View Javadoc
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.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.MappingDispatchAction;
32  
33  /**
34   * Example DispatchAction.
35   *
36   * @version $Rev$ $Date$
37   */
38  public class MappingDispatchExampleAction extends MappingDispatchAction {
39      private static final long serialVersionUID = -7462768133841595979L;
40  
41      private int fooCount;
42      private int barCount;
43  
44      /**
45       * Example "foo" method.
46       *
47       * @param mapping The ActionMapping used to select this instance
48       * @param form The optional ActionForm bean for this request
49       * @param request The servlet request we are processing
50       * @param response The servlet response we are creating
51       *
52       * @exception Exception if business logic throws an exception
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       * Example "bar" method.
72       *
73       * @param mapping The ActionMapping used to select this instance
74       * @param form The optional ActionForm bean for this request
75       * @param request The servlet request we are processing
76       * @param response The servlet response we are creating
77       *
78       * @exception Exception if business logic throws an exception
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  }