Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parameterized construcor in servlet?

 
Sandeep Bhandari
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what happens if I provide a parameterized constructor in servlet. Will the dynamic loader be able to load the servlet class and call the init/service/doGet/doPost method on it??
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How will the container know which parameter to pass ? You need a non-argument constructor, otherwise the servlet cannot be instanciated.
 
Vishal Matere
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you provide parameterised constructor to servlet then you HAVE to define NON-Parameterized constructor also because compiler mandates you to specify that.

However even after that only NON-parameterized constructor will be called to create new Servlet instance.

V
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic