aspose file tools*
The moose likes Servlets and the fly likes Regarding Service, SevletConfig and ServletContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Regarding Service, SevletConfig and ServletContext" Watch "Regarding Service, SevletConfig and ServletContext" New topic
Author

Regarding Service, SevletConfig and ServletContext

Sriram Sharma
Ranch Hand

Joined: Apr 12, 2006
Posts: 98
Why shouldn't we override service, getServletContext and getServletConfig methods?
Any reason for this? What will hapen if we override?

Regards,
Sriram
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

1. service method is common to all HTTP methods like GET, POST, DELETE etc. It gets called whatever the HTTP method of the request is. The default implementation of service method delegates the request to the correct handler for that HTTP method like doGet for GET, doPost for POST etc. If you override the service method, you'll handle all type of HTTP methods with the same code. This might not be correct behavior. Suppose the user sends a DELETE request, then also you'll service that request in a normal form like sending some information etc. But the intention of DELETE requests is to delete the resource.

2. If you want to override the getServletContext and getServletConfig method, you'll also have to override the init(ServletConfig conf) method. The default implementation in the GenericServlet class handles all these details nicely. So normally you only override the init() method without any parameters. This is what the GenericServlet class usually does for you



Implementing this again manually is just a waste of effort...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding Service, SevletConfig and ServletContext