• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doGet() and doPost()

 
Sowjanya Chowdary
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody please explain me what is the difference between doGet() and doPost() methods in form tag's action?
I am really confused when to use doGet and when doPost().
 
Eric Pascarello
author
Rancher
Posts: 15385
6
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the Servlets forum.
 
michel knight
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you just use one servlet to do simple things. you can do it like me:

public class testservlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doService(request,response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doService(request,response);
}

public void doService(HttpServletRequest
request,HttpServletResponseresponse)
throws ServletException, IOException {
//put your code here
}
}

when you dont know what time do doGet() and what time do doPost(),just do it like me
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Amrutha Ch",

There aren't may rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Sowjanya Chowdary
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello,
Thanks for the reply. It has been a useful link.

Bear Bibeault,
I had adjusted my display name. Hope it is obeys JavaRanch Naming Policy now.
 
ranjan kumar panda
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Amrutha, I think you did not get the right answer to your question even not in the link given to you. This is how it works.
---doGet() is to generally get some data rather than posting data. But we generally use doGet() as to post a very small amount of data to the server to let the server know what kind of data we are expecting to get as a responce. As data volume is very small mostly upto 240 characters it is just appended in the requested URL (Query String).Once we send that small amount of data to the server there is no constraint in getting any volume of data.
---- On the other hand, doPost() method is generally meant for posting data of large volume to the server. You can post unlimited amount of data to the server which is carried forward with a request object. So the query string does not change.
This is the basic thing behind it. If you want more then send me querries.
 
Sowjanya Chowdary
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ranjan.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic