In a web application with multiple servlets needing a shared resource, where should this resource be initialized?
- In a Servlet class constructor
- In the contextInitialized() method of ServletContextListener
- In the doGet() method of each servlet
- In the init() method of each servlet
For a shared resource across multiple servlets, it's best to initialize it in the contextInitialized() method of a ServletContextListener, ensuring it's available when the application starts.
Loading...
Related Quiz
- The __________ method of AsyncContext allows for manually controlling the timeout of an asynchronous operation.
- At which stage in the filter lifecycle can you perform actions based on the initialization parameters?
- How is a servlet configured in a web application?
- In a scenario where sensitive data is transmitted, which protocol should a servlet use to ensure data security?
- What is the impact of calling request.getParameter() after request.getInputStream() or request.getReader() in a servlet?