File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need clarification on Properties file in a java web application

 
shivang sarawagi
Ranch Hand
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 331
Python Ruby Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic