• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How does the servlet class object get loaded?

 
santhosh.R gowda
Ranch Hand
Posts: 296
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all

If we define a constructer for a servlet class then how the container will create the object for that servlet class....
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The web app developer should not provide any constructor for a servlet. It's for the servlet container to construct servlets using the no-argument constructor. Anything the app developer needs to do for servlet initialization should go into one of the "init" methods. Also see http://faq.javaranch.com/java/ServletsFaq#lifecycle for further information.
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As i saw in cavaj decompiler default servlet constructer has been created .... and i also in Head first Servlet that after loading the servlet class it runs servlet constructer provided by the compiler ... tell me how exactly container executes servlet class files in detail are please provide me a link to go through
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the compiler will insert a no-argument constructor if the developer didn't add any constructor. (A constructor is needed to, well, construct objects.) But that's standard Java behavior, not specific to servlets. The developer still shouldn't use any constructor in a servlet.

You'll find lengthy explanations on the servlet lifecycle by googling for "servlet lifecycle". It shouldn't be necessary to provide a link for that - you can find those yourself easily.
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya Ok but i had one doubt is it the container after loading the servlet class create object of my servlet class and call init service destroy method.....?
 
shivendra tripathi
Ranch Hand
Posts: 263
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's correct. Methods inside servlet are callback methods. These will be called by container.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic