aspose file tools*
The moose likes Servlets and the fly likes How does the servlet class object get loaded? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How does the servlet class object get loaded?" Watch "How does the servlet class object get loaded?" New topic
Author

How does the servlet class object get loaded?

santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
Dear all

If we define a constructer for a servlet class then how the container will create the object for that servlet class....


Creativity is nothing but Breaking Rules
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42951
    
  72
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

Joined: Apr 06, 2009
Posts: 296
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
Marshal

Joined: Mar 22, 2005
Posts: 42951
    
  72
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

Joined: Apr 06, 2009
Posts: 296
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

Joined: Aug 26, 2008
Posts: 263
That's correct. Methods inside servlet are callback methods. These will be called by container.


SCJP 1.5(97%) My Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How does the servlet class object get loaded?