View Javadoc

1   // ========================================================================
2   // Copyright (c) 1996-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package com.acme;
15  import java.io.IOException;
16  
17  import javax.servlet.ServletConfig;
18  import javax.servlet.ServletException;
19  import javax.servlet.ServletOutputStream;
20  import javax.servlet.SingleThreadModel;
21  import javax.servlet.http.HttpServlet;
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  
25  
26  /* ------------------------------------------------------------ */
27  /** Dump Servlet Request.
28   * 
29   */
30  public class HelloWorld extends HttpServlet implements SingleThreadModel
31  {
32      /* ------------------------------------------------------------ */
33      public void init(ServletConfig config) throws ServletException
34      {
35      	super.init(config);
36      }
37  
38      /* ------------------------------------------------------------ */
39      public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
40      {
41          doGet(request, response);
42      }
43  
44      /* ------------------------------------------------------------ */
45      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
46      {
47          response.setContentType("text/html");
48          ServletOutputStream out = response.getOutputStream();
49          out.println("<html>");
50          out.println("<h1>Hello World</h1>");
51          out.println("</html>");
52          out.flush();
53          
54          try
55          {
56              Thread.sleep(200);
57          }
58          catch (InterruptedException e)
59          {
60              getServletContext().log("exception",e);
61          }
62      }
63  
64      
65   
66      
67  }