• Post Reply Bookmark Topic Watch Topic
  • New Topic

service(req,res) Vs doGet()/doPost()  RSS feed

 
Hemant Bhaiya
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Servlets, we can override the service() method or doGet()/doPost() to get the work done.But what is the criteria for selecting whether to use the service() method or any of other two methods?Is there any performance improvement when we use service() method directly?
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need to mention here that someone from the ranch corrected
my doubt. service method w'd be called even for header requests + am not sure what else. So probably you w'd'nt want that behaviour.
So you are better off overriding doGet and doPost methods.
I don't see much of a preformance problem i guess service() w'd forward the call accordingly..basically just one method call away.
karthik.
 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
my servlet book say not to overwrite service method.
if you want doGet and doPost supported you should call either doGet from doPost or vice versa.
there is other stuff called in the service:
GET
POST
HEAD
TRACE
OPTIONS
TRACE
(check the code of HttpServlet do see details)
i assume that POST/GET and HEAD are most often used.

karl
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!