• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Constructor of a Servlet ?

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I have the following doubt :
As I understand, the servlet is instantiated by the servlet container, when the first request is sent by a user (client).
Then only its service method is called.
But then where is the constructor of the servlet located ? I mean how does the container instantiates the servlet object ?
Thanks in advance
Mandar
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The container uses the default constructor to instantiate the servlet.You can define the constructor if you want.
 
Mandar Puranik
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Osama,
Thanks for the answer, but where is that constructor ?
Mandar
 
Osama Hasan
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The default constructor is created implicitly when no constructor is provided.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the JavaDocs for GenericServlet and HttpServlet in the servlet API. You will find empty no-args constructors. The only thing a servlet constructor has to do is initialize memory for the instance variables. This is similar to the Applet API.
Thats because both servlets and applets are held in a "container" that provides many functions, including instance construction. The init method is where you are expected to do custom initialization using the servlet context.
Just one of the many differences you have to get used to when programming servlets.
Bill
 
Mandar Puranik
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks Osama and William.
That clears my doubts about the Servlet Constructor.
Will be back with more doubts, as I go on..

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