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

What methodology can be followed to store more number of objects in a remote server?

1999


How is an application exception handling is done using a servlet?

740


What is the process to implement doget and dopost methods?

714


What is http servlet?

777


How is the get () method different from the post() method?

719


What is cookies in servlet with example?

697


What do you mean by deployment descriptor?

740


What do you mean by servlet context?

789


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

825


What is difference between GenericServlet and HttpServlet?

745


What is the difference between using getSession(true) and getSession(false) methods?

788


Explains the differences between context.getrequestdispatcher() and request.getrequestdispatcher()?

740


How do we call one servlet from another servlet?

752


Why don't we write a constructor in a servlet?

780


Explain in brief the directory structure of a web application?

779