如何在同一个 JSP 中使用多个资源包?
<fmt:setBundle> 标记用于加载资源包并将它存储在指定的范围变量或包配置变量中。
属性
<fmt:setBundle> 标记有如下属性 -
| 属性 | 描述 | 必需 | 默认 |
|---|---|---|---|
| basename | 作为有作用域或配置变量显示的资源包系列的基本名称 | 是 | 无 |
| var | 存储新包的变量名称 | 否 | 替换默认 |
| scope | 存储新包的变量的作用域 | 否 | 页面 |
示例
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/fmt" prefix = "fmt" %>
<html>
<head>
<title>JSTL fmt:setBundle Tag</title>
</head>
<body>
<fmt:setLocale value = "en"/>
<fmt:setBundle basename = "com.tutorialspoint.Example" var = "lang"/>
<fmt:message key = "count.one" bundle = "${lang}"/><br/>
<fmt:message key = "count.two" bundle = "${lang}"/><br/>
<fmt:message key = "count.three" bundle = "${lang}"/><br/>
</body>
</html>以上代码将生成以下结果 -
One Two Three
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP