Can we define constructors in Servlet?

Answer Posted / vivekanand prasad

The init() method creates and loads the servlet.But the servlet instance is first created through the constructor (done by Servlet container). We cannot write constructors of a servlet class with arguments in servlet (It will throw Exception). So, They provided a init() method that accepts an ServletConfig object as an argument.ServletConfig object supplies a servlet with information about its initialization (init) parameters.Servlet class cannot declare a constructor with ServletConfig object as a argument and cannot access ServletConfig object.

Is This Answer Correct ?    20 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

the same information whether it will connect to the database or it will be used previous information?

560


If your ui seems to freeze periodically, what might be a likely reason?

535


What is the difference between long.class and long.type?

552


What is the diffrence between a local-tx-datasource and a xa-datasource? Can you use transactions in both?

562


What is a policy?

1760






What is TL and its use?

1982


What is scalable, portability in the view of J2EE?

1865


Describe, in general, how java's garbage collector works?

528


Difference between swing and awt?

593


Why a component architecture for the java platform?

565


What is the difference between the session.get() method and the session.load() method?

591


What are the benefits of detached objects?

577


wahts is mean by dynavalidatorform in struts/

1557


What is abstract schema?

546


How are the elements of a cardlayout organized?

587