Jump to Real's How-to Main page

Read a Web Application property

Web Application properties are defined in the WEB-INF/web.xml deployment descriptor (in between the <webapp> </webapp> tag)
<env-entry>
    <env-entry-name>docPath</env-entry-name>
    <env-entry-value>c:/doc/doc1</env-entry-value>
    <env-entry-type>java.lang.String</env-entry-type>
</env-entry>

<env-entry>
    <env-entry-name>docUser</env-entry-name>
    <env-entry-value>net1</env-entry-value>
    <env-entry-type>java.lang.String</env-entry-type>
</env-entry>

Then from your JSP or Servlet,

Context env = (Context) new InitialContext().lookup("java:comp/env");
String docBase = (String) env.lookup("docPath");
String docBaseUser = (String) env.lookup("docUser");

If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]