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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *