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