Forums Register Login

need clarification on Properties file in a java web application

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Thanks for the reply Sumit, so if I add the string data to an array that means it will add to the heap size?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
Danger, 10,000 volts, very electic .... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1305 times.
Similar Threads
can I define two property files in a web application
Connect to MSSQL Server
Need Help in Encryption
How Derby Store data
Properties file path hard coded
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:57:05.