views:

117

answers:

2

I know it it is easy to read the context-param values from web.xml with a Servlet.

But is it possible to read the value with a normal java class?

+4  A: 

You can perse web.xml (with something like dom4j), but I guess that's not your point - a context-param does not make any sense in a non-servlet environment.

I assume you want to obtain the value of an init parameter in a class in your web application that is not a servlet, but is, 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.

In case this is configuration that you can afford to make static - load it only once, on init() of a servlet.

Bozho
You are right about the scenario I am facing right now. Thanks!
Jay
A: 

If you have the Request object you can get the ServletContext from that and you can get the init parameters from the Context via the API.

EJP
I donot think i have the request object available.:(
Jay