esuslogo
 [To advertise Java(tm) Events here, contact joris@esus.com!]
banner

Java™
by example!






New @ Esus.com


  gb  In-house search engine for better results!

  gb  Get updates with the esus.com
newsletter!









  Home 
 Browse Categories 
 Ask a Java Question 
 Help 
  For Java Tips & Tricks, subscribe to the esus.com newsletter!
Search Java Q&A, Links, API's:   adv 

How do I read environment variables from a Servlet?
To get environmental values, servlets should use

 ServletConfig.getParameter(String param_name)

method. The ServletConfig object can be obtained either during any service method or at

 init()

time by calling

 getServletConfig()

.

The tricky and vendor-dependant part is defining the parameters.

With Apache/Jserv, you need to alter relevant zone.properties file and set

 servlet.<servlet-name>.initArgs=my_param=my_value



With Tomcat, go to $TOMCAT_HOME/webapps//WEB-INF/web.xml and have it include something like this:


 
<servlet>
<servlet-name>
my_servlet
</servlet-name>
<init-param>
<param-name>param_name</param-name>
<param-value>param_value</param-value>
</init-param>
</servlet>


You can have as many sections as you need parameters to be passed.

A good way is to pass to servlets only one parameter, which is the path to some configuration file, so that only this file needs to be changed to alter servlets behaviour, and access permissions for this file do not depend on access rights to other config files. This is important when people with different access rights have to manage several web apps running on the same servlet engine.


Further Information
Author of answer: hal9000

Comments
Comments to this answer are only viewable by members. Login or become a member!





Terms of Service | Privacy Policy | Contact

Copyright © 2000-2003 Esus.com - All Rights Reserved 
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. Esus.com is independent of Sun Microsystems, Inc. All other trademarks are the sole property of their respective owners.