How to store string values in context.xml

后端 未结 2 1161
醉话见心
醉话见心 2021-02-04 01:06

I\'d like to store connection URLs in a JNDI binding for my Tomcat application. Since Tomcat uses context.xml for JNDI resource defining, I need to figure out the p

2条回答
  •  迷失自我
    2021-02-04 02:12

    You can use an Environmenttag:

    
        
    
    

    And you can read it almost as you specified in the question:

    InitialContext initialContext = new InitialContext();
    Context environmentContext = (Context) initialContext.lookup("java:/comp/env");
    String connectionURL = (String) environmentContext.lookup("myConnectionURL");
    

    This is much the same as using a Parameter tag, but without the need for a ServletContext.

提交回复
热议问题