1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 1999 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. *
  54. * ====================================================================
  55. *
  56. * This source code implements specifications defined by the Java
  57. * Community Process. In order to remain compliant with the specification
  58. * DO NOT add / change / or delete method signatures!
  59. */
  60. package javax.servlet;
  61. import java.io.IOException;
  62. /**
  63. * Defines methods that all servlets must implement.
  64. *
  65. * <p>A servlet is a small Java program that runs within a Web server.
  66. * Servlets receive and respond to requests from Web clients,
  67. * usually across HTTP, the HyperText Transfer Protocol.
  68. *
  69. * <p>To implement this interface, you can write a generic servlet
  70. * that extends
  71. * <code>javax.servlet.GenericServlet</code> or an HTTP servlet that
  72. * extends <code>javax.servlet.http.HttpServlet</code>.
  73. *
  74. * <p>This interface defines methods to initialize a servlet,
  75. * to service requests, and to remove a servlet from the server.
  76. * These are known as life-cycle methods and are called in the
  77. * following sequence:
  78. * <ol>
  79. * <li>The servlet is constructed, then initialized with the <code>init</code> method.
  80. * <li>Any calls from clients to the <code>service</code> method are handled.
  81. * <li>The servlet is taken out of service, then destroyed with the
  82. * <code>destroy</code> method, then garbage collected and finalized.
  83. * </ol>
  84. *
  85. * <p>In addition to the life-cycle methods, this interface
  86. * provides the <code>getServletConfig</code> method, which the servlet
  87. * can use to get any startup information, and the <code>getServletInfo</code>
  88. * method, which allows the servlet to return basic information about itself,
  89. * such as author, version, and copyright.
  90. *
  91. * @author Various
  92. * @version $Version$
  93. *
  94. * @see GenericServlet
  95. * @see javax.servlet.http.HttpServlet
  96. *
  97. */
  98. public interface Servlet {
  99. /**
  100. * Called by the servlet container to indicate to a servlet that the
  101. * servlet is being placed into service.
  102. *
  103. * <p>The servlet container calls the <code>init</code>
  104. * method exactly once after instantiating the servlet.
  105. * The <code>init</code> method must complete successfully
  106. * before the servlet can receive any requests.
  107. *
  108. * <p>The servlet container cannot place the servlet into service
  109. * if the <code>init</code> method
  110. * <ol>
  111. * <li>Throws a <code>ServletException</code>
  112. * <li>Does not return within a time period defined by the Web server
  113. * </ol>
  114. *
  115. *
  116. * @param config a <code>ServletConfig</code> object
  117. * containing the servlet's
  118. * configuration and initialization parameters
  119. *
  120. * @exception ServletException if an exception has occurred that
  121. * interferes with the servlet's normal
  122. * operation
  123. *
  124. * @see UnavailableException
  125. * @see #getServletConfig
  126. *
  127. */
  128. public void init(ServletConfig config) throws ServletException;
  129. /**
  130. *
  131. * Returns a {@link ServletConfig} object, which contains
  132. * initialization and startup parameters for this servlet.
  133. * The <code>ServletConfig</code> object returned is the one
  134. * passed to the <code>init</code> method.
  135. *
  136. * <p>Implementations of this interface are responsible for storing the
  137. * <code>ServletConfig</code> object so that this
  138. * method can return it. The {@link GenericServlet}
  139. * class, which implements this interface, already does this.
  140. *
  141. * @return the <code>ServletConfig</code> object
  142. * that initializes this servlet
  143. *
  144. * @see #init
  145. *
  146. */
  147. public ServletConfig getServletConfig();
  148. /**
  149. * Called by the servlet container to allow the servlet to respond to
  150. * a request.
  151. *
  152. * <p>This method is only called after the servlet's <code>init()</code>
  153. * method has completed successfully.
  154. *
  155. * <p> The status code of the response always should be set for a servlet
  156. * that throws or sends an error.
  157. *
  158. *
  159. * <p>Servlets typically run inside multithreaded servlet containers
  160. * that can handle multiple requests concurrently. Developers must
  161. * be aware to synchronize access to any shared resources such as files,
  162. * network connections, and as well as the servlet's class and instance
  163. * variables.
  164. * More information on multithreaded programming in Java is available in
  165. * <a href="http://java.sun.com/Series/Tutorial/java/threads/multithreaded.html">
  166. * the Java tutorial on multi-threaded programming</a>.
  167. *
  168. *
  169. * @param req the <code>ServletRequest</code> object that contains
  170. * the client's request
  171. *
  172. * @param res the <code>ServletResponse</code> object that contains
  173. * the servlet's response
  174. *
  175. * @exception ServletException if an exception occurs that interferes
  176. * with the servlet's normal operation
  177. *
  178. * @exception IOException if an input or output exception occurs
  179. *
  180. */
  181. public void service(ServletRequest req, ServletResponse res)
  182. throws ServletException, IOException;
  183. /**
  184. * Returns information about the servlet, such
  185. * as author, version, and copyright.
  186. *
  187. * <p>The string that this method returns should
  188. * be plain text and not markup of any kind (such as HTML, XML,
  189. * etc.).
  190. *
  191. * @return a <code>String</code> containing servlet information
  192. *
  193. */
  194. public String getServletInfo();
  195. /**
  196. *
  197. * Called by the servlet container to indicate to a servlet that the
  198. * servlet is being taken out of service. This method is
  199. * only called once all threads within the servlet's
  200. * <code>service</code> method have exited or after a timeout
  201. * period has passed. After the servlet container calls this
  202. * method, it will not call the <code>service</code> method again
  203. * on this servlet.
  204. *
  205. * <p>This method gives the servlet an opportunity
  206. * to clean up any resources that are being held (for example, memory,
  207. * file handles, threads) and make sure that any persistent state is
  208. * synchronized with the servlet's current state in memory.
  209. *
  210. */
  211. public void destroy();
  212. }