|
|
Start of Tutorial > Start of Trail |
Search
Feedback Form |
An HTTP Servlet handles client requests through its
servicemethod. Theservicemethod supports standard HTTP client requests by dispatching each request to a method designed to handle that request. For example, theservicemethod calls thedoGetmethod shown earlier in the simple example servlet.
This section discusses using the objects that represent the client's request (anHttpServletRequestobject) and the servlet's response (anHttpServletResponseobject). These objects are provided to theservicemethod and to the methods thatservicecalls to handle HTTP requests.
The methods to which theservicemethod delegates HTTP requests include,
doGet, for handling GET, conditional GET, and HEAD requests
doPost, for handling POST requests
doPut, for handling PUT requests
doDelete, for handling DELETE requests
By default, these methods return a
BAD_REQUEST (400)error. Your servlet should override the method or methods designed to handle the HTTP interactions that it supports. This section shows you how to implement methods that handle the most common HTTP requests: GET and POST.The
HttpServlet'sservicemethod also calls thedoOptionsmethod when the servlet receives an OPTIONS request, anddoTracewhen the servlet receives a TRACE request. The default implementation ofdoOptionsautomatically determines what HTTP options are supported and returns that information. The default implementation ofdoTracecauses a response with a message containing all of the headers sent in the trace request. These methods are not typically overridden.
HTTP servlets are typically capable of serving multiple clients concurrently. If the methods in your servlet do work for clients by accessing a shared resource, then you must either:
This lesson shows you how to implement your second option. (The first is covered in the tutorial's lesson on threads.)
- Synchronize access to that resource, or
- Create a servlet that handles only one client request at a time
In addition to handling HTTP client requests, servlets are also called upon to supply descriptions of themselves. This section shows you how to provide a description by overriding the method,
getServletInfo, that supplies the servlet description.
|
|
Start of Tutorial > Start of Trail |
Search
Feedback Form |
Copyright 1995-2002 Sun Microsystems, Inc. All rights reserved.