Project Tiles has retired. For details please refer to its Attic page.
IncludingServlet xref
View Javadoc

1   /*
2    * $Id: IncludingServlet.java 897303 2010-01-08 19:07:59Z apetrelli $
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.tiles.test.servlet;
22  
23  import java.io.IOException;
24  
25  import javax.servlet.ServletConfig;
26  import javax.servlet.ServletException;
27  import javax.servlet.http.HttpServlet;
28  import javax.servlet.http.HttpServletRequest;
29  import javax.servlet.http.HttpServletResponse;
30  
31  /**
32   * Sample servlet that includes a page specified by the <code>include</code>
33   * init parameter.
34   *
35   * @version $Rev: 897303 $ $Date: 2010-01-09 06:07:59 +1100 (Sat, 09 Jan 2010) $
36   */
37  public class IncludingServlet extends HttpServlet {
38  
39      /**
40       * Init parameter value, that indicates the path to include.
41       */
42      private String include;
43  
44      /**
45       * Initializes the servlet, reading the <code>include</code> init
46       * parameter.
47       *
48       * @param config The servlet configuration object to use.
49       * @throws ServletException Thrown by
50       * {@link HttpServlet#init(ServletConfig)}
51       */
52      @Override
53      public void init(ServletConfig config) throws ServletException {
54          super.init(config);
55  
56          include = config.getInitParameter("include");
57      }
58  
59      /**
60       * Processes the request, including the specified page.
61       *
62       * @param request The request object.
63       * @param response The response object.
64       * @throws ServletException Thrown by the {@link #include} method.
65       * @throws IOException Thrown by the {@link #include} method.
66       */
67      @Override
68      protected void doGet(HttpServletRequest request,
69              HttpServletResponse response) throws ServletException, IOException {
70          request.getRequestDispatcher(include).include(request, response);
71      }
72  }