• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

doGet() & doPost()

Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a doubt in Servlets.In a Servlet class we need to override doGet()/doPost() methods.The invoking of corresponding methods will depend on the way the form submitted.If the form is submitted with GET method then doGet() is invoked.If POST is used doPost() is invoked().My question is how the servlet engine recognises that a form is submitted with GET/POST method.I will be highly grateful for the same.
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Service method is invoked when the client acceses the servlet. It dispatches the request to the corresponding doGet/doPost method. This servicemethod checks the HTTP Request type get/Post and calls the corresponding doget/doPost method The method is specified on the form when it's submitted. If no method is specified at all, the default is to use doGet.
Posts: 20838
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTTP, like most of the original Internet protocols is based on transmissions of text messages. This was partly because the original nodes of the Internet had different internal binary representations, and quite a few of them had different character codesets (ASCII or EBCDIC). It's much easier to translate codesets than binary fields, especially when you're bouncing a message through a dozen intermediate computers or more.
There's another fringe benefit - it's easier to debug the protocol if you can directly print eveything going up and down the wire - or even drive it manually via a telnet to port 80.
You can write Internet apps all day long, but you'll never truly be an Internet Guru until you know what the format and sequence of those messages are. They're documented in a set of RFC (Request For Comment) documents, and the one for HTTP v1.1 is RFC2068: http://www.w3.org/Protocols/rfc2068/rfc2068
The short answer tou your question, though, is that if you have a hyperlink or a form whose action is "GET", a message in the following form is sent:
GET http://www.myserver.com/mypage.cgi?arg1=foo&arg2=bar
If a form has action POST, it will look more like:
POST http://myserver.com/mypage.cgi
There may be some inaccuracies here, and I haven't bothered to show the headers, but that's the core of it. The RFC is the authority.
[ January 11, 2002: Message edited by: Tim Holloway ]
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I'm flogging my posts again!

Regular: http://www.javaranch.com/ubb/Forum7/HTML/006990.html
Multipart: http://www.javaranch.com/ubb/Forum7/HTML/006987.html
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!