How can I read context parameter/web.xml values in a non-servlet java file?

后端 未结 5 1166
长发绾君心
长发绾君心 2020-12-28 17:46

I\'ve got a regular java file that I use to update and query a mysql database but I need to take configurable options in that file (like host name, password, etc) and put it

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-28 18:31

    You could use context-parameters in your web.xml and a javax.servlet.ServletContextListener to populate some static fields.

    In you normal java class you read this this static fields.

    
    
    ...
    
        Prameter
        myParam
        123456790
    
    ...
    
    

    You can access this context parameter with ServletContext.getInitParameter

提交回复
热议问题