Java ServletContext

前端 未结 5 803
遥遥无期
遥遥无期 2021-01-23 16:26

I have a JSP web site, not Spring MVC, and it has a config file web.xml.

There are a couple of settings within the web.xml file that I\'d like to get.

However, I

5条回答
  •  心在旅途
    2021-01-23 17:08

    Hmmm... I am assuming that once your web app is up then you are not going to make any change in the web.xml....

    Now what you can do is a create a servlet which loads on the startup and initialize a singleton class. You can use the following setting in your web.xml.

      
        
        XMLStartUp
        XMLStartUp
        com.test.servlets.XMLStartUp
        
          log4j-init-file
          WEB-INF/classes/log4j.properties
        
        0
      
    

    In tomcat if you set load-on-startup value 0, then it means that while loading it has got the highest priority. now in the servlets init method read all the init-parameters like this and set it in your singleton class.

    String dummy= getInitParameter("log4j-init-file");
    

提交回复
热议问题