The difference between GET and POST
There are two principal methods by which a browser interacts with a web server.
The most common is the GET method, in which the browser simply
requests the contents of a particular URL. When the browser uses this method,
the web server ends up calling the servlet's
The second is the POST method, in which the browser "sends"
data to a particular URL. For example, it may send some data than a user has
entered in a form on a web page. In this case, the servlet's
In practice, there is some overlap between the two methods, and your servlet may not even need to care which method is used.
This is because either GET or POST can actually be used to send data from a web
form. With the GET method, the data is appended to the URL with a special syntax.
You've probably seen URLs such as
To a servlet, there's really little difference between the two methods. In one case, doGet() will be called, and in the other doPost. But in either case, the servlet container such as Tomcat will already have extracted the parameters (be they in the URL or in posted data) and makes them available via the HttpServletRequest object. Unless you specifically care which method is used and want to carry out very different actions accordingly, you can generally make the doPost() method simply pass the request directly to your doGet() method.
Back to servlet introduction and skeleton servlet class.
Written by Neil Coffey. Copyright © Javamex UK 2008. All rights reserved.