• 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

accessing property file in servlet

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody..
i need to access property file in my servlet.

What i wanted to know was can we access a bean object for a key tthrough property file.

Say example if i have a bean userBean having attributes as

String name
String address
Int phoneNmbr

well now i want to store all these infomation against an USERID as key for these information in the property file.
the problem is how can i store all these values against USERID as key? because what i presume the value for key would be a single
String message. Not that i can get name , address,or telephone number separately for a same key.


What is going in my mind is that i can store like this in property file

2001 = Rohit,Street number 5 ABCD, 2828282;

and on fetching in servlet..i can break the String whereever i get comma. in this way i will get the required attributes for userBean and then i can create the key value pair for hashmap. but i don't know if this is a correct one method.

My Requirement in application
what i wanted in my application was that i would read the property file and fetch information against the USERID as key and create a hashmap where again the key is the USERID and value is userBean object which has the name , address, telephone number defined in the property file against the same USERID.

Is is it posssible in way..or some other way..
if in any way it can be implemented through property file , please suggest me the way.

i know i can store all these things in a database also ..but that is currently avoided and i want it to implement through property file.
Thanks.
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The userBean object can be serialized and stored as a file. Maybe you can use the "2001.ser" (the corresponding user id) as the filename. Later when you need the values corresponding to 2001, you can deserialize this file and create the userBean object. That directly gives you the Object to put on the map...

Here's an example for Serializing an object
 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okey..just correct me if i am wrong .....but in this case what i guess is i need to prepare a file for each object.
so if i have say 500 objects , i will have to create 500 files.

if that is the case ...i thing it will be a little heavy from performance point of view.
Expecting your opinion.
Thanks
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using a property file for what appears to be a job for a database?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying to use Property files for anything more complex than a name/value pair leads to confusion. You should have seen the mess in early JRun servlet engines before XML was adopted for configuration.

XML has many advantages, easy to read, can be written with a text editor, and mainly - its eXtensible. Since it is extensible, I can add new configuration parameters to my servlets without breaking anything.

Bill
 
Grow a forest with seedballs and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic