< Prev
Next >



ServletConfig



In this article, we are going to understand how to read the servlet configurations using the ServletConfig object. These configurations are set in the deployment descriptor file, web.xml. The Servlet configuration could point to -

During the initialization of a Servlet, the Servlet Container uses a ServletConfig object to communicate with a Servlet and pass the configurations specific to it.


ServletConfig is an interface and it is a part of the Servlet API. The full path to import and access all the methods provided by ServletConfig is javax.servlet.ServletConfig.




ServletConfig methods


Let's take a look at the methods part of javax.servlet.ServletConfig interface.

Methods Description
String getInitParameter(String str) This method returns the value of a parameter named str .
Enumeration getParameterNames() This method returns all the names of the parameters associated with the servlet.
ServletContext getServletContext() This method returns a reference to the ServletContext.
ServletName getServletName() This method returns the name of the Servlet being executing.





Creating a webpage which calls the Servlet


We are creating a webpage which asks the user to click a button named Yes, let's read!, which when clicked will execute a Servlet to display the Servlet Configurations, such as -
Please subscribe our social media channels for notifications, we post a new article everyday.

Decodejava Google+ Page Decodejava Facebook Page  DecodeJava Twitter Page

Coming Next
-
C++ and Python

Ad2