[EMAIL PROTECTED] wrote:
> i don't even overload doPost() and doGet() anymore in my servlets - i go
> straight to service().  is that bad if i don't treat posting vs. getting
> differently?  i can't imagine why, but in case anyone has a good reason not
> to do it that way i'd be happy to hear it.

Kito D. Mann ([EMAIL PROTECTED]) replied:
> Like everything else, I don't think there's a simple answer. Generally, I
> stick to the main point of a GET request (querying info) and a POST request
> (posting data). I generally use service() for any processing which is used
> by all types of requests. So my code typically has general code (such as
> user checking) in the service method, and then calls doGet() or doPost() to
> handle the request. But, if your servlet responds the same for GET and POST
> requests, there's really no reason to use the individual handlers.

     I had pretty much the same opinion, until I managed to spark off
a long thread on this topic a couple months ago, which convinced me
that it's a good idea, from a design standpoint, to leave service()
alone.

     In a nutshell, service() dispatches incoming requests to doGet(),
doPost(), doPut(), doDelete(), doOptions(), doTrace(), or
getLastModified(), according to the HTTP headers in the request.  By
overriding service() instead of the specific operation you need to
customize, you make life much more complicated aind painful if you
need to handle one of the other request types later on, or if you
perhaps need to handle GET differently than POST.

     I suspect most people coming from the CGI world will find this a
bit inobvious, since we're used to letting the server handle all the
other operations and only invoke CGI for GET or POST operations.  But
servlet programmers apparently tend to look at servlets as more of a
whole application than something to respond to a specific request.

     You can see most of the original thread of messages on this topic
at:

http://archives.java.sun.com/cgi-bin/wa?S2=servlet-interest&q=service+and+doGet+and+doPost&s=service+or+get+or+post&f=&a=1+september+1999&b=1+december+1999

Steven J. Owens
[EMAIL PROTECTED]
[EMAIL PROTECTED]

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to