12 What Is the Use Of Servlet Context in Web.xml File

preview_player
Показать описание
ServletContext is created by the web container at time of deploying the project.
There is only one ServletContext object per web application.

Advantage of ServletContext
• Easy to maintain if any information is shared to all the servlet, it is better to make it available for all the servlet.

Usage of ServletContext
There can be a lot of usage of ServletContext object. Some of them are as follows:

1. The object of ServletContext provides an interface between the container and servlet.
4. The ServletContext object can be used to provide inter-application communication.

How to get the object of ServletContext interface
1. getServletContext() method of ServletConfig interface returns the object of ServletContext.
//We can get the ServletContext object from ServletConfig object
ServletContext context=getServletConfig().getServletContext();
2. getServletContext() method of GenericServlet class returns the object of ServletContext.
//Another way to get the ServletContext object
ServletContext application=getServletContext();

Material Source: Internet
Рекомендации по теме
Комментарии
Автор

Hi! May I ask if I can initialize a JSP page as a param-value, and if yes, how can I call it from the Servlet/JSP?

For context, I have header.jsp as ServletContext and I want to put it in all my pages.

Thank you!

elishafranciaplaton