From the API: javax.servlet.http.HttpServlet.service() Dispatches client requests to the protected service method. javax.servlet.http.HttpServlet.doGet() Called by the server (via the service method) to allow a servlet to handle a GET request. javax.servlet.http.HttpServlet.doPost() Called by the server (via the service method) to allow a servlet to handle a POST request. There is more information available in the API, but essentially the HTTP protocol supports multiple ways of making requests to a server. When the servlet container receives the request, it finds out which Servlet to send it to. The servlet service() method gets called, and it looks at the request, decides what sort of request it is and calls a doXXX() method. There are more than just doGet and doPost. You can override the service() method to manage all requests at a central point, but usually you want to retain the doXXX() methods, so if you do override the service() method, you would add some specific functionality and then still call the corresponding doXXX() method. Dave
Joined: Nov 01, 2002
One additional note: doGet is default so when calling the servlet from a hyperlink or when no action is specified in the form, this is what is called. So, I've always felt that it's better to use both and have doGet call doPost for these cases.
No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
Joined: Feb 23, 2004
And since 'GET' is the default protocol used when requesting a page/servlet, it can be used to determine the state of your app. Of course you could use a fullblown MVC framework like Struts, but consider this: doGet: generate a form, action is same servlet with method=post doPost: process input from the form This way it's easy to separate the two views.