Read a Web Application propertyTag(s): Servlet/JSP


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");

blog comments powered by Disqus