jump to navigation

Servlet Interface August 23, 2005

Posted by Coolguy in Servlets/Jsp.
  • The Servlet interface is the central abstraction of the Java Servlet API. All servlets implement this interface either directly, or more commonly, by extending a class that implements the interface.
  • The two classes in the Java Servlet API that implement the Servlet interface are GenericServlet and HttpServlet. For most purposes, Developers will extend HttpServlet to implement their servlets.
  • The basic Servlet interface defines a service method for handling client requests. This method is called for each request that the servlet container routes to an instance of a servlet.
  • Generally the Web container handles concurrent requests to the same servlet by concurrent execution of the service method on different threads.
  • The HttpServlet abstract subclass adds additional methods beyond the basic Servlet interface that are automatically called by the service method in the HttpServlet class to aid in processing HTTP-based requests.
  • These methods are:• doGet for handling HTTP GET requests• doPost for handling HTTP POST requests• doPut for handling HTTP PUT requests• doDelete for handling HTTP DELETE requests• doHead for handling HTTP HEAD requests• doOptions for handling HTTP OPTIONS requests• doTrace for handling HTTP TRACE requests
  • Typically when developing HTTP-based servlets, a Servlet Developer will only concern himself with the doGet and doPost methods.
  • The doPut and doDelete methods allow Servlet Developers to support HTTP/1.1 clients that employ these features.
  • The doHead method in HttpServlet is a specialized form of the doGet method that returns only the headers produced by the doGet method.
  • The doOptions method responds with which HTTP methods are supported by the servlet.
  • The doTrace method generates a response containing all instances of the headers sent in the TRACE request.
  • The HttpServlet interface defines the getLastModified method to support conditional GET operations. A conditional GET operation requests a resource be sent only if it has been modified since a specified time.
  • For a servlet not hosted in a distributed environment (the default), the servlet container must use only one instance per servlet declaration.
  • For a servlet implementing the SingleThreadModel interface, the servlet container may instantiate multiple instances to handle a heavy request load and serialize requests to a particular instance.
  • In the case where a servlet was deployed as part of an application marked in the deployment descriptor as distributable, a container may have only one instance per servlet declaration per Java Virtual Machine (JVM).
  • The use of the SingleThreadModel interface guarantees that only one thread at a time will execute in a given servlet instance’s service method.
  • SingleThreadModel Interface is deprecated now


No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: