Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: kelp/webapp/presentation/GreetingServlet.java


1   /*
2    * Enhydra Java Application Server Project
3    *
4    * The contents of this file are subject to the Enhydra Public License
5    * Version 1.1 (the "License"); you may not use this file except in
6    * compliance with the License. You may obtain a copy of the License on
7    * the Enhydra web site ( http://www.enhydra.org/ ).
8    *
9    * Software distributed under the License is distributed on an "AS IS"
10   * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11   * the License for the specific terms governing rights and limitations
12   * under the License.
13   *
14   * The Initial Developer of the Enhydra Application Server is Lutris
15   * Technologies, Inc. The Enhydra Application Server and portions created
16   * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17   * All Rights Reserved.
18   *
19   * Contributor(s):
20   *
21   */
22  package kelp.webapp.presentation;
23  
24  // Xerces imports
25  import org.w3c.dom.html.HTMLElement;
26  
27  // Servlet imports
28  import javax.servlet.ServletException;
29  import javax.servlet.ServletOutputStream;
30  import javax.servlet.http.HttpServlet;
31  import javax.servlet.http.HttpServletRequest;
32  import javax.servlet.http.HttpServletResponse;
33  
34  // Standard imports
35  import java.io.IOException;
36  
37  /**
38   * <p>
39   * This presentation object dynamically creates an HTML page
40   * showing the greeting from the application configuration file.
41   * </p>
42   */
43  public class GreetingServlet extends HttpServlet {
44      private final String GREETING = "Hello World!";
45  
46      public void doGet(HttpServletRequest request,
47                        HttpServletResponse response) throws ServletException,
48                        IOException {
49          GreetingHTML page = null;
50          ServletOutputStream out;
51          byte[] buffer;
52  
53          page = createPage();
54          buffer = page.toDocument().getBytes();
55          response.setContentType( "text/html" );
56          response.setContentLength( buffer.length );
57          out = response.getOutputStream();
58          out.write(buffer);
59          out.flush();
60          response.flushBuffer();
61      }
62  
63      public GreetingHTML createPage() {
64          GreetingHTML page = null;
65          HTMLElement  element = null;
66  
67          page = new GreetingHTML();
68          element = page.getElementSpanGreeting();
69          element.getFirstChild().setNodeValue(GREETING);
70          return page;
71      }
72  
73  }