Can we write a constructor for a Servlet class ? if yes how ?
if no why not ?

Answer Posted / tharun raj

yes, we can provide a constructor in servlet calss..
Webcontainer uses the similar code shown below for creating
servlet object for our servlet class

Class c=Class.forName("OurServlet");
Object o=c.newInstance();

this newInstance() method uses zero argument constructor
while creating object..

Is This Answer Correct ?    10 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is servlet thread safe?

525


how many jsp scripting elements are there and what are those?

543


What is Client-Server Computing?

1899


What do you mean by the servlet chaining?

549


Explain the difference between servletconfig and servletcontext in servlet?

577






What’s the difference between genericservlet and httpservlet?

534


Define the lifecycle for executing a jsp page.

597


Can we refresh servlet in client and server side automatically?

596


What is the use of java servlet api?

602


What exactly are the functions of servlet?

603


Tell the new features added in servletrequest interface i.e. Servlet 2.4

577


Differentiate between the get and post method

567


What are the life-cycle methods for a servlet?

557


What are the types of servlet?

671


What is pure servlet?

698