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 pure servlet?

698


What is the difference between Servlets and Applets?

549


Why do we have servlet wrapper classes?

580


Hello, My project requirement is like I need to create a web page using MVC pattern. I hava a bean class, jsp page, servlet, service and dao. My jsp has two fields. One is dropdown list. The option values has to get populated from the database table. The other one is a text box and its value has to come from database table. As of now I have defined the fields in bean class, got the values from database using arraylists in dao class and I called this from service class. Can anyone please tell me the workflow of how the servlet will get this arraylist and populate the arraylist values as dropdown options in jsp page? Also I would like to know the role of bean class in MVC pattern? Thanks in advance!

1838


What is http servlet?

584






Explain the difference between servlet and cgi?

611


What are the kinds of http requests?

611


How do you configure a centralized error handler in servlets?

537


How do I use cookies to store session state on the client?

538


Write a servlet to upload file on server.

599


How to notify an object in session when session is invalidated or timed-out?

634


How do servlets work?

538


What are advantages of servlets over cgi?

632


Difference between GET and POST?

714


What do you mean by request dispatcher in servlet? Also explain its methods.

611