• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about servlet request methods  RSS feed

 
bhagya patil
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Servlet where exactly do we use doXXX(http_req, http_res) ?
I haven't found any use of these doXXX() method in most of the applications?
[ October 16, 2007: Message edited by: Ben Souther ]
 
Nischal Tanna
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am surprised that you have not found any such application as of now...Anyways doGet and doPost are the generally used doXXX methods...doGet is used when the request form has <form method="get">...doPost is used when method="post"....i prefer the doPost as it does not show up parameters in the URL whereas while using get method, the form parameters are appended to the URL, something like http://www.javaranch.com/test?name=rocky&surname=rocks....
 
prakash chauhan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the doXXX methods are called by service() method which in turn is called by the container (tomcat for example) , the service() mehtod will always be called when ever a request comes to the container for a resource(servlet) but by allowing you to implement the doXXX() methods , the container gives you the power to accept or reject particular types of requets , for example if you implement only doGET then the Post requests will not be processed and vice versa.
Hope it clears some confusion.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see an awful lot of people make doGet and doPost do the same thing. That is they both call a third method that does all the work or one calls the other which does all the work. This strikes me as a lazy convenience, and doesn't match the intent of the HTTP spec. GET, POST, PUT, DELETE, HEAD and other "methods" each has a purpose.

Take a look for the HTTP definitions of the methods, and then Google for REST or RESTful architecture. It's cool stuff and worth doing right.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!