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 parameters 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 shown in Example: Methods to access context parameters in code.
Methods to access context parameters in code
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.
In the Visual Editor, 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:
Element | Description |
---|---|
Param Name |
Specifies the parameter's name, such as |
Param Value |
Specifies the parameter's value, such as |
Description |
Specifies a description, such as |
Related Topics
Developing Applications with NetBeans IDE,
Developing Applications with NetBeans IDE,
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |