|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
A Servlet is a small program that runs inside a web server. It receives and responds to requests from web clients.
All servlets implement this interface. Servlet writers typically do this by subclassing either GenericServlet, which implements the Servlet interface, or by subclassing GenericServlet's descendent, HttpServlet.
The Servlet 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 by the network service in the following manner:
In addition to the life-cycle methods, the Servlet interface provides for a method for the servlet to use to get any startup information, and a method that allows the servlet to return basic information about itself, such as its author, version and copyright.
GenericServlet
,
HttpServlet
Method Summary | |
void |
destroy()
Called by the servlet engine when the servlet is removed from service. |
ServletConfig |
getServletConfig()
Returns a ServletConfig object, which contains any initialization parameters and startup configuration for this servlet. |
java.lang.String |
getServletInfo()
Allows the servlet to provide information about itself to the host servlet runner such as author, version, and copyright. |
void |
init(ServletConfig config)
Called by the web server when the Servlet is placed into service. |
void |
service(ServletRequest req,
ServletResponse res)
Called by the servlet engine to allow the servlet to respond to a request. |
Method Detail |
public void init(ServletConfig config) throws ServletException
If a ServletException is thrown during the execution of this method, a servlet engine may not place the servlet into service. If the method does not return within a server defined time-out period, the servlet engine may assume that the servlet is nonfunctional and may not place it into service.
config
- object containing the servlet's startup-
configuration and initialization parametersUnavailableException
,
getServletConfig()
public ServletConfig getServletConfig()
The servlet writer is responsible for storing the ServletConfig object passed to the init method so it may be accessed via this method. For your convience, the GenericServlet implementation of this interface already does this.
init(javax.servlet.ServletConfig)
public void service(ServletRequest req, ServletResponse res) throws ServletException, java.io.IOException
Note that servlets typically run inside of multi threaded servlet engines that can handle multiple requests simultaneously. It is the servlet writer's responsibility to synchronize access to any shared resources, such as network connections or the servlet's class and instance variables. Information on multi-threaded programming in Java can be found in the Java tutorial on multi-threaded programming.
req
- the client's request of the servletres
- the servlet's response to the clientpublic java.lang.String getServletInfo()
public void destroy()
This method gives the servlet an opprotunity to clean up whatever resources are being held (e.g., memory, file handles, thread) and makes sure that any persistent state is synchronized with the servlet's current in-memory state.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |