• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

basic info skipped

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it compulsory to override any method of servlet life cycle for successful compilation and execution of a particular servlet? Please reply in regards of both Servlet and HttpServlet
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In case of Servlet:

You have to override all the life-cylce methods viz. init(), service() and destroy().

In case of HttpServlet:

No need to override all but only the doXXX method that you are using in your client-side(JSP or HTML which will call this servlet), like doGet or doPost.This is because HttpServlet extends Generic servlet which already implements the life-cycle methods.The HttpServlet calls the service method when we call a doXXX method.


A servlet is meant to process a request.When you have a request, you have to provide a service or a doXXX method implementation in your servlet.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I were wondering this, I would create a servlet that extends HttpServlet with no methods overridden.
I would try to compile it and then I would try to deploy it.
I would see what happens.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rao raghu:

You have to override all the life-cylce methods viz. init(), service() and destroy().



Are you sure about this?
Why do you think you need to override these?
Look at:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/GenericServlet.html

Are the life-cycle methods that you've mentioned declared as abstract?
[ January 19, 2007: Message edited by: Ben Souther ]
 
kunal vora
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya but if you use netbeans or eclipse and if you do not override any life cycle methods than also the servlet successfully runs.....
what is the reason behind it then?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again, look at the API for the object you're extending.
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServlet.html

If it implements the methods required by the Servlet interface and those methods are not declared abstract, then you do not need to override them.

Of course, if you will need to override something if you want your servlet to actually do something.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlet is just an interface, so if you use that as the basis for your servlet you will need to implement (not override) all the lifecycle methods.
 
reply
    Bookmark Topic Watch Topic
  • New Topic