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.
|