tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Juha Laiho <Juha.La...@iki.fi>
Subject Re: Problem Reading Property files
Date Tue, 26 May 2009 18:34:45 GMT
john S wrote:
> Actually, I am not sure where to place and configure the property
> files (*SERVLET ARGS*) in tomcat.

If it's ok for you to have the files deployed along with your application,
then I'd like to propose the following:
Place the files within /WEB-INF/ directory in your web application.
You could also create a subdirectory within /WEB-INF/ to contain
just these files, such as /WEB-INF/config/ .

Then read the files with getResourceAsStream method of ServletContext,
and process the stream to get the data you need. This way is specified
by the Servlet specification, so is portable across different containers.


Files places within /WEB-INF/ cannot be accessed by direct browser
requests, so they are safe from prying eyes.

The other way would be to place the configuration files outside
your web application. For this you'll likely want to split the
"root" directory for the files from the file names (and possibly
directory hierarchy underneath the "root") so that the placement
underneath the "root" is dictated by the application, but the "root"
location is set from outside the application. For this there is no
standard way, but you could use a Java system property (specified
with "-Dprop_name=value" on the JVM command line), or Tomcat context
parameters, to set the root directory. The placement underneath the
root would still be as it is now. Then in your code you'd concatenate
the "root" location with the file path/name from web.xml and process
the files as such.

-- 
..Juha

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message