SRV.3.1 Request Handling Methods


SRV.3.1 Request Handling Methods

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. Multiple request threads may be executing within the service method at any time.

SRV.3.1.1 HTTP Specific Request Handling Methods

The HttpServlet abstract subclass adds additional methods which 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 rest of these methods are considered to be advanced methods for use by programmers very familiar with HTTP programming.

The doPut and doDelete methods allow servlet developers to support HTTP/1.1 clients which support these features. The doHead method in HttpServlet is a specialized method that will execute the doGet method but return only the headers produced by the doGet method to the client. The doOptions method automatically determines which HTTP methods are directly supported by the servlet and returns that information to the client. The doTrace method causes a response with a message containing all of the headers sent in the TRACE request.

In containers that support only HTTP/1.0, only the doGet , doHead , and doPost methods will be used as HTTP/1.0 does not define the PUT, DELETE, OPTIONS, and TRACE methods.

SRV.3.1.2 Conditional GET Support

The HttpServlet interface defines the getLastModified method to support conditional get operations. A conditional get operation is one in which the client requests a resource with the HTTP GET method and adds a header that indicates that the content body should be sent only if it has been modified since a specified time.

Servlets that implement the doGet method and that provide content that does not necessarily change from request to request should implement this method to aid in efficient utilization of network resources.



Java 2 Platform, Enterprise Edition. Platform and Component Specifications
Java 2 Platform, Enterprise Edition: Platform and Component Specifications
ISBN: 0201704560
EAN: 2147483647
Year: 2000
Pages: 399

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net