How to get context-param value in web.xml

<context-param> is the static parameter and defined in web.xml file. We often use it to store some data, that does not change frequently. For example, we store the path of the configuration file, store email addresses, and so on.

web.xml
<context-param>
    <param-name>configFilePath</param-name>
    <param-value>/app/config.xml</param-value>
</context-param>

Using the following code in either a JSP or Servlet to get the above configFilePath context param value:

String value = getServletContext().getInitParameter("configFilePath");
System.out.print(value); // /app/config.xml

0 0 vote
Article Rating
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x