If a servlet needs to access a shared resource specified in the web application's context parameters, which approach should be used?
- Access the shared resource through the HttpSession object.
- Directly access the shared resource using the File class.
- Use a global variable within the servlet to store the shared resource.
- Utilize the ServletContext to retrieve the shared resource using getInitParameter().
To access a shared resource specified in the web application's context parameters, a servlet should use the ServletContext and the getInitParameter() method. This ensures proper retrieval of the shared resource.
Loading...
Related Quiz
- How does connection pooling in servlets optimize database interactions?
- How does a servlet container differentiate between authenticated and unauthenticated users?
- The __________ method of AsyncContext allows for manually controlling the timeout of an asynchronous operation.
- To retrieve all the parameter names sent in a request, you can use the __________ method of the HttpServletRequest object.
- In a situation where multiple asynchronous tasks are initiated by a servlet, how is the completion of these tasks managed?