GeekInterview.com
Series: Subject: Topic:
Question: 55 of 177

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

Asked by: Interview Candidate | Asked on: Nov 6th, 2006
Showing Answers 1 - 19 of 19 Answers
Srinivasan

Answered On : 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.

Yes  1 User has rated as useful.
  
Login to rate this answer.
HIMANSHU MARKAM

Answered On : 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.  

Yes  1 User has rated as useful.
  
Login to rate this answer.
Bhumika

Answered On : 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.  

  
Login to rate this answer.
Swathi Reddy

Answered On : 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.

Yes  2 Users have rated as useful.
  
Login to rate this answer.
A Naresh Kumar Reddy

Answered On : 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

  
Login to rate this answer.
sunil.yadav

Answered On : Jan 31st, 2007

View all answers by sunil.yadav

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.

  
Login to rate this answer.
Arvind

Answered On : Mar 24th, 2007

One thing morethat 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.

  
Login to rate this answer.
vijay

Answered On : 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.  

  
Login to rate this answer.
sampra

Answered On : Mar 4th, 2008

View all answers by sampra

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.

  
Login to rate this answer.
dhruv_saksena

Answered On : Mar 14th, 2008

View all answers by dhruv_saksena

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

  
Login to rate this answer.
anandbakshi

Answered On : Jun 19th, 2008

View all answers by anandbakshi

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.

  
Login to rate this answer.

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

  
Login to rate this answer.
ixwaku

Answered On : 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.

  
Login to rate this answer.
papia

Answered On : 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

  
Login to rate this answer.
Ashok Kumar Gogula(MCA)

Answered On : 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.

  
Login to rate this answer.
Muhammad Yassein

Answered On : 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

  
Login to rate this answer.
rpd

Answered On : 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

  
Login to rate this answer.
shivaniyadav

Answered On : 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.....

  
Login to rate this answer.
sandy

Answered On : 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....

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

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.