• 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

.properties file

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i use a .properties file to load the database preferences into an object which connects to db. the object is used by a servlet, and therefor is found in $CATALINA_HOME/webapps/XYZ/WEB-INF/classes/ folder.
the .properties file should be stored in classpath, but on winxp machine nothing but putting it in the same .../classes folder works for me.
the problem is that .../classes folder is visible for everyone. of corse i can make servlet mappings to prevent a possibility to open the .properties file, but still, sounds bad to place a file with the full info regarding my db (including user : pass) in the folder visible to everyone.
what should i do?
10x
[ September 28, 2003: Message edited by: Cyc Lid ]
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The WEB-INF directory is not visible to anyone.
From the Servlet API Specification:

No file contained in the WEB-INF directory may be served directly to a client by the container.


HTH
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you put the .properties file in the WEB-INF folder or in any subfolder of the WEB-INF folder you can use the servletcontext to open the file. You would do something like:
stream = servletContext().getResourceAsStream("/WEB-INF/pathtofile/file.properties");
And I believe that returns an InpuStream so then you can do your typical
properties.load(stream);
And all should be fine.
Now, just to give other options, when working with Web Apps, Connection Pooling is a much better method for getting a connection to a database.
 
Lidia Cyc
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. i didn't say the file is in WEB-INF, it's in WEB-INF/classes, the folder where you put all your servlets classes, which IS the folder the cpntainer services for requests.
2. of course i'm using a connection pool, but it still needs some preferences to be initialized. i also use
getClass().getResourceAsStream(filename) as you said, which loads the properties file, but only if it's in WEB-INF/classes too...
any other ideas?
10X
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Cyc Lid:
1. i didn't say the file is in WEB-INF, it's in WEB-INF/classes, the folder where you put all your servlets classes, which IS the folder the container services for requests.


You don't get the point: WEB-INF is not a public node. /classes is in WEB-INF, so is not a public directory. It is used to put their contents available for the application class loader.


2. of course i'm using a connection pool, but it still needs some preferences to be initialized. i also use
getClass().getResourceAsStream(filename) as you said, which loads the properties file, but only if it's in WEB-INF/classes too...
any other ideas?
10X


If you read again Gregg's post you will notice he said:
servletContext().getResourceAsStream("/WEB-INF/pathtofile/file.properties");
nor getClass.getResourceAsStream(filename)
And if you really use connection pooling, you dont need any configuration file in the /classes directory, you can put the init values in the deployment descriptor.
HTH
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And if you really use connection pooling, you dont need any configuration file in the /classes directory, you can put the init values in the deployment descriptor.
I second that
 
reply
    Bookmark Topic Watch Topic
  • New Topic