Introducing doGet() and doPost() Methods

These two methods acts as Service() method in servlet. In project we can use service() or doGet() or doPost(). Now let us see doGet() and doPost() in detail.

doGet(): 

This method indicates which operation has to be carried out by the server. This is the default method sent by the client to the server. In get(), the data that client wants to send to server will get appended to url. But the url limits to 1024 characters. Let us see with example. When we type the url in the address bar and once if we press Enter, by default get request goes to the server. 

doGet()  example

In the above figure you can see the login form. Since this is get() when we enter the username and password and click on Enter/Login button, both the username and password gets appended to the url as follows.

doGet() example.

You can observe the username and password appended to the url. This is the major disadvantage of get() method. To overcome this we use Post().

doPost():

 This method is also used to execute the resource in a server. When we use Post(), the browser/client sends the data to the server through request body. This is the only difference between Get() and Post(). Post request is highly used for secured web pages.                             



No comments:

Post a Comment