xml - How can i get appropriate .properties file using servlet when i have multiple .properties file in web-inf folder? -
<param-name>language</param-name> <param-value>en</param-value> </context-param> <context-param> <param-name>country</param-name> <param-value>us</param-value> </context-param> <context-param> <param-name>language</param-name> <param-value>jp</param-value> </context-param> <context-param> <param-name>country</param-name> <param-value>jp</param-value> </context-param>
this web.xml file code.
servletcontext app = getservletcontext(); localelang = app.getinitparameter("language"); localecountry = app.getinitparameter("country");
this jsp code i'm accessing properties files based on language , country. i.e., when lang en , country need access en_us.properties file , when lang jp , country jp need access jp_jp.properties file when have 100 properties file how can access properties file based on appropriate lang , country?
rather directly accessing properties files should consider using resourcebundle
mechanism, designed precisely situation. put properties files in web-inf/classes
instead of in web-inf
, , name them common prefix
messages.properties messages_en.properties messages_en_gb.properties messages_jp.properties
use resourcebundle.getbundle("messages", new locale(localelang, localecountry))
, pull properties messages_lang_country.properties
when exist in there, , fall messages_lang.properties
, messages.properties
if necessary.
Comments
Post a Comment