Accessing ServletContext outside of a servlet

前端 未结 4 1207
长发绾君心
长发绾君心 2021-01-03 05:26

I wonder if anyone can advise on a Java webapp question?

I have a set standard Java class which has methods to set and get values of a property file. These methods a

4条回答
  •  失恋的感觉
    2021-01-03 05:44

    You could always store your settings in a different place than the Servlet Context, say a set of static variables on a configuration class. Then the ServletContextListener could set those variables on startup, and any other code can access those statics, regardless of whether they have access to the ServletContext itself or not.

提交回复
热议问题