Tutorials4u.net Forum

Full Version: Read a Web Application property
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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");
Reference URL's