Using properties in web.xml

后端 未结 3 949
一整个雨季
一整个雨季 2020-12-09 20:05

I would like to control the settings in web.xml and using different once for different environments.

Is it possible to use a property, from a property file on classp

3条回答
  •  眼角桃花
    2020-12-09 20:46

    No. However you can pass the properties file in and read from it at runtime.

    
        propfile
        myprop.properties
    
    

    It is then trivial to load the property at runtime if you have access to the servlet.

    Properties properties = new Properties();
    GenericServlet theServlet = ...;
    String propertyFileName = theServlet.getInitParameter("propfile");
    properties.load(getClass().getClassLoader().getResourceAsStream(propertyFileName));
    Object myProperty = properties.get("myProperty");
    

提交回复
热议问题