HttpServlet
GenericServlet is truly generic because it is applicable to any
chat-type protocol; however, web development is mostly about the HTTP protocol.
To chat in HTTP, javax.Servlet.http.HttpServlet is best to extend.
HttpServlet is a subclass of GenericServlet. Therefore, the
init, service, and destroy methods from
GenericServlet are available when extending HttpServlet.
HttpServlet defines a method for each of the HTTP methods. These
methods are doGet, doPost, doPut, doOptions,
doDelete, and doTrace. When Tomcat receives a client request
of the GET type, the requested Servlet's doGet() method
is invoked to reply to that client. Additionally, HttpServlet has an
HTTP-specific version of the service method. The only change in the
HttpServlet service method over the GenericServlet's
version is that HTTP-specific request and response objects are the parameters
(javax.servlet.http.HttpServletRequest and
javax.servlet.http.HttpServletResponse).
To write a Servlet by subclassing HttpServlet, implement each HTTP
method desired (such as doGet or doPost), or define the
service method. The HttpServlet class also has a
getlastModified method that you may override if you wish to return a
value (milliseconds since the 1970 epoch) representing the last time the Servlet
or related data was updated. This information is used by caches.
HttpServlet Methods
Table 12.2 includes all of the methods for the javax.servlet.http.
HttpServlet class, and example usage in Jython. Those methods that are
overridden have a def statement in Jython, and those methods invoked on
the superclass begin with self. Java signatures in Table 12.2 do not
include return values or permission modifiers. For permissions, all methods are
protected except for service(ServletRequest req, ServletResponse res),
it has no permissions modifier (package private). All return values are
void except for getLastModified, which returns a long type representing
milliseconds since the epoch.
Table 12.2 HttpServlet Methods
|
Java Signature
|
Usage in Jython Subclass
|
|
doDelete(HttpServletRequest req, HttpServletResponse resp)
|
def doDelete(self, req, res):
|
|
doGet(HttpServletRequest req, HttpServletResponse resp)
|
def doGet(self, req, res):
|
|
doHead(HttpServletRequest req, HttpServletResponse resp)
|
def doHead(self, req, res): *in J2EE version 1.3
|
|
doOptions(HttpServletRequest req, HttpServletResponse resp)
|
def doOptions(self, req, res):
|
|
doPost(HttpServletRequest req, HttpServletResponse resp)
|
def doPost(self, req, res):
|
|
doPut(HttpServletRequest req, HttpServletResponse resp)
|
def doPut(self, req, res):
|
|
doTrace(HttpServletRequest req, HttpServletResponse resp)
|
def doTrace(self, req, res):
|
|
getLastModified(HttpServletRequest req)
|
def getLastModified(self, req):
|
|
service(HttpServletRequest req, HttpServletResponse resp)
|
def service(self, req, res):
|
|
service(ServletRequest req, ServletResponse res)
|
def service(self, req, res):
|
The service method that accepts HTTP-specific request and
response object redispatches those request to the appropriate do*
method (if it isn't overridden). The service method that accepts a generic
Servlet request and response object redispatches the request to the
HTTP-specific service method. The redispatching makes the service methods
valuable when implementing Servlet mappings.
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|