ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Can we keep parameterised constructor in our servlet class?

user-image
تم إضافة السؤال من قبل Firoz Ahmad , Software Engineer , Tata Consultancy Service Limited
تاريخ النشر: 2017/05/09
hardik sangani
من قبل 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
من قبل Hasan Mobarak , Software Engineer (Java) , Fakir Knitwear's ltd

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

Gulshan Kumar
من قبل 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
من قبل 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
من قبل Vishal Patel , Java developer , Open Dox Technology Indore

yes we keep parameterised constructor in our servlet class.

sriramjee Alluri
من قبل 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.