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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Method of   javax.servlet.Servlet" Watch "Method of   javax.servlet.Servlet" New topic
Author

Method of javax.servlet.Servlet

Vilas Lawande
Ranch Hand

Joined: Nov 07, 2006
Posts: 127
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

Joined: Oct 13, 2005
Posts: 27
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.


SCJP 1.4<br />SCBCD 5.0<br />SCWCD 1.4 (Preparing)
Vilas Lawande
Ranch Hand

Joined: Nov 07, 2006
Posts: 127
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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)


[My Blog]
All roads lead to JavaRanch
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
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

Joined: Nov 07, 2006
Posts: 127
Thanks a lot,
for valuable reply.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Method of javax.servlet.Servlet