Is possible to have a constructor for a servlet?

Is possible to have a constructor for a servlet?

- Yes, it is possible to have a constructor for a servlet.

- However, it is not practiced usually.

- The operations with the constructor can be performed as usual just that it cannot be called explicitly using the ‘new’ keyword.

- This is implicitly handled by the servlet container.

- Thus, the container performs initialization as well as constructor functions.

Is possible to have a constructor for a servlet?

- The init() method creates and loads the servlet.

- However, the servlet instance creation of is handled by the servlet container which internally calls the constructor.

- The communication between the servlet and the servlet container is done through ServletConfig.

- ServletConfig is a servlet configuration object. It is used by a servlet container to pass information to a servlet during initialization.

- Servlet class cannot declare a constructor with ServletConfig object as a argument and cannot access ServletConfig object.
Difference between an Applet and a Servlet
Servlet and Applet - Applets are applications designed to be transmitted over the network and executed by Java compatible web browsers...
Servlet HTTP Tunneling - Define HTTP Tunneling?
Servlet HTTP Tunneling - The solution is to have them encapsulated in http or https and sent as an HttpRequest. Thus, masking other protocols as http requests is called HTTP Tunneling...
Difference between ServletConfig and ServletContext
Servlet ServletConfig and ServletContext - ServletConfig is a servlet configuration object. It is used by a servlet container to pass information to a servlet during initialization...
Post your comment