ReourceBundle类用来获取配置文件中的内容。
下面是两个配置文件内容:
res_zh_CN.properties

res_en_US.properties

publicclassDemo1 {
@Test
publicvoidfun1() {
ResourceBundle rb = ResourceBundle.getBundle("res", newLocale("zh", "CN"));
String username = rb.getString("msg.username");
String password = rb.getString("msg.password");
System.out.println(username);
System.out.println(password);
}
@Test
publicvoidfun2() {
ResourceBundle rb = ResourceBundle.getBundle("res", newLocale("en", "US"));
语法:ext.msg.alert(string title, string msg, function fn, object scope)。 msg * @param msg * @return */string hello(string msg)。 //string msg = string.format("finger id:{0} finger type: {1} tip position: {2}", f.id, f.type(), worldposition)。
String password = rb.getString("msg.password");
System.out.println(username);
System.out.println(password);
}
}
ResourceBundle的getBundle()方法需要两个参数:
l第一个参数:配置文件的基本名称
l第二个参数:Locale
getBundle()方法会通过两个参数来锁定配置文件!

其实页面国际化也是同一道理,只需要通过切换Locale来切换配置文件。我们写一个MessageUtils类,内部需要ResourceBundle的实例。
我们再写一个过滤器MessageFilter,它会通过参数创建Locale对象,传递给MessageUtils,然后在页面中使用MessageUtils来获取文本信息。
MessageUtils.java
MessageFilter.java
publicclassMessageFilter implementsFilter {
publicvoiddestroy() {
}
publicvoiddoFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throwsIOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
getparameter (string) 方法返回带有特定名称的参数。param变量是调用给定参数名的getparameter(string name)方法的结果,使用el表示如下:。(选择一项) a)string getparameter(string name) b)string[] getparameter(string name) c)string getparametervaluses(string name) d)string[] getparametervalues(string name)。
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-93009-12.html
涓滴之水成海洋
”易烊千玺朝我笑了笑