aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Doubts in service()/doPost()/doGet() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Doubts in service()/doPost()/doGet()" Watch "Doubts in service()/doPost()/doGet()" New topic
Author

Doubts in service()/doPost()/doGet()

Micheal John
Ranch Hand

Joined: Nov 01, 2006
Posts: 344
I have a doubt, What is the situation in which we need to override the service()? In lots of example I have seen, instead of overriding the doPost/doGet, they override the service()? Is there any necessity to override the service() than overriding doPost()/doGet()?

And also, I have seen some examples that both doGet and doPost are overridden in the same servlet? Why? and What for? They have used like below:


if the above servlet is called directly wihout from any form, the doGet will first execute right?
[ December 31, 2006: Message edited by: Micheal John ]

Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Well sometimes people call the methods in that way so that both doPost and doGet functionalities are supported. Very rarely would you have to override the service method to achieve an end result.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42635
    
  65
One of the things the service method does is to distinguish between the various HTTP methods. The available HTTP methods are GET, POST, HEAD, TRACE, PUT, DELETE and OPTIONS. If service is overridden, then the dispatching to the proper doXYZ methods has to be performed by the servlet code itself. Note that the javadocs state "There's no need to override this method."

You're right that doGet would be called if a URL is entered into a browser. Sometimes it can be useful to have GET and POST do different things in a servlet, but I'd consider that not such a good design. At other times you might want to specifically disallow either GET and POST, in which case it's handy to be able to differentiate between the two.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubts in service()/doPost()/doGet()