Accessing server.xml config settings in a web application

H

hitectahir

Hi,

I want to use the settings I make in server.xml for Tomcat
configuration in my web application as well. Is there some way I can
use the values stored in server.xml directly through my web application
code instead of having to store them in another properties file?

Regards
Tahir.
 
T

Tom Dyess

Hi,

I want to use the settings I make in server.xml for Tomcat
configuration in my web application as well. Is there some way I can
use the values stored in server.xml directly through my web application
code instead of having to store them in another properties file?

Regards
Tahir.

Is context-param what you are looking for?

<context-param>
<param-name>server</param-name>
<param-value>192.168.1.27</param-value>
</context-param>
 
L

littlewild

To be more specific, you can set the context params in your serverl.xml
and then retrieve them by:
1. Get the ServletConfig object using Servlet.getServletConfig()
2. Get the ServletContext object using
ServletConfig.getServletContext()
3. Get the parameter using ServletContext.getAttribute()

Since each app server will only have one ServletContext object, the
values are shared by all web application. If you want to make the
values specific to just one servlet, you can specify the parameters
inside your application's web.xml as:
<servlet>
......
<init-param>
<param-name>foo</param-name>
<param-value>bar</param-value>
</init-param>
</servlet>

You can then retrive the values using ServletConfig.getInitParameter().

Hope it helps.
 
M

Malte

Tom said:
Is context-param what you are looking for?

<context-param>
<param-name>server</param-name>
<param-value>192.168.1.27</param-value>
</context-param>

I am not sure, but wouldn't program parms be better written into web.xml?
 
H

hitectahir

Thanks for the response, but I actually want to retrieve the properties
that have been set for the connectors. More specifically, my web
application supports both http and https communication. However, over
http, it uses the same keystore being used by the SSL Connector to
authenticate with the client. Currently, I have to put the path to the
keystore file in both server.xml and a separate properties file. Is
there some way I can get this path directly from server.xml instead of
having to put it in another file as well?

Thanks
Tahir.
 
J

Juha Laiho

(e-mail address removed) said:
Thanks for the response, but I actually want to retrieve the properties
that have been set for the connectors. More specifically, my web
application supports both http and https communication. However, over
http, it uses the same keystore being used by the SSL Connector to
authenticate with the client. Currently, I have to put the path to the
keystore file in both server.xml and a separate properties file. Is
there some way I can get this path directly from server.xml instead of
having to put it in another file as well?

I don't think you can (easily) get to that information:

As I see it, providing webapp access to the _server_ keystore could
compromise the security/integrity of the server (of course a non-issue
if the server is just running a single application, but it is a design
issue as the server is designed to simultaneously run several
independent webapps).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top