aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes getServletConfig() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "getServletConfig()" Watch "getServletConfig()" New topic
Author

getServletConfig()

Kris Reid
Ranch Hand

Joined: Jan 05, 2005
Posts: 247
Why does a servlet have a method getServletConfig() when servlet IS-A ServletConfig?

That is, Servlet implements ServletConfig so the method appears to just return a referance to it's self.

All the examples in HEad first use this method and it seams pointless
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,

The GenericServlet implements the ServletConfig interface, but the Servlet interface does not extends the ServletConfig. The getServletConfig method is from Servlet interface. As per the specification this method needed if you are plannining to define your own servlet class which does not extends GenericServlet or the class does not implements Servletconfig directly or indirectly.

Thanks


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Kris Reid
Ranch Hand

Joined: Jan 05, 2005
Posts: 247
That is a fine point.

But I am talking about HttpServlet.
What is the point of using getServletConfig on a class that is a ServletConfig?
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
Originally posted by Kris Reid:
That is, Servlet implements ServletConfig so the method appears to just return a referance to it's self.


Are you sure that the method, getServletConfig() returns a reference to itself? Or is it possible that the method returns a reference to a different Object implementing the ServletConfig interface. This Object could be a member variable of the GenericServlet. The Adapter pattern rings a bell for me here.

I think that the Object implementing Servlet and ServletConfig are different because you pass ServletConfig to the init method of Servlet.

void init(ServletConfig config)
Kris Reid
Ranch Hand

Joined: Jan 05, 2005
Posts: 247
I don't see why it wouldn't be passing a referance to it self.

you are calling getServletConfig which will return a ServletConfig with all the information about this Servlet. Therefore what instance of ServletConfig would have more information about the Servlet then the Servlet itself?

I just think it is a waste of resources to call getServletConfig().getInitParameters(name) when you can just call getInitParameter(name)
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
Originally posted by Kris Reid:
I just think it is a waste of resources to call getServletConfig().getInitParameters(name) when you can just call getInitParameter(name)


I agree. . I guess the designers of the Servlet API wanted us to use getInitParemter(name) instead of getServletConfig().getInitParameter(name).


But what I meant in my above post is that it could be possible
that ServletConfig and Servlet could be different Objects.
If you compare the Servlet(this pointer) to the ServletConfig() object,
they may not be the same.
sergio mendez-rueda
Ranch Hand

Joined: May 12, 2005
Posts: 37
hi,
Sevlet is an INTERFACE
O.K.
GenericServlet IMPLEMENTS Servlet
Servlet can't implements nothing!! Why??
Servlet is an INTERFACE!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getServletConfig()
 
Similar Threads
GenericServlet & ServletConfig
Servlets and ServletConfig problem
GenericServlet Question
init method of Servlet
ServletContext within ServletConfig