Answers for Servlets Online Test - Online Exam - Online Quiz - Mock Test
←Go Back to Online Practice TestQues. I have a web application on tomcat. Here many servlets open their own separate connection to database. To optimize this application, I decided to ask all servlet developers to use same db connection. I need to initialize this connection, before any servlet / jsp will be accessed. I got following suggestions from my developers. Which is the best way to do it? |
Option 1. Initialize connection in the servlet itself and save connection |
Option 2. Putting the connection in the webapps init parameter |
Option 3. Make the connection code in a filter for every servlet and save the connection. |
Option 4. Make the connection in a context listener and save it. |
Ans. Option 4 |
Please provide the reason below. The best provided reason will be displayed with your name(if you are logged-in) on website. |
Enter Reason |
Is it helpful?
Yes
No