Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Can we keep parameterised constructor in our servlet class?

user-image
Question added by Firoz Ahmad , Software Engineer , Tata Consultancy Service Limited
Date Posted: 2017/05/09
hardik sangani
by 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
by Hasan Mobarak , Software Engineer (Java) , Fakir Knitwear's ltd

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

Gulshan Kumar
by 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
by 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
by Vishal Patel , Java developer , Open Dox Technology Indore

yes we keep parameterised constructor in our servlet class.

sriramjee Alluri
by 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.

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.