On Mon, 12 Jul 1999, Srinivasan S (Systems Engineering Group) wrote:

> Hello people,
>
>         I have a basic doubt in servlets what is the difference
>         between an service method and doPost and doGet methods
>         could u please explain me in detail abt this with an
>         example please i referred lot of examples but none
>         was forthcoming please help me to understand.
[ ... ]

I'll assume that you're aware that HTTP allows different request
methods (not to be confused with the Java/OO sense of "method"), with
GET and POST being two of them (probably the two most common).

With all servlets, the service() method is what is called to service
the request.  In HttpServlet, the abstract base class that all HTTP
servlets must extend, there is a default implementation of service().
Basically all it does is look at the HTTP method being used in the
request, and call the corresponding do***() method.  For example, if
the HTTP method is GET, the doGet() method is called; if the HTTP
method is POST, the doPost() method is called.  This is actually a
pretty nice, useful, modular organization of the servlet code.

HttpServlet does not implement these do***() methods (well, other than
to generate a message that the corresponding HTTP method is not
implemented).  The general idea is that, when you write your HTTP
servlet, you use the default service() method and only override the
do***() methods that you intend to use.  If you want to allow both GET
and POST, and have them do the same thing, you can implement one of
doGet() and doPost(), and have the other call the one that's
implemented.

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[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