Accessing ServletContext outside of a servlet

前端 未结 4 1233
长发绾君心
长发绾君心 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:38

    ServletContext can be used within the context or boundaries of a servlet.

    You can store the variables in the jndi server that ships along with the app server and can use the initial context to get the variables from there.

    Also the classes that load the properties file, you can bundle in a jar and put that jar in the classpath of your server (you can refer to server startup script and put it in the classpath there).So when your server is loaded load a class with a static {} bloc inside it and refer to those properties file. You can then refer to this class directly as it is in server classpath.As regarding hard coding the path to properties file , you can store it in the jndi server.

提交回复
热议问题