01: /*
02: * $Id: DispatchExampleAction.java 471754 2006-11-06 14:55:09Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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 javax.servlet.http.HttpServletRequest;
24: import javax.servlet.http.HttpServletResponse;
25: import org.apache.struts.actions.DispatchAction;
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:
32: /**
33: * Example DispatchAction.
34: *
35: * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
36: */
37: public class DispatchExampleAction extends DispatchAction {
38:
39: private int fooCount;
40: private int barCount;
41:
42: /**
43: * Example "foo" method.
44: *
45: * @param mapping The ActionMapping used to select this instance
46: * @param form The optional ActionForm bean for this request
47: * @param request The servlet request we are processing
48: * @param response The servlet response we are creating
49: *
50: * @exception Exception if business logic throws an exception
51: */
52: public ActionForward doFoo(ActionMapping mapping, ActionForm form,
53: HttpServletRequest request, HttpServletResponse response)
54: throws Exception {
55:
56: fooCount++;
57:
58: ActionMessages messages = new ActionMessages();
59: messages.add("foo", new ActionMessage("count.foo.message",
60: fooCount + ""));
61: saveMessages(request, messages);
62:
63: return (mapping.findForward("success"));
64:
65: }
66:
67: /**
68: * Example "bar" method.
69: *
70: * @param mapping The ActionMapping used to select this instance
71: * @param form The optional ActionForm bean for this request
72: * @param request The servlet request we are processing
73: * @param response The servlet response we are creating
74: *
75: * @exception Exception if business logic throws an exception
76: */
77: public ActionForward doBar(ActionMapping mapping, ActionForm form,
78: HttpServletRequest request, HttpServletResponse response)
79: throws Exception {
80: barCount++;
81:
82: ActionMessages messages = new ActionMessages();
83: messages.add("bar", new ActionMessage("count.bar.message",
84: barCount + ""));
85: saveMessages(request, messages);
86:
87: return (mapping.findForward("success"));
88:
89: }
90:
91: }
|