• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading Configuration information present in server.xml

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to place some configuration information for my application in server.xml. This is not the related to DB, but is general information which is for the whole application.

Can I do it and if yes, how can I retrieve the information from the Servlets (Java) Program.

-Vishnu
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you mean web.xml?

The server.xml file is not part of the servlet spec.
I assume you're using Tomcat, correct?
 
Vishnu Vardhan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben,

Thanks for the reply. I am using tomcat.

The reason I asked server.xml is that the user cannot modify the web.xml in my application as it is present in the war file.

I want some of the parameters to be filled in by the user.

Infact I am working with Tomcat and Sockets and not with the Database. So parameters like The socket pool size, socket port number and all I thought would be a good idea to place it in server.xml

Please correct me if I am wrong.

Vishnu
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're not wrong.
But... since this question is Tomcat specific, I'll move it to the Tomcat forum.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can set context init params in the Context Section of web.xml.
Search for "Context Parameters" on this page.
http://tomcat.apache.org/tomcat-5.5-doc/config/context.html

In Tomcat 5x and up, you can also place the Context tag in it's own file (called a context fragment file). These files can be shipped in the META-INF directory. When the app is deployed, the file gets written to tomcat/conf/Catalina/localhost/.

This could be useful to you because it would allow you to ship the app with default settings but also allow your users to edit the context fragment independently of the war file.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This feature also works in Tomcat 4, with one caveat: if you put a "myapp.xml" in TOMCAT_HOME/webapps AND you put "myapp.war" in TOMCAT_HOME/webapps, the myapp.xml wouldn't be seen and you'd lose the deplyment info. So I always put my actual WARs elsewhere. Which also means that multiple tomcats can share them if I do desire.

I make extensive use of overridable resource definitions myself. The web.xml holds the default definition and the Context xml file does the server-specific override (which in turn can be updated by the Tomcat manager webapp). The app retrieves the final value by a JNDI lookup via java:comp/env.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi:
I have the exact same issue.
Can you please let me know how do I retrive the context parameters specified in context.xml in my Servlet class.

It displays 'null' if I use the following lines of code.
config = getServletConfig();
String name = config.getInitParameter("companyName");
System.out.println("CompanyName = '" + name + "'");

Following is the entry in my context.xml
<Parameter name="companyName" value="My Company, Incorporated"
override="false"/>

Thanks,
Jyoti
reply
    Bookmark Topic Watch Topic
  • New Topic