How to read context-param values โ€‹โ€‹from web.xml with normal Java class

I know that it is easy to read context-param values โ€‹โ€‹from web.xml using Servlet.

But is it possible to read the value using a regular java class?

+4
source share
2 answers

You can migrate web.xml (with something like dom4j ), but I think that is not your point - a context-param makes no sense in an environment without servlets.

I assume that you want to get the value of the init parameter in the class of your web application, which is not a servlet, but, say, a helper class.

You can - your entry point is always a servlet, so get the context-param value there and pass it as a method argument to the method you need.

If this is a configuration that you can allow static , load it only once on the servlet init() .

+4
source

If you have a Request object, you can get ServletContext from it, and you can get init parameters from context through the API.

0
source

All Articles