View Javadoc

1   /*
2    * $Id: PrepareLinksAction.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.links;
20  
21  import java.util.HashMap;
22  
23  import javax.servlet.http.HttpServletRequest;
24  import javax.servlet.http.HttpServletResponse;
25  
26  import org.apache.struts.action.Action;
27  import org.apache.struts.action.ActionForm;
28  import org.apache.struts.action.ActionForward;
29  import org.apache.struts.action.ActionMapping;
30  
31  import examples.TestBean;
32  
33  /***
34   * Perform any tasks and setup any data that
35   * must be prepared before the form is displayed.
36   *
37   * @version $Rev: 421486 $ $Date: 2006-07-12 20:37:08 -0700 (Wed, 12 Jul 2006) $
38   */
39  public class PrepareLinksAction extends Action {
40  
41      // ------------------------------------------------------------ Constructors
42  
43      /***
44       * Constructor for PrepareOptionsAction.
45       */
46      public PrepareLinksAction() {
47          super();
48      }
49  
50      // ---------------------------------------------------------- Action Methods
51  
52      /***
53       * Process the request and return an <code>ActionForward</code> instance
54       * describing where and how control should be forwarded, or
55       * <code>null</code>if the response has already been completed.
56       *
57       * @param mapping The ActionMapping used to select this instance
58       * @param form The optional ActionForm bean for this request (if any)
59       * @param request The HTTP request we are processing
60       * @param response The HTTP response we are creating
61       *
62       * @exception Exception if an exception occurs
63       *
64       * @return the ActionForward to forward control to
65       */
66      public ActionForward execute(
67          ActionMapping mapping,
68          ActionForm form,
69          HttpServletRequest request,
70          HttpServletResponse response)
71          throws Exception {
72  
73          HashMap parms = new HashMap();
74          parms.put("color", "Red");
75          parms.put("fruit", "Apple");
76          parms.put("animal", "Rabbit");
77          request.setAttribute("parms", parms);
78  
79          TestBean bean = new TestBean();
80          request.setAttribute("testBean", bean);
81  
82          // Just forward to the form - no preparation required
83          return mapping.findForward("success");
84  
85      }
86  
87  }