Easiest way to supply a Java webapp with lists of email lists
I'm renovating a legacy Java webapp ( servlets and JSPs ) I inherited. The webapp sends email and it uses about 12 lists of email addresses. The email addresses are hard coded into the webapp. Naturally, I want to put those lists of email addresses into a file and have the webapp read them in.
In the old days I would put those lists into a *.properties file in the webapp root directory.
I'm guessing Properties objects and *.propertie files is not the modern Java way to do this.
One choice I have is to put each email list into the web.xml as a <context-param>
, with the <param-value>
being a comma separated list of email addresses. I would then retrieve each list, by name, with context.getInitParameter() and then write a function to tokenize the emails and put each list into an ArrayList. My intuition tells me that is more messy than it has to be.
I would like my config file to be non-tech user friendly like a properties file, with comments, white space,key-value pairs, ie
########################################
## This file lists the email lists
#########################################
customerList = joeblow@gmail.com,sara@yahoo.com
managerList = jack@biz.com,jane@bigorg.gov
##########################################
## end of file
##########################################
Such a file would contain 12 such lists with about 10 different email addresses
I know how to use the Properties class to find such a file inside of a WAR and load it into a properties object very easily.
The problem comes in how to elegantly get each of those 12 lists out of the properties object, tokenized and into an individual ArrayList(with a named reference)
Am I right in assuming that the Prooperties class has been made obsolete by the modern collections? Im guessing the way to go is to use the Scanner class to read and tokenize the file into a Map, with each key being the name of an email list and each value being an ArrayList of email addresses.
I'm not sure how I would put that all together with the type of file I described above.
Any suggestions.
My goal is to do this first in the easiest way and then in the most modern way ( I have a book on collections and generics, but I am still assimil开发者_开发百科ating it ).
Thanks in advance for any help or ideas
Steve
The trendy answer is to use the JSON format, but if a .properties file works for your use case, go for it. Avoid storing it in the web.xml as your data is larger that the standard key value parameter.
This java json lib that has some upvotes. https://stackoverflow.com/questions/338586/a-better-java-json-library/785066#785066
精彩评论