?? servlet.html
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Mon Sep 29 15:11:53 PDT 2003 --><TITLE>: Interface Servlet</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT ID="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT ID="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT ID="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT ID="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-all.html"><FONT ID="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT ID="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../javax/servlet/RequestDispatcher.html"><B>PREV CLASS</B></A> <A HREF="../../javax/servlet/ServletConfig.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="Servlet.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">javax.servlet</FONT><BR>Interface Servlet</H2><DL><DT><B>All Known Implementing Classes:</B> <DD><A HREF="../../javax/servlet/GenericServlet.html">GenericServlet</A></DD></DL><HR><DL><DT>public interface <B>Servlet</B></DL><P>Defines methods that all servlets must implement. <p>A servlet is a small Java program that runs within a Web server. Servlets receive and respond to requests from Web clients, usually across HTTP, the HyperText Transfer Protocol. <p>To implement this interface, you can write a generic servlet that extends <code>javax.servlet.GenericServlet</code> or an HTTP servlet that extends <code>javax.servlet.http.HttpServlet</code>. <p>This interface defines methods to initialize a servlet, to service requests, and to remove a servlet from the server. These are known as life-cycle methods and are called in the following sequence: <ol> <li>The servlet is constructed, then initialized with the <code>init</code> method. <li>Any calls from clients to the <code>service</code> method are handled. <li>The servlet is taken out of service, then destroyed with the <code>destroy</code> method, then garbage collected and finalized. </ol> <p>In addition to the life-cycle methods, this interface provides the <code>getServletConfig</code> method, which the servlet can use to get any startup information, and the <code>getServletInfo</code> method, which allows the servlet to return basic information about itself, such as author, version, and copyright.<P><DL><DT><B>See Also: </B><DD><A HREF="../../javax/servlet/GenericServlet.html"><CODE>GenericServlet</CODE></A>, <A HREF="../../javax/servlet/http/HttpServlet.html"><CODE>HttpServlet</CODE></A></DL><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><!-- ======== CONSTRUCTOR SUMMARY ======== --><!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Method Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../javax/servlet/Servlet.html#destroy()">destroy</A></B>()</CODE><BR> Called by the servlet container to indicate to a servlet that the servlet is being taken out of service.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../javax/servlet/ServletConfig.html">ServletConfig</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../javax/servlet/Servlet.html#getServletConfig()">getServletConfig</A></B>()</CODE><BR> Returns a <A HREF="../../javax/servlet/ServletConfig.html"><CODE>ServletConfig</CODE></A> object, which contains initialization and startup parameters for this servlet.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> java.lang.String</CODE></FONT></TD><TD><CODE><B><A HREF="../../javax/servlet/Servlet.html#getServletInfo()">getServletInfo</A></B>()</CODE><BR> Returns information about the servlet, such as author, version, and copyright.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../javax/servlet/Servlet.html#init(javax.servlet.ServletConfig)">init</A></B>(<A HREF="../../javax/servlet/ServletConfig.html">ServletConfig</A> config)</CODE><BR> Called by the servlet container to indicate to a servlet that the servlet is being placed into service.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../javax/servlet/Servlet.html#service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)">service</A></B>(<A HREF="../../javax/servlet/ServletRequest.html">ServletRequest</A> req, <A HREF="../../javax/servlet/ServletResponse.html">ServletResponse</A> res)</CODE><BR> Called by the servlet container to allow the servlet to respond to a request.</TD></TR></TABLE> <P><!-- ============ FIELD DETAIL =========== --><!-- ========= CONSTRUCTOR DETAIL ======== --><!-- ============ METHOD DETAIL ========== --><A NAME="method_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Method Detail</B></FONT></TD></TR></TABLE><A NAME="init(javax.servlet.ServletConfig)"><!-- --></A><H3>init</H3><PRE>public void <B>init</B>(<A HREF="../../javax/servlet/ServletConfig.html">ServletConfig</A> config) throws <A HREF="../../javax/servlet/ServletException.html">ServletException</A></PRE><DL><DD>Called by the servlet container to indicate to a servlet that the servlet is being placed into service. <p>The servlet container calls the <code>init</code> method exactly once after instantiating the servlet. The <code>init</code> method must complete successfully before the servlet can receive any requests. <p>The servlet container cannot place the servlet into service if the <code>init</code> method <ol> <li>Throws a <code>ServletException</code> <li>Does not return within a time period defined by the Web server </ol><DD><DL><DT><B>Parameters:</B><DD><CODE>config</CODE> - a <code>ServletConfig</code> object containing the servlet's configuration and initialization parameters<DT><B>Throws:</B><DD><A HREF="../../javax/servlet/ServletException.html">ServletException</A> - if an exception has occurred that interferes with the servlet's normal operation<DT><B>See Also: </B><DD><A HREF="../../javax/servlet/UnavailableException.html"><CODE>UnavailableException</CODE></A>, <A HREF="../../javax/servlet/Servlet.html#getServletConfig()"><CODE>getServletConfig()</CODE></A></DL></DD></DL><HR><A NAME="getServletConfig()"><!-- --></A><H3>getServletConfig</H3><PRE>public <A HREF="../../javax/servlet/ServletConfig.html">ServletConfig</A> <B>getServletConfig</B>()</PRE><DL><DD>Returns a <A HREF="../../javax/servlet/ServletConfig.html"><CODE>ServletConfig</CODE></A> object, which contains initialization and startup parameters for this servlet. The <code>ServletConfig</code> object returned is the one passed to the <code>init</code> method. <p>Implementations of this interface are responsible for storing the <code>ServletConfig</code> object so that this method can return it. The <A HREF="../../javax/servlet/GenericServlet.html"><CODE>GenericServlet</CODE></A> class, which implements this interface, already does this.<DD><DL><DT><B>Returns:</B><DD>the <code>ServletConfig</code> object that initializes this servlet<DT><B>See Also: </B><DD><A HREF="../../javax/servlet/Servlet.html#init(javax.servlet.ServletConfig)"><CODE>init(javax.servlet.ServletConfig)</CODE></A></DL></DD></DL><HR><A NAME="service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)"><!-- --></A><H3>service</H3><PRE>public void <B>service</B>(<A HREF="../../javax/servlet/ServletRequest.html">ServletRequest</A> req, <A HREF="../../javax/servlet/ServletResponse.html">ServletResponse</A> res) throws <A HREF="../../javax/servlet/ServletException.html">ServletException</A>, java.io.IOException</PRE><DL><DD>Called by the servlet container to allow the servlet to respond to a request. <p>This method is only called after the servlet's <code>init()</code> method has completed successfully. <p> The status code of the response always should be set for a servlet that throws or sends an error. <p>Servlets typically run inside multithreaded servlet containers that can handle multiple requests concurrently. Developers must be aware to synchronize access to any shared resources such as files, network connections, and as well as the servlet's class and instance variables. More information on multithreaded programming in Java is available in <a href="http://java.sun.com/Series/Tutorial/java/threads/multithreaded.html"> the Java tutorial on multi-threaded programming</a>.<DD><DL><DT><B>Parameters:</B><DD><CODE>req</CODE> - the <code>ServletRequest</code> object that contains the client's request<DD><CODE>res</CODE> - the <code>ServletResponse</code> object that contains the servlet's response<DT><B>Throws:</B><DD><A HREF="../../javax/servlet/ServletException.html">ServletException</A> - if an exception occurs that interferes with the servlet's normal operation<DD>java.io.IOException - if an input or output exception occurs</DL></DD></DL><HR><A NAME="getServletInfo()"><!-- --></A><H3>getServletInfo</H3><PRE>public java.lang.String <B>getServletInfo</B>()</PRE><DL><DD>Returns information about the servlet, such as author, version, and copyright. <p>The string that this method returns should be plain text and not markup of any kind (such as HTML, XML, etc.).<DD><DL><DT><B>Returns:</B><DD>a <code>String</code> containing servlet information</DL></DD></DL><HR><A NAME="destroy()"><!-- --></A><H3>destroy</H3><PRE>public void <B>destroy</B>()</PRE><DL><DD>Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet's <code>service</code> method have exited or after a timeout period has passed. After the servlet container calls this method, it will not call the <code>service</code> method again on this servlet. <p>This method gives the servlet an opportunity to clean up any resources that are being held (for example, memory, file handles, threads) and make sure that any persistent state is synchronized with the servlet's current state in memory.</DL><!-- ========= END OF CLASS DATA ========= --><HR><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_bottom"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_bottom_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT ID="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT ID="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT ID="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT ID="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-all.html"><FONT ID="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT ID="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../javax/servlet/RequestDispatcher.html"><B>PREV CLASS</B></A> <A HREF="../../javax/servlet/ServletConfig.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="Servlet.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -