如何在同一個 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