web.xml Visual Editor: Context Parameters

See Also 

Use the Context Parameters section in the web.xml Visual Editor to add, remove, and view the web application's context parameters. Context parameters are initialization paramaters that are available throughout a web application. You can use them, for example, to provide configuration information to all servlets and JSP pages in a web application.

You can access context parameters in your code using the javax.servlet.ServletContext.getInitParameter() and javax.servlet.ServletContext.getInitParameterNames() methods, as illustrated below:

   ServletContext context = this.getServletContext();
   String mainPage = context.getInitParameter("mainPage");

If a company name changes frequently, you can define its value as a context parameter in the web.xml file instead of hard-coding it in all your JSP files and servlets. Then define and declare a listener that reads the value and stores it in the servlet context. Next, define and declare another listener that monitors changes to the name.

To declare a context parameter, you must register it in the web.xml file. When you do this, you provide information needed by the server to use the parameter. You tell the server which value should be returned when a context parameter is referred to in the web application.

You open the web.xml Visual Editor from the Projects window by expanding the Web Pages node, then the WEB-INF node, and then double-clicking the web.xml file. Click General at the top of the editor to open the General section, then click the Context Parameters header to open the Context Parameters section.

Click Add to define the context parameter element with the following properties:

See Also
About Deployment Descriptors
About Configuring Web Applications
Configuring Web Application Deployment Descriptors

Legal Notices