Accessing server.xml config settings in a web application

Discussion in 'Java' started by hitectahir@hotmail.com, Mar 10, 2005.

  1. Guest

    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.
     
    , Mar 10, 2005
    #1
    1. Advertising

  2. Tom Dyess Guest

    <> wrote in message
    news:...
    > 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>

    --
    Tom Dyess
    OraclePower.com
     
    Tom Dyess, Mar 11, 2005
    #2
    1. Advertising

  3. Guest

    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.

    wrote:
    > 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.
     
    , Mar 11, 2005
    #3
  4. Malte Guest

    Tom Dyess wrote:
    > <> wrote in message
    > news:...
    >
    >>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>
    >


    I am not sure, but wouldn't program parms be better written into web.xml?
     
    Malte, Mar 11, 2005
    #4
  5. Guest

    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.

    wrote:
    > 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.
    >
    > wrote:
    > > 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.
     
    , Mar 11, 2005
    #5
  6. Juha Laiho Guest

    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).
    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)
     
    Juha Laiho, Mar 13, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QXVndXN0aW4gUHJhc2FubmEuIEo=?=

    Web.Config Get Config settings at runtime.

    =?Utf-8?B?QXVndXN0aW4gUHJhc2FubmEuIEo=?=, Feb 5, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,268
    Kevin Spencer
    Feb 6, 2004
  2. CSharpner
    Replies:
    0
    Views:
    1,047
    CSharpner
    Apr 9, 2007
  3. leeanne
    Replies:
    0
    Views:
    1,874
    leeanne
    Sep 24, 2008
  4. daveh551
    Replies:
    0
    Views:
    543
    daveh551
    Nov 29, 2008
  5. donet programmer
    Replies:
    3
    Views:
    1,552
    Gregory A. Beamer
    Nov 20, 2009
Loading...

Share This Page