This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method of javax.servlet.Servlet

 
Vilas Lawande
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Where menthos of interface javax.servlet.Servlet
implemented ?
i.e. getServletConfig();

If in GenericServlet then
Why it is abstract class.


Thanks in advance.
Vilas
 
Ashwin Kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the methods of Servlet and ServletConfig are implemented in GenericServlet.

Only abstract method in GenericServlet is the service(ServletRequest, ServletResponse) method. The implementation of this method is left to the class which extends GenericServlet. HttpServlet happens to be one of such classes, which provides HTTP specific implementation.

Similarly we can choose to have another FTPServlet which provides FTP specific service() method implementation.

In otherwords, GenericServlet is abstract because it gives a generic signature for the service() method, leaving the implementation details to the subclass.
 
Vilas Lawande
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Originally posted:.............

Only abstract method in GenericServlet is the service(ServletRequest, ServletResponse) method. The implementation of this method is left to the class which extends GenericServlet.


Then,
if we don't write service method in userservelt(programmer)
& write only doGet or doPost
then how it will work.


Originallt posted:............

Similarly we can choose to have another FTPServlet which provides FTP specific service() method implementation.

What is this FTPServlet.?
[ September 17, 2007: Message edited by: Vilas Lawande ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if we don't write service method in userservelt(programmer) & write only doGet or doPost then how it will work.

If you're dealing with HTTP servlets, then you usually extend your servlet from HttpServlet, which deals with the service() method. If you extend from GenericServlet, you must implement the abstract service method, otherwise it won't compile.

What is FTPServlet

It is just an example, given by Ashwin, of another kind of class which could extend the GenericServlet. (it does not exist)
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posted by vilas
if we don't write service method in userservelt(programmer)
& write only doGet or doPost
then how it will work.


The HttpServlet has overridden the service method which checks for the incoming request and invokes one of the method doGet,doPost.. depending on the type of request.
There is nothing stopping you from overriding the service method of HttpServlet but why do you need to do it when you have the do<Method> available?
 
Vilas Lawande
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot,
for valuable reply.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic