Can we define constructor in Servlet class?

Answer Posted / srikanth b

Yes, we can define constructor in Servlet class.
Constructor may be a Default Constructor or Parameterised
Constructor.
If we didn't write any constructor then the default
constructor will be executed. Because, to read init
parameters of a servlet we need servlet config object in the
life cycle of the servlet. Servlet config object object is
created after the execution of the constructor.

Is This Answer Correct ?    1 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the purpose of dispatcherservlet properties?

709


What is the use of httpservletresponsewrapper?

703


What is a java servlet?

759


Why is http protocol called as a stateless protocol?

729


Can servlet have a constructor ?

796


What do you mean by a filter and how does it work?

707


What is the workflow of a servlet?

890


Write all the phases defined in servlet life cycle?

759


What methods do you use in servlet - applet communication?

791


When Servlet is unloaded?

829


Is it possible to have a constructor inside the servlet?

735


How to get the path of servlet in the server?

719


How can we refresh automatically when new data has entered the database?

830


What are important features of Servlet 3?

800


What is a servlet engine?

737