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.extras.actions;
22  
23  import jakarta.servlet.ServletException;
24  import jakarta.servlet.http.HttpServletRequest;
25  import jakarta.servlet.http.HttpServletResponse;
26  
27  import org.apache.struts.action.ActionForm;
28  import org.apache.struts.action.ActionForward;
29  import org.apache.struts.action.ActionMapping;
30  
31  /**
32   * <p>An <strong>Action</strong> that forwards to the context-relative URI
33   * specified by the <code>parameter</code> property of our associated
34   * <code>ActionMapping</code>.  This can be used to integrate Struts with
35   * other business logic components that are implemented as servlets (or JSP
36   * pages), but still take advantage of the Struts controller servlet's
37   * functionality (such as processing of form beans).</p>
38   *
39   * <p>To configure the use of this Action in your <code>struts-config.xml</code>
40   * file, create an entry like this:</p>
41   *
42   * {ſ@code &lt;action path="/saveSubscription"
43   * type="org.apache.struts.extras.actions.ForwardAction"
44   * name="subscriptionForm" scope="request" input="/subscription.jsp"
45   * parameter="/path/to/processing/servlet"/&gt;}
46   *
47   * <p>which will forward control to the context-relative URI specified by the
48   * <code>parameter</code> attribute.</p>
49   *
50   * @version $Rev$ $Date: 2005-08-14 17:24:39 -0400 (Sun, 14 Aug 2005)
51   *          $
52   */
53  public class ForwardAction extends BaseAction {
54      private static final long serialVersionUID = -3526864110155621740L;
55  
56      // ----------------------------------------------------- Instance Variables
57  
58      /**
59       * Process the specified HTTP request, and create the corresponding HTTP
60       * response (or forward to another web component that will create it).
61       * Return an <code>ActionForward</code> instance describing where and how
62       * control should be forwarded, or <code>null</code> if the response has
63       * already been completed.
64       *
65       * @param mapping  The ActionMapping used to select this instance
66       * @param form     The optional ActionForm bean for this request (if any)
67       * @param request  The HTTP request we are processing
68       * @param response The HTTP response we are creating
69       * @return The forward to which control should be transferred, or
70       *         <code>null</code> if the response has been completed.
71       * @throws Exception if an error occurs
72       */
73      public ActionForward execute(ActionMapping mapping, ActionForm form,
74          HttpServletRequest request, HttpServletResponse response)
75          throws Exception {
76          // Create a RequestDispatcher the corresponding resource
77          String path = mapping.getParameter();
78  
79          if (path == null) {
80              throw new ServletException(messages.getMessage("forward.path"));
81          }
82  
83          // Let the controller handle the request
84          ActionForward retVal = new ActionForward(path);
85  
86          return retVal;
87      }
88  }