Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doGet and doPost

 
Nilesh Srivastava
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All..
What is the difference between doGet and doPost.and
When we post a form, which form is called doPost or doGet.
Thanks
Nilesh
 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nilesh,
Here is a good explanation :
 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nilesh,
Here is a good explanation : http://www.coderanch.com/t/348803/Servlets/java/Difference-bet-doGet-doPost
 
Gayan Balasooriya
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's another good explanation from
http://www.esus.com/javaindex/j2ee/servlets/servletdogetdopost.html
When you invoke a Servlet, the servlet engine passes the information on to the Servlets service() method. This method determines the type of request made (GET, POST, HEAD, ...) and calls the function doTYPE, like doGet, doPost. GET and POST just differ in the way form data is sent from the browser to the server. The method doGet handles data that has been attached to the url in the form url questionmark (name=value ampersand)+. Typically in a CGI you would have to read the environment variable QUERY_STRING to get this string of concatenated parameternames and values. With the doPost method, form data comes in through standard input stream, a cgi would just need to open the input stream and read until EOF to get the form data.
With Servlets, you don't need to read in the concatenated string of parameternames and values. The parsing is all done behind the scenes. You just need to call getParameter regardless of how the form data is actually sent in.

Gayan Balasooriya
SCJP,SCWCD
http://www.gayanb.com - Free Java/J2EE/J2ME books and mock exams
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic