写一个工具类:
package jsfdb.model;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ModelUtils {
//注意如何访问资源属性文件的位置
public static final String RESOURCES= ModelUtils.class.getPackage().getName() + ".res.ModelResources";
private static ResourceBundle resources;
public static void log(Throwable x) {
Logger.global.log(Level.SEVERE, x.getMessage(), x);
}
public static synchronized ResourceBundle getResources() {
if (resources == null)
try {
resources = ResourceBundle.getBundle(RESOURCES);
} catch (MissingResourceException x) {
log(x);
throw new InternalError(x.getMessage());
}
return resources;
}
public static String getResource(String key) {
return getResources().getString(key);
}
}
在JSP中调用:
out.println("窗口标题="+s2+"
");
out.println("页面标题="+s3+"
");
out.println(ModelUtils.RESOURCES);
%>
运行结果:
窗口标题=JSF测试
页面标题=请填写下列的信息
jsfdb.model.res.ModelResources
附:ModelResources_zh_CN.properties
indexWindowTitle=JSF\u6d4b\u8bd5
indexPageTitle=\u8bf7\u586b\u5199\u4e0b\u5217\u7684\u4fe1\u606f
↑返回目录
前一篇: java统计当前在线人数
后一篇: rm播放器与jsp