• Post Reply Bookmark Topic Watch Topic
  • New Topic

ResourcBundle use in Servlets ?

 
Pawanpreet Singh
Ranch Hand
Posts: 264
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have some code in servlet

Locale locale = Locale.getDefault();

ResourceBundle bundle = PropertyResourceBundle.getBundle("i18n.WelcomeBundle",locale,ClassLoader.getSystemClassLoader());

System.out.println("Welcome output :"+bundle.getString("Welcome"));
}

Where should i put i18n.WelcomeBundle_en_US.properties file so that i do not get MissingResourceException.


Thanks in advance.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try putting it in WEB-INF/classes.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am just confused over the following.

ResourceBundle bundle = PropertyResourceBundle.getBundle("i18n.WelcomeBundle",locale,ClassLoader.getSystemClassLoader());

Why to put system classloader as the classloader of choice.
Why not to use the other version of the same method without an classloader argument in it.
 
Sylven Yip
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put it in the WEB-INF/classes dir.
you can also put it in your package:
com.xxx.bundle.properties

and then get the bundle:
ResourceBundle.getBundle("com/xxx/bundle");
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!