• 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

servlet life cycle

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In many interviews there is frequently asked question about life cycle of the servlet
I know the init(),service(), and destory() methods well
But how to answer this question up to the point (how much scope)
And please can u explain about
Do not override service() method.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ALaxmi Shankaran:
In many interviews there is frequently asked question about life cycle of the servlet
I know the init(),service(), and destory() methods well
But how to answer this question up to the point (how much scope)
And please can u explain about
Do not override service() method.



Reply:

if they ask servlet life cycle tell in details of each methods like

init() will call first time and it intialize one time and then it calls service method.explain about init()...

like:
{don't explain like this study this and tell in your words}
The init() method is typically used to perform servlet initialization--creating or loading objects that are used by the servlet in the handling of its requests. Why not use a constructor instead? Well, in JDK 1.0 (for which servlets were originally written), constructors for dynamically loaded Java classes (such as servlets) couldn't accept arguments. So, in order to provide a new servlet any information about itself and its environment, a server had to call a servlet's init() method and pass along an object that implements the ServletConfig interface. Also, Java doesn't allow interfaces to declare constructors. This means that the javax.servlet.Servlet interface cannot declare a constructor that accepts a ServletConfig parameter.

what servlet will do:
1)Create and initialize the servlet. -init()
2)Handle zero or more service calls from clients. -Servie
3)Destroy the servlet and then garbage collect it. -destroy

Answer for your question here:

init()Called only once during the initialization of the Servlet.
destroy()Called only once when Servlet instance is about to be destroyed.
service()Do not override this method.
doGet(), doPost(), doPut(), doDelete(), doOptions, doTrace()These methods are called according to the type of HTTP request received. Override them to generate your own response.


thanks

mail me if u want any further answer:

jai gurudev
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic