Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Can we keep parameterised constructor in our servlet class?

user-image
Question ajoutée par Firoz Ahmad , Software Engineer , Tata Consultancy Service Limited
Date de publication: 2017/05/09
hardik sangani
par hardik sangani , Information Technology Analyst , Infosys Ltd

no , we cannot provide a parameterized constructor in servlet.As , in servlet consist of the container creates the object for servlet.

Hasan Mobarak
par Hasan Mobarak , Software Engineer (Java) , Fakir Knitwear's ltd

No.Servlet instances created by Servlet container, it Create no argument constractor. 

Gulshan Kumar
par Gulshan Kumar , Senior Software Developer , Cognizant - India

No, in servlet every instance is created by the given container via reflection api.

No, Servlet instances are created by the container, and they expect to find a public, no-arg constructor (the default constructor).

sundar yannabathula ys
par sundar yannabathula ys , Software Engineer , Infosys Technologies Limited

no! we cannot provide a parameterized constructor in servlet.The servlet container creates the object for sevrlet.The container will create the object based on Class.forName(String classname). we can create an object to a class using Class.forName(), if the class contains default constructor only.since the container uses the Class.forName() code in creating object, we do not write parameterized constructor as part out servlet. Even though if we want to write parameterized constructor, we have call the constructor from service()method!

Vishal Patel
par Vishal Patel , Java developer , Open Dox Technology Indore

yes we keep parameterised constructor in our servlet class.

sriramjee Alluri
par sriramjee Alluri , Software Engineer , BMW AG

No we can't use paramererized constructor

 

7down voteaccepted

No.

Servlet instances are created by the container via reflection, and they expect to find a public, no-arg constructor (the default constructor).

To configure your servlet, use servlet parameters specified in the web.xml file. These are passed to your servlet's init() method.