在tomcat上获取变量的描述

时间:2015-07-31 18:20:52

标签: java xml tomcat

我在context.xml上设置了一些带有描述的变量。

<Environment
name="var"
description="description"
type="java.lang.String"
/>

我用以下内容阅读:

variable = (String) new InitialContext().lookup("java:comp/env/var");

如何获取变量的值描述?

1 个答案:

答案 0 :(得分:0)

Description attribute is there only for documentation purposes.

You should use value attribute to assign a value to the environment variable:

 <Context>
    <Environment name="yourVariable" 
                 value="yourValue" 
                 type="java.lang.String" 
                 description="this assigns yourValue to yourVariable" /> 
 </Context>

This way, when you do

String variable = (String) new InitialContext().lookup("java:comp/env/yourVariable");

variable will contain string "yourValue".