Example & Tutorial understanding programming in easy ways.

What is the difference between doGet() and doPost()?

The difference between doGet() and doPost() methods of servlet lifecyle are as follows:-


doGet();

doPost()

In doGet(); method the parameters are appended to the URL and sent along with header information in the browser.

In doPost(); method, send the information in a html form element through socket back to the webserver and it won't show up in the URL bar.

The amount of information you can send less amount of information using a GET and it is restricted as URLs can only be 1024 characters.

You can send much more information to the server bydoPodst(); - and it's not restricted to textual data either. It is possible to send files and even binary data such as serialized Java objects any sensitive data also.

In the doGet(); method it is a request for information; it does not (or should not) change anything on the server. (doGet() should be idempotent).

In the doPost(); method it provides information (such as placing an order for merchandise) that the server is expected to remember. Like kart APIs.

The parameters are not encrypted in this method.

The parameters are encrypted in this method

The doGet(); method is faster if we set the response content length since the same connection is used. Thus increasing the performance of our application.

This doPost() method is generally used to update or post some information to the server. doPost() is slower compared to doGet since doPost does not write the content length.

This doGet() method should be idempotent. i.e. doget should be able to be repeated safely many times.

This method does not need to be idempotent. Operations requested through POST can have side effects for which the user can be held accountable.

The doGet() method should be safe without any side effects for which user is held responsible

This method does not need to be either safe


It allows bookmarks.

It disallows bookmarks.


Read More →