Ould Abba
Ould Abba

Reputation: 843

Dynamically set context-param in tomcat webapp?

I have webapp deployed on tomcat_5.0.28, Linux.

my app is multi users and profiles (user can be admin or just simple user).

In my web.xml I have these lines

...
<web-app>
    <display-name>my-app</display-name>
    <context-param>
        <param-name>configFileName</param-name>
        <param-value>/WEB-INF/my-app-config.xml</param-value>
    </context-param>
    ...

How to set the value of the param configFileName at user login according to his profile

Upvotes: 0

Views: 2771

Answers (1)

km1
km1

Reputation: 2443

If you can use the param value as a template

 <param-name>configFileName</param-name>
 <param-value>/WEB-INF/my-app-config-{username}.xml</param-value>

Then you jsp can be something like this

 String userName = request.getRemoteUser()
 String temp = context.getInitParameter("configFileName");
 String fileName = temp.replace("{username}", userName);

Upvotes: 1

Related Questions