This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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?
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.