View Javadoc

1   /*
2    * $Id: SuccessAction.java 421486 2006-07-13 03:37:08Z wsmoak $
3    *
4    * Copyright 2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package examples;
20  
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpServletResponse;
23  
24  import org.apache.struts.action.Action;
25  import org.apache.struts.action.ActionForm;
26  import org.apache.struts.action.ActionForward;
27  import org.apache.struts.action.ActionMapping;
28  
29  /***
30   * <p>An Action that forwards control via a "success" ActionFoward.</p>
31   *
32   * <p>A recommended strategy is that view pages should link only to Actions and
33   * never directly to other views. In situations where the view does not require
34   * any preparation you can use a SuccessAction, specifying the view as an
35   * ActionForward named "success" in your action mapping.</p>
36   *
37   * <p>e.g. If you configure an ActionMapping in struts-config.xml like this:</p>
38   *
39   * <pre>
40   *    &lt;action path="/prepareView"
41   *            type="examples.SuccessAction"&gt;
42   *        &lt;forward name="success" path="/jsp/View.jsp"/&gt;
43   *    &lt/action&gt;
44   * </pre>
45   *
46   * <p>You could create a link to the view (via the Action) as follows:</p>
47   *
48   * <pre>
49   *     &lt;html:link action="/prepareView"&gt;Display 'view' page&lt;/html:link&gt;
50   * </pre>
51   *
52   * <p>If you later change your application such that the view page requires some
53   * initialization you can change a single ActionMapping definition in
54   * struts-config.xml rather than lots of link definitions in many JSPs.</p>
55   *
56   * @version $Rev: 421486 $ $Date: 2006-07-12 20:37:08 -0700 (Wed, 12 Jul 2006) $
57   */
58  public class SuccessAction extends Action {
59  
60      // ------------------------------------------------------------ Constructors
61  
62      /***
63       * Constructor for SuccessAction.
64       */
65      public SuccessAction() {
66          super();
67      }
68  
69      // ---------------------------------------------------------- Action Methods
70  
71      /***
72       * Returns the <code>ActionForward</code> named "success" if one is
73       * configured or <code>null</code>if it cannot be found.
74       *
75       * Searches first for a local forward, then a global forward.
76       *
77       * @param mapping The ActionMapping used to select this instance
78       * @param form The optional ActionForm bean for this request (if any)
79       * @param request The HTTP request we are processing
80       * @param response The HTTP response we are creating
81       *
82       * @exception Exception if mapping.findForward throws an Exception
83       *
84       * @return the "success" ActionForward, or null if it cannot be found
85       */
86      public ActionForward execute(
87          ActionMapping mapping,
88          ActionForm form,
89          HttpServletRequest request,
90          HttpServletResponse response)
91          throws Exception {
92  
93          return mapping.findForward("success");
94  
95      }
96  
97  }