• 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

need clarification on Properties file in a java web application

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 331
Python Ruby Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic