Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question for SCWCD.  RSS feed

 
Sumit Bansal
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,

Somebody might have asked this question before me and many of you might have known the answer. So please share it

It is a simple(may be stupid) question on Servlet.
At last servlet is a class and every class has its constructor. So Container must be calling that constructor in case of servlet for us.

Is that constructor really exists?

But what is in that constructor?

What would happen if we write our own constructor in a servlet?

Thank you,

Sumit
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like any java classes, servlets also have constructors. If you don't write one, there will still be the default constructor. You must have a no-argument constructor, because the container needs it to instanciate it.
You're not supposed to do anything in the constructor. Initialization should be done in the "init" method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!