Getting context initialization parameters in JSP

Context initialization parameters are parameters defined in the web.xml deployment descriptor and are available to all servlets of your webapplication.

web.xml example:

<?xml version="1.0" encoding="ISO-8859-1"?>
 
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
 
<web-app>
   <context-param>
      <param-name>name1</param-name>
      <param-value>value1</param-value>
   </context-param>
   <context-param>
      <param-name>name2</param-name>
      <param-value>value2</param-value>
   </context-param>
</web-app>

getparams.jsp:

<%
   ServletContext context = config.getServletContext();
   String value1 = context.getInitParameter("name1");
   String value2 = context.getInitParameter("name2");
%>
 
Value of name1: <%=value1%><br>
Value of name2: <%=value2%>