web.xml Visual Editor: Environment Entries

Use the Environment Entries section to add, remove, and view the web application's environment variables. Application environment entries are initialization variables that are available throughout a web application. You can use them, for example, to validate the object's type.

You access application environment variables in the java:comp/env context through a JNDI lookup, unlike context parameters, which you access via a ServletContext object. So, you would extract the value of an application environment variable as shown in Example: Extracting the value of an application environment variable.

Extracting the value of an application environment variable

InitialContext context = new InitialContext();
String header = (String) context.lookup("java:comp/env/headerPage");

The JNDI lookup method expects the type specified by the env-entry-type element and throws an exception if the returned value is not of that type.

To declare an application environment variable, 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 an environment entry is referred to in the web application.

In the Visual Editor, click References at the top of the editor to open the References section, then click the Environment Entries header to open the Environment Entries section.

Click Add to define an environment entry element with the following properties:

Element Description

Entry Name

Specifies the variable's name, such as headerPage.

Entry Type

Specifies the variable's name for validation, such as java.lang.String.

Entry Value

Specifies the parameter's value, such as mypages/header-0034.html.

Description

Specifies a description, such as Header Page for Travel Agency Application.



Related Topics

Developing Applications with NetBeans IDE,

Developing Applications with NetBeans IDE,

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.