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

Showing Answers 1 - 58 of 58 Answers

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.

HIMANSHU MARKAM

  • Nov 25th, 2006
 

1-->

In doget() method there is a security problems are arrival because when the user or client submit the form the associated user name or password has been display on the addressbar.

but in case of doPost() method when the user submit the form the associated user name or password are not display on the addressbar.

2-->

by doget() method client can send limited amount of data.

but in case of dopost() method client can send more then data as compare to doget() method.

 

 

Bhumika

  • Dec 4th, 2006
 

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.  

  Was this answer useful?  Yes

Swathi Reddy

  • Dec 18th, 2006
 

In addition to the above Comments ,

doPost(..) method is generally used for Insertion /updation / deletion of data , whereas doGet(..) is used when the users tries to request for any Read Only data.

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

sunil.yadav

  • Jan 31st, 2007
 

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.

  Was this answer useful?  Yes

Arvind

  • Mar 24th, 2007
 

one thing more

that is by doGet() method we becomes limted for sending parameters,bcoz each specific browser has a limtitation,means they can send  parameters only in limtation,

but by doPost() method we can send unlimited parameters through browser.

  Was this answer useful?  Yes

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.  

  Was this answer useful?  Yes

sampra

  • Mar 4th, 2008
 

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.

  Was this answer useful?  Yes

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.

Dhruv

  Was this answer useful?  Yes

anandbakshi

  • Jun 19th, 2008
 

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.

  Was this answer useful?  Yes

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

  Was this answer useful?  Yes

ixwaku

  • Sep 22nd, 2011
 

1-->

In doget() method there is a security problems are arrival because when the user or client submit the form the associated user name or password has been display on the addressbar.

but in case of doPost() method when the user submit the form the associated user name or password are not display on the addressbar.

2-->

by doget() method client can send limited amount of data.

but in case of dopost() method client can send more then data as compare to doget() method.

3-->doget() it is default method in case of form and hyperlinks but we have to mention dopost() method explicitly.

  Was this answer useful?  Yes

papia

  • Sep 24th, 2011
 

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

  Was this answer useful?  Yes

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.

  Was this answer useful?  Yes

Muhammad Yassein

  • May 17th, 2012
 

1-
DoPost() Method work with post method from Client
DoGet() Method work with get Method from Client

2-
DoPost () is Secure than DoGet
DoPost() send user data in form Body and Encryption Data
DoGet() send user data in url Heder and not Encrypted data

3-
DoGet() best performance than DoPost() because page header send before page body

4-
DoGet() can limit data up to 256 byte only
DoPost() unlimit Data from user

5-
doGet() Limited user Parameter
doPost() unlimited user paameter

6-
doGet() is Default way in html form method
doPost() you must determine it when cal form method

7-
doGet() you can bookmark or save in favorite and recall it again .
doPost() you can not bookmark it and when tried to call url-pattern U will not find it

thanks

  Was this answer useful?  Yes

rpd

  • Jul 19th, 2012
 

in doPost() data of the client is send as apart of request body and in doGet() data of the client is send as a part of url

  Was this answer useful?  Yes

shivaniyadav

  • Jul 28th, 2012
 

they both r service methods.....

do get() has a disadvantage of sending very less amt of
information as it can send 24 to 255 character........

do post() is used for posting d information.....

  Was this answer useful?  Yes

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....

  Was this answer useful?  Yes

Gopi Devarapalli

  • Sep 11th, 2014
 

The doGet() attach result to URL. where as doPost it will not show result on the URL. It is internally attaches to next resources.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions