Save This Page
Home » struts-1.3.9-src » org.apache.struts » actions » [javadoc | source]
    1   /*
    2    * $Id: ForwardAction.java 54929 2004-10-16 16:38:42Z germuska $ 
    3    *
    4    * Copyright 2001-2004 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 org.apache.struts.actions;
   20   
   21   import javax.servlet.ServletException;
   22   import javax.servlet.http.HttpServletRequest;
   23   import javax.servlet.http.HttpServletResponse;
   24   
   25   import org.apache.struts.action.Action;
   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.util.MessageResources;
   30   
   31   /**
   32    * <p>An <strong>Action</strong> that forwards to the context-relative
   33    * URI 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
   40    * <code>struts-config.xml</code> file, create an entry like this:</p>
   41    *
   42    * <code>
   43    *   &lt;action path="/saveSubscription"
   44    *           type="org.apache.struts.actions.ForwardAction"
   45    *           name="subscriptionForm"
   46    *          scope="request"
   47    *          input="/subscription.jsp"
   48    *      parameter="/path/to/processing/servlet"/&gt;
   49    * </code>
   50    *
   51    * <p>which will forward control to the context-relative URI specified by the
   52    * <code>parameter</code> attribute.</p>
   53    *
   54    * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
   55    */
   56   public class ForwardAction extends Action {
   57   
   58   
   59       // ----------------------------------------------------- Instance Variables
   60   
   61   
   62       /**
   63        * The message resources for this package.
   64        */
   65       protected static MessageResources messages =
   66        MessageResources.getMessageResources
   67           ("org.apache.struts.actions.LocalStrings");
   68   
   69   
   70       // --------------------------------------------------------- Public Methods
   71   
   72   
   73       /**
   74        * Process the specified HTTP request, and create the corresponding HTTP
   75        * response (or forward to another web component that will create it).
   76        * Return an <code>ActionForward</code> instance describing where and how
   77        * control should be forwarded, or <code>null</code> if the response has
   78        * already been completed.
   79        *
   80        * @param mapping The ActionMapping used to select this instance
   81        * @param form The optional ActionForm bean for this request (if any)
   82        * @param request The HTTP request we are processing
   83        * @param response The HTTP response we are creating
   84        *
   85        * @exception Exception if an error occurs
   86        */
   87       public ActionForward execute(
   88           ActionMapping mapping,
   89           ActionForm form,
   90           HttpServletRequest request,
   91           HttpServletResponse response)
   92           throws Exception {
   93   
   94           // Create a RequestDispatcher the corresponding resource
   95           String path = mapping.getParameter();
   96   
   97           if (path == null) {
   98               throw new ServletException(messages.getMessage("forward.path"));
   99           }
  100   
  101           // Let the controller handle the request
  102           ActionForward retVal = new ActionForward(path);
  103           retVal.setContextRelative(true);
  104   
  105           return retVal;
  106       }
  107   
  108   
  109   }
  110   

Save This Page
Home » struts-1.3.9-src » org.apache.struts » actions » [javadoc | source]