11 What is the Use Of Servlet Config in Web.xml File

Опубликовано: 16 Октябрь 2024
на канале: Sameer's Code Room
1,991
12

• It is used to get configuration information from web.xml file.
• If the configuration information is modified from the web.xml file, we don't need to change the servlet.
E.g. String str = config.getInitParameter("name")

Advantage of ServletConfig
• The core advantage of ServletConfig is that you don't need to edit the servlet file if information is modified from the web.xml file.
How to get the object of ServletConfig
• getServletConfig() method of Servlet interface returns the object of ServletConfig.

Usage of ServletConfig
If any specific content is modified from time to time. you can manage the Web application easily without modifying servlet through editing the value in web.xml
E.g. ServletConfig config=getServletConfig();

Methods of ServletConfig interface
1. public String getInitParameter(String name):Returns the parameter value for the specified parameter name.
2. public Enumeration getInitParameterNames():Returns an enumeration of all the initialization parameter names.
3. public String getServletName():Returns the name of the servlet.
4. public ServletContext getServletContext():Returns an object of ServletContext

Material Source: Internet