How to store string values in context.xml

后端 未结 2 1159
醉话见心
醉话见心 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 01:49

    You can configure named values that will be made visible to the web application as servlet context initialization parameters by nesting elements inside this element. For example, you can create an initialization parameter like this:

     
          ...
         
           ...
     
    
       This is equivalent to the inclusion of the following element in the web application deployment descriptor (/WEB-INF/web.xml):
    
    
    
     
           companyName
           My Company, Incorporated
     
    

    Your java code looks like this

     ServletContext sc = getServletContext();  
    
     String companyName = sc.getInitParameter("companyName");  
    

    Please see the reference http://tomcat.apache.org/tomcat-7.0-doc/config/context.html

提交回复
热议问题