aspose file tools*
The moose likes Servlets and the fly likes need clarification on Properties file in a java web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "need clarification on Properties file in a java web application" Watch "need clarification on Properties file in a java web application" New topic
Author

need clarification on Properties file in a java web application

shivang sarawagi
Ranch Hand

Joined: Jun 19, 2008
Posts: 148
I have a situation suppose I want to display hundreds of lines of string data in a jsp page based on some logic. So where do I save loads of string data in a String array, database or the property file?

I have used properties file in a web application before to load the database properties and other stuff.
But can anyone specifically tell me what are the properties files?
When to store data in the db & when to go for properties files?


Thanks
Sumit Bisht
Ranch Hand

Joined: Jul 02, 2008
Posts: 329

Any data you need to persist is best kept in database, especially when it can scale at large amounts .
If you have the same data/information that is not dependent upon user but upon some site-wide logic such as language used in site contents, then properties files are the best place to display that information.
To use property files without involving any specific framework, I'd advise you go through internationalization exercises.
And lastly, anything you need quickly from the server without involving an I/O or database hit, needs to be either cached or saved in the memory which is where arrays belong.
Generally properties files are located at the context root of the application, but you are free to choose where they are actually located.
shivang sarawagi
Ranch Hand

Joined: Jun 19, 2008
Posts: 148
Thanks for the reply Sumit, so if I add the string data to an array that means it will add to the heap size?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42639
    
  65
I wouldn't worry about memory consumption. "Hundreds of lines of string data" is a negligible amount of data.

Generally properties files are located at the context root of the application, but you are free to choose where they are actually located.

Not really. If you want to use the properties via Java's built-in I18N mechanism then they need to be in the classpath - either in WEB-INF/classes or in a jar file in WEB-INF/lib.


Ping & DNS - my free Android networking tools app
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Ulf Dittmer wrote:
Generally properties files are located at the context root of the application, but you are free to choose where they are actually located.

Not really. If you want to use the properties via Java's built-in I18N mechanism then they need to be in the classpath - either in WEB-INF/classes or in a jar file in WEB-INF/lib.

That's true if you are using the class loader to load the properties. If you are using the properties methods on the ServletContext, the file can be located anywhere within the web app, usually under WEB-INF to prevent it from being served accidentally.

Putting a properties file in the root of the web app isn't a great idea for security.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need clarification on Properties file in a java web application