home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / binaries / Windows / jsdk / servlets / SimpleServlet.java < prev    next >
Encoding:
Java Source  |  1997-07-18  |  1.7 KB  |  54 lines

  1. /*
  2.  * @(#)SimpleServlet.java    1.21 97/05/22
  3.  * 
  4.  * Copyright (c) 1996-1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.0
  20.  */
  21.  
  22. import java.io.*;
  23.  
  24. import javax.servlet.*;
  25. import javax.servlet.http.*;
  26.  
  27.  
  28. /**
  29.  * This is a simple example of an HTTP Servlet.  It responds to the GET
  30.  * and HEAD methods of the HTTP protocol.
  31.  */
  32. public class SimpleServlet extends HttpServlet { 
  33.  
  34.     public void doGet (HttpServletRequest req, HttpServletResponse res)
  35.     throws ServletException, IOException
  36.     {
  37.         ServletOutputStream out = res.getOutputStream();
  38.  
  39.     // set content type and other response header fields first
  40.         res.setContentType("text/html");
  41.  
  42.     // then write the data of the response
  43.         out.println("<HEAD><TITLE> SimpleServlet Output </TITLE></HEAD><BODY>");
  44.     out.println("<h1> SimpleServlet Output </h1>");
  45.     out.println("<P>This is output from SimpleServlet.");
  46.     out.println("</BODY>");
  47.     out.close();
  48.     }
  49.  
  50.     public String getServletInfo() {
  51.         return "A simple servlet";
  52.     }
  53. }
  54.