• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Purpose of ServletConfig??

 
Anand Wadhwani
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope this does not comes out as a stupid question!

What is the purpose of getServletConfig() method in a servlet? I have seen this being primarily used to get Init parameters for the servlet.

But my point is that getInitParameter() method is defined in servlet itself, and cane be used as it is. In fact GenericServlet implements ServletConfig interface, and therefore essentially all methods of ServletConfig can be used in the servlet implementation class without using getServletConfig() method, then why this method exists?

Thanks!
[ June 19, 2005: Message edited by: Anand Wadhwani ]
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think the Servlet object provided by the container is different than the ServletConfig object. ServletConfig is interface. Our servlet class is extended from GenericServlet class indirectly. The genericServlet class only implement the methds of ServletCnfig object. I treat the GenericServlet is a Adaptor class which implemets methods of both Servlet and ServletConfig interfaces. When you call the methods in the Servlet related to ServletConfig methods, these methods indirectly calls the methods from the Object of ServletConfig.
I treat thses method as conveniance method which refers the ServletConfig object only.

This is my understanding. Anybody can correct me?

Thanks
 
Anand Wadhwani
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Narendra for the prompt response!

But unfortunately I am still confused about purpose of getServletConfig() method in servlet class.

Let me put my question this way:

Is there any method of ServletConfig object which can be called only via ServletConfig object and not via 'this' Servlet object, i.e. is there any method which can called only via following syntax:

getServletConfig().Some_Method();

and not via:

Some_Method();

??

I am just trying to understand the objective of using getServletConfig() method in our servlet object. Per your response I understand that our servlet object is decorating ServletConfig object's methods then why would we ever need to call getServletConfig() method ever? I guess that the intention is to pass ServletConfig object to some other utility class. That's the only purpose I see. Please confirm!

Thanks Much!
[ June 18, 2005: Message edited by: Anand Wadhwani ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic