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
22 package examples;
23
24 import jakarta.servlet.http.HttpServletRequest;
25 import jakarta.servlet.http.HttpServletResponse;
26
27 import org.apache.struts.action.Action;
28 import org.apache.struts.action.ActionForm;
29 import org.apache.struts.action.ActionForward;
30 import org.apache.struts.action.ActionMapping;
31
32 /**
33 * <p>An Action that forwards control via a "success" ActionFoward.</p>
34 *
35 * <p>A recommended strategy is that view pages should link only to Actions and
36 * never directly to other views. In situations where the view does not require
37 * any preparation you can use a SuccessAction, specifying the view as an
38 * ActionForward named "success" in your action mapping.</p>
39 *
40 * <p>e.g. If you configure an ActionMapping in struts-config.xml like this:</p>
41 *
42 * <pre>
43 * <action path="/prepareView"
44 * type="examples.SuccessAction">
45 * <forward name="success" path="/jsp/View.jsp"/>
46 * </action>
47 * </pre>
48 *
49 * <p>You could create a link to the view (via the Action) as follows:</p>
50 *
51 * <pre>
52 * <html:link action="/prepareView">Display 'view' page</html:link>
53 * </pre>
54 *
55 * <p>If you later change your application such that the view page requires some
56 * initialization you can change a single ActionMapping definition in
57 * struts-config.xml rather than lots of link definitions in many JSPs.</p>
58 *
59 * @version $Rev$ $Date$
60 */
61 public class SuccessAction extends Action {
62 private static final long serialVersionUID = 8464922680951404772L;
63
64 // ------------------------------------------------------------ Constructors
65
66 /**
67 * Constructor for SuccessAction.
68 */
69 public SuccessAction() {
70 super();
71 }
72
73 // ---------------------------------------------------------- Action Methods
74
75 /**
76 * Returns the <code>ActionForward</code> named "success" if one is
77 * configured or <code>null</code>if it cannot be found.
78 *
79 * Searches first for a local forward, then a global forward.
80 *
81 * @param mapping The ActionMapping used to select this instance
82 * @param form The optional ActionForm bean for this request (if any)
83 * @param request The HTTP request we are processing
84 * @param response The HTTP response we are creating
85 *
86 * @exception Exception if mapping.findForward throws an Exception
87 *
88 * @return the "success" ActionForward, or null if it cannot be found
89 */
90 public ActionForward execute(
91 ActionMapping mapping,
92 ActionForm form,
93 HttpServletRequest request,
94 HttpServletResponse response)
95 throws Exception {
96
97 return mapping.findForward("success");
98 }
99 }