wood burning stoves 2.0*
The moose likes Servlets and the fly likes Question on GenericServlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Question on GenericServlet" Watch "Question on GenericServlet" New topic
Author

Question on GenericServlet

Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
I'm looking at the api for GenericServlet.

Can aynone turn me onto the reason that, even though the class implements the ServletConfig interface, it has a separate method called getServletConfig()?

Why would a class need a method to getServletConfig() if it is an instanceof ServletConfig?


Fun programming etcetera!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, it also implements Servlet, which has the getServletConfig() method, so it is forced to implement that method.
Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
Ok, I can see that. At the risk of seeming peevish, anyone have thoughts on why a class that's forced to supply a getter method for an interface would also implement that interface? I'm just trying to get a feel of the APIs structure and feeling lost.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Basically GenericServlet implements Servlet because it wants to be a servlet. When I look at it, my peevishness arises from why it needs to implement ServletConfig. Smells like the bad kind of multiple inheritance to me. But this stuff was designed years ago. I bet if they were doing it now, GenericServlet wouldn't implement ServletConfig. It doesn't need to BE a ServletConfig if it already HAS a ServletConfig.

The way it is now, there's always a question of whether servlet.getServletConfig().x() returns the same thing as servlet.x() -- it appears that it always does, but why make a design where the question has to be asked?
Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
Thanks for the reality check. I'm glad someone else found the design to be strange.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on GenericServlet
 
Similar Threads
servletContext
init method of Servlet
Doubt in Servlets
init() methods in Generic Servlet
getServletConfig()