home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 September / PCWorld_2000-09_cd.bin / Komunik / sambar / _setup.1 / javaeng.jar / javax / servlet / Servlet.java < prev    next >
Text File  |  2000-04-03  |  5KB  |  146 lines

  1. /*
  2.  * Servlet.java -- Interface for all servlets
  3.  *
  4.  * Copyright (c) 1998, 1999 by Free Software Foundation, Inc.
  5.  * Written by Paul Siegmann (pauls@euronet.nl)
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU Library General Public License as published
  9.  * by the Free Software Foundation, version 2. (see COPYING.LIB)
  10.  *
  11.  * This program is distributed in the hope that it will be useful, but
  12.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software Foundation
  18.  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
  19.  */
  20.  
  21. package javax.servlet;
  22.  
  23. import java.io.IOException;
  24.  
  25. /**
  26.  * This is the interface for all servlets.
  27.  * <P>
  28.  * Servlets handle server request.
  29.  * <P>
  30.  * Servlets have 5 phases in their lifespan, as follows:
  31.  * <OL>
  32.  * <LI>Creation<BR>
  33.  * This is an ordinary constructor call by the server.
  34.  * <LI>init<BR>
  35.  * The server who created the servlet calls the <CODE>init</CODE> method
  36.  * somewhere between creation and the first request it ever gives
  37.  * the servlet to handle.
  38.  * <LI>service<BR>
  39.  * For every incoming request the server calls the <CODE>service</CODE> method.
  40.  * The server packages all the request data in a ServletRequest object, and
  41.  * creates a ServletResponse object for the servlet to write reply data to.<BR>
  42.  * Note that the service method is run in a seperate thread.<BR>
  43.  * This is also the great advantage of using servlets versus traditional cgi
  44.  * scripting: instead of forking of a proces for every request only a new
  45.  * thread is created.
  46.  * <LI>destroy<BR>
  47.  * This method is called by the server indicating that the server no longer
  48.  * requires this servlet's services. The serlvet is expected to release any
  49.  * resources it is holding using this method.<BR>
  50.  * (With resources things like database connections etc are meant).
  51.  * <LI>Destruction<BR>
  52.  * This happens whenever the garbage collector happens to feel like
  53.  * reclaiming the memory used by this servlet.
  54.  * </OL>
  55.  *
  56. #ifdef SERVLET_2_0
  57.  * @version Servlet API 2.0
  58. #endif
  59. #ifdef SERVLET_2_1
  60.  * @version Servlet API 2.1
  61. #endif
  62. #ifdef SERVLET_2_2
  63.  * @version Servlet API 2.2
  64. #endif
  65.  * @since Servlet API 1.0
  66.  * @author Paul Siegmann (pauls@euronet.nl)
  67.  */
  68. public interface Servlet
  69. {
  70.     /**
  71.      * Initializes the servlet.
  72.      * Called by the server exactly once during the lifetime of the servlet.
  73.      * This method can be used to setup resources (connections to a
  74.      * database for example) for this servlet. The servlet should store the
  75.      * <code>ServletConfig</code> so it can return it again when the
  76.      * <code>getConfig()</code> method is called. If the the servlet is
  77.      * temporarily or permanently unavailable it should throw an
  78.      * <code>UnavailableException</code>.
  79.      * @see javax.servlet.UnavailableException
  80.      *
  81.      * @since Servlet API 1.0
  82.      *
  83.      * @param config This servlet configuration class
  84.      * @exception ServletException If an unexpected error occurs
  85.      * @exception UnavailableException If servlet is temporarily or permanently
  86.      * unavailable
  87.      */
  88.     void init (ServletConfig config) throws ServletException;
  89.  
  90.  
  91.     /**
  92.      * Called by the server every time it wants the servlet to handle
  93.      * a request. The servlet engine doesn't have to wait until the service
  94.      * call is finished but can start another thread and call the service method
  95.      * again to handle multiple concurrent requests. If a servlet doesn't want
  96.      * this to happen it has to implement the <code>SingleThreadModel</code>
  97.      * interface.
  98.      * @see javax.servlet.SingleThreadModel
  99.      * 
  100.      * @since Servlet API 1.0
  101.      *
  102.      * @param request all the request information
  103.      * @param response class to write all the response data to
  104.      * @exception ServletException If an error occurs
  105.      * @exception IOException If an error occurs
  106.      */
  107.     void service (ServletRequest request, ServletResponse response)
  108.         throws IOException, ServletException;
  109.  
  110.  
  111.     /**
  112.      * Called by the server when it no longer needs the servlet.
  113.      * The servlet programmer should use this method to free all
  114.      * the resources the servlet is holding.
  115.      *
  116.      * @since Servlet API 1.0
  117.      */
  118.     void destroy ();
  119.  
  120.  
  121.     /**
  122.      * Gets the servlet config class. This should be the same
  123.      * <code>ServletConfig</code> that was handed to the <code>init()</code>
  124.      * method.
  125.      *
  126.      * @since Servlet API 1.0
  127.      * @return The config class
  128.      */
  129.     ServletConfig getServletConfig ();
  130.  
  131.     /** 
  132.      * Gets a string containing information about the servlet.
  133.      * This String is provided by the Servlet writer and may contain
  134.      * things like the Servlet's name, author, version... stuff like that.
  135.      *
  136.      * @since Servlet API 1.0
  137.      */
  138.     String getServletInfo ();
  139. }
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.