tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Smith <>
Subject Re: Problem Reading Property files
Date Tue, 26 May 2009 21:34:11 GMT
Assuming you wrote this servlet, it would *really* help if you provided
relevant parts of your servlet where this file is read.  We're flying
blind here.

Normally the servlet would do something like this:

class MyServlet extends javax.servlet.http.HttpServlet {
    function init(ServletConfig sc) throws javax.servlet.ServletException {
        string properties_file_path = sc.getInitParameter( "loan.props" ) ;
        try {
            loanProps = new java.util.Properties() ;
sc.getServletContext().getResourceAsStream(properties_file_path) ) ;
            /* Do something with the properties object ... maybe make it
a class variable. */
        } catch ( fnfe) {
            throw new ServletException( "Could not configure.  Servlet
disabled.", fnfe) ;
    /* other methods here */

This may not be perfect, but it's enough to illustrate the idea.  With
the above, you should be able to declare the path to your properties in
the web.xml as servlet init-params.

I'm guessing iPlanet is doing something different.  What's posted above
is supported as part of the servlet spec.


john S wrote:
> I placed under WEB-INF itself. I created a directory called config adn
> placed the abc.props and abc.log under it.
> Whether i need to configure them in the web.xml? or should i remove it from
> there.
> Because wen i removed the init param, there is no change i am getting the
> same error......not able to find the abc.props or abc.log files
> Just want to know where should i specify them.
> On Tue, May 26, 2009 at 2:34 PM, Juha Laiho <> wrote:
>> 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:
>> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message