Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

.properties file

 
Lidia Cyc
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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 ]
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • 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
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic