• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generic Servlet & ServletContext

 
Khadija Lokhandwala
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a doubt.
Generic Servlet & ServletContext both contain a log() method.
I read in the Servlet docs that

GenericServlet also implements the log method, declared in the ServletContext interface.


But Generic Servlet implements Servlet & ServletConfig interfaces.. so how can it implement a ServletContext's interface method. or is Generic Servlet defined a new method of its own..

If yes, what is the purpose of defining it in both GenericServlet & ServletContext, since you can obtain a servletcontext object from your generic servlet.

I know I am missing something here , please clarify.
Thanks in advance
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say the wording in the javadocs is a bit misleading. It should probably read something like "GenericServlet also implements the log method, which has the same semantics as the log method declared in the ServletContext interface."

Strictly speaking, you're right that the method is different from the one in ServletContext.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that the description has been replaced in Servlets 2.5 :

Before:
GenericServlet makes writing servlets easier. It provides simple versions of the lifecycle methods init and destroy and of the methods in the ServletConfig interface. GenericServlet also implements the log method, declared in the ServletContext interface.

After:
GenericServlet makes writing servlets easier. It provides simple versions of the lifecycle methods init and destroy and of the methods in the ServletConfig interface. GenericServlet also implements the log method, declared in the ServletContext interface.

The javadoc does not seem to be updated though...
[ March 18, 2008: Message edited by: Christophe Verre ]
 
Ashok Kumar Babu
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

1. GenericServlet does not implements ServletContext.

2. The log() method in Generic Servlet implements ServletContext log() method just by calling getServletContext().log()

If yes, what is the purpose of defining it in both GenericServlet & ServletContext, since you can obtain a servletcontext object from your generic servlet.


You may want to override it. This is what my understanding. Please correct me if I am wrong.
 
Khadija Lokhandwala
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Christophe,

The javadoc is unchanged. But I can not figure out the methods repeated in GenericServlet & ServletContext.

Ashok had quoted


The log() method in Generic Servlet implements ServletContext log() method just by calling getServletContext().log()




that's what i think too..
Any inputs???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic