View comments | RSS feed

Servlet API

Servlet classes must implement the javax.servlet.Servlet interface. The Servlet API provides two classes that implement this interface, which you can extend to create Java servlets:

Basic servlet classes and interfaces

The Servlet API uses classes and interfaces from the java.io, java.lang, javax.servlet, and javax.http.servlet packages, as the following figure shows:

This image shows a class diagram for the javax.servlet and javax.http.servlet classes.

For complete information on the classes, interfaces, and exceptions in the Servlet API, see the Servlet API JavaDocs.

Servlet lifecycle

Servlets undergo a multiphase lifecycle, as the following figure shows:

This image shows the lifecycle of a servlet.

During the initialization phase, JRun invokes the servlet's init method. The init method gets called only once, thus avoiding the need to allocate expensive resources every time the JRun invokes the servlet. Use the init method to allocate resources the servlet requires throughout its lifecycle. JRun invokes the init method at startup (if enabled in the JMC) or when the first client request is received.

You are not required to override the init method in your servlet class. You override it only when you want to perform some type of processing at initialization time.

The servicing requests phase occurs when the servlet handles all incoming requests. JRun routes requests to either the service method if you override Generic Servlet) or a doXxx method (if you override the HttpServlet class).

JRun unloads the servlet from memory when you shut down the JRun server or when the JRun server reloads a modified servlet. At the time of the unload, the servlet goes through the destroy phase. When the destroy request is initiated, JRun calls the destroy method. Inside the destroy method, you can deallocate resources that the servlet was using. As soon as JRun invokes the destroy method, the class can be garbage-collected.

Comments


No screen name said on Nov 29, 2004 at 7:56 PM :
It is not javax.http.servlet package that contain HttpServlet class.It is javax.servlet.http.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/jrun/4/Programmers_Guide/techniques_servlet2.htm