What is the difference between doGet() and doPost() methods of a HttpServlet and when to use each one?

Srinivasan

Nov 7th, 2006

Hai doGet() method is the default HTTPServletRequest method. In this user entered data is appended to the URL as query String. It can send only limited amount of data. In doPost() method the user entered information as data and not appended to the URL.It can send any amount of data.

Bhumika

1. In doGet() u submit the request by appending the URL while in doPost() request is submitted via form.

2.Since doGet() appends the link it is not safe for request containing passwords etc. while doPost() uses form hens it is safe.

3.You can send only limited data in doGet() while unlimited data in doPost() .

4.doGet() request could used like a bookmark as it uses URL ,but doPost() can't be used as bookmark.

5.doPost() is Idempotent i.e if the user requests for some thing & later he changes his decision & rerequests to make some changes in previous request ,doPost() gets failed in that case ,while doGet() is useful in such cases.

A Naresh Kumar Reddy

Jan 9th, 2007

doGet is used when there is are requirement of sending dataappended to a query string in the URL. The doGet models the GET methodof Http and it is used to retrieve the info on the client from some server as arequest to it.The doGet cannot be used to send too much info appended as a querystream. GET puts the form values into the URL string. GET is limited toabout 256 characters (usually a browser limitation) and creates reallyugly URLs.

POST allows you to have extremely dense forms and pass that to theserver without clutter or limitation in size. e.g. you obviously can'tsend a file from the client to the server via GET. POST has no limit on the amount of data you can send and because thedata does not show up on the URL you can send passwords. But this doesnot mean that POST is truly secure. For real security you have to lookinto encryption which is an entirely different topic

Depending on the request type (get or post) container invokes the corresponding doGet() or doPost() method, by default the request type is get and the container looks for doGet() method.preferabily for posting data through form post is used, and for getting data from server side preferabily get is used, get is fastt than post request, get transfers data through url and hence not safe, post transfer data as a body or in the form of packets, get can transfer limited data, post has no such limitation.

vijay

Nov 8th, 2007

Hai doGet() method is the default HTTPServletRequest method. In this user entered data is appended to the URL as query String. It can send only limited amount of data. In doPost() method the user entered information as data and not appended to the URL.It can send any amount of data.

1. In doGet() u submit the request by appending the URL while in doPost() request is submitted via form.

2.Since doGet() appends the link it is not safe for request containing passwords etc. while doPost() uses form hens it is safe.

3.You can send only limited data in doGet() while unlimited data in doPost() .

4.doGet() request could used like a bookmark as it uses URL ,but doPost() can't be used as bookmark.

5.doPost() is Idempotent i.e if the user requests for some thing & later he changes his decision & rerequests to make some changes in previous request ,doPost() gets failed in that case ,while doGet() is useful in such cases.

Depending on the request type (get or post) container invokes the corresponding doGet() or doPost() method, by default the request type is get and the container looks for doGet() method.preferabily for posting data through form post is used, and for getting data from server side preferabily get is used, get is fastt than post request, get transfers data through url and hence not safe, post transfer data as a body or in the form of packets, get can transfer limited data, post has no such limitation.

See whenever a request comes up it goes to service() method of Httpservlet which forwards it to the doGet() or doPost() method depending on the type of request GET or POST.

In get request we have certain limit on the amount of parameters which we are sending to the servlet and also the parameters get inserted in the URL also but if we are using a POST request we can pass as many no. of parameters as we want and the wont get updated in the URL also.

First,In the case of DoGet() the data is appended to the end of the URL,whereas in the doPost() the data is sent to the server at the end of the body of the text.Second,the max. is 240 bytes in the former whereas in the latter their is no limit.Third,the parameters are not encrypted in the former and encrypted in the later.Fourth,doget() is faster as compared to doPost()Fiffth,doPost being encrypted is safer to use over the network than doGet()

In practical use the functionality of both are same.Developers who have deploy a small to medium project should use doGet() because it is faster and easier to implement,but implimenting it over a larger network where the methods are called repeatidly it is better to use doPost() for better safety and proper execution prodecure.

The difference between doGet() and doPost() method is-
-doGet() method is limited with 2k of data to be sent, and doPost() method doesn't have this limitation.
-in doGet() method the data is not secured where as in doPost() the data is secured

papia

1) In doGet Method the parameters are appended to the URL and sent along with header information. In doPost, parameters are sent in separate line in the body

2) Maximum size of data that can be sent using doget is 240 bytes in doPost There is no maximum size for data.

3)In doGet Parameters are not encrypted. In doPost, Parameters are encrypted

4) DoGet method generally is used to query or to get some information from the server.Dopost is generally used to update or post some information to the server

5) DoGet is faster if we set the response content length since the same connection is used. Thus increasing the performance. DoPost is slower compared to doGet since doPost does not write the content length

6) DoGet should be idempotent. i.e. doget should be able to be repeated safely many times. In doPost,This method does not need to be idempotent. Operations requested through POST can have side effects for which the user can be held accountable, for example, updating stored data or buying items online.

7) DoGet should be safe without any side effects for which user is held responsible. In doPost,This method does not need to be either safe

Ashok Kumar Gogula(MCA)

Oct 15th, 2011

A doGet() method is limited with 2k of data to be sent, and doPost() method doesn't have this limitation. A request string for doGet() looks like the following:

http://www.allapplabs.com/svt1?p1=v1&p2=v2&...&pN=vN
doPost() method call doesn't need a long text tail after a servlet name in a request. All parameters are stored in a request itself, not in a request string, and it's impossible to guess the data transmitted to a servlet only looking at a request string.

sandy

Jul 17th, 2014

if we override either lifecycle or non-lifecycle service method, then our servlet class loses the logic given by the super class but if we override doGet() or doPost() method of super class , then our class doesnt loose any superclass logic.

doGet() or doPost() is decided based on Http protocol method if Http method is get(), then doGet() method is overriden and if Http method is post(), then dopost methods are overriden....

What is the difference between MS SQL Server and SQL Server? Are both same are not?

Asked by: Sireesha

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.

This site uses cookies to deliver our services and to show you relevant ads and job listings. By using our site, you acknowledge that you have read and understand our
Cookie Policy,
Privacy Policy, and our
Terms of Service. Your use of GeekInterview’s Content, Products and Services, including the Exforsys Inc Network, is subject to these policies and terms.