Ashish Srivastava
Ashish Srivastava

Reputation: 99

Can i read context-param using a normal java class file form web.xml file

Web.xml

    <param-name>driver</param-name>
    <param-value>com.mysql.jdbc.Driver</param-value>
</context-param>
<context-param>
    <param-name>url</param-name>
    <param-value>jdbc:mysql:///gts_user</param-value>
</context-param>
<context-param>
    <param-name>user_name</param-name>
    <param-value>root</param-value>
</context-param>
<context-param>
    <param-name>password</param-name>
    <param-value>gts</param-value>
</context-param>

i want get all value from web.xml using a java class file

Upvotes: 2

Views: 3091

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279890

You'll be able to get access to all those context-param elements if you have access to the ServletContext. You have access to the ServletConfig in a number of places, namely, Servlet#init(..), Filter#init(..), and most of the listener types.

The method you are looking for is ServletContext#getInitParameterNames().

Otherwise, you will have to parse the web.xml yourself.

Upvotes: 2

Related Questions