- JSP 基礎教程
- JSP - 首頁
- JSP - 概述
- JSP - 環境搭建
- JSP - 架構
- JSP - 生命週期
- JSP - 語法
- JSP - 指令
- JSP - 動作
- JSP - 隱式物件
- JSP - 客戶端請求
- JSP - 伺服器響應
- JSP - HTTP 狀態碼
- JSP - 表單處理
- JSP - 編寫過濾器
- JSP - 處理 Cookie
- JSP - 會話跟蹤
- JSP - 檔案上傳
- JSP - 處理日期
- JSP - 頁面重定向
- JSP - 訪問計數器
- JSP - 自動重新整理
- JSP - 傳送郵件
- 高階 JSP 教程
- JSP - 標準標籤庫
- JSP - 資料庫訪問
- JSP - XML 資料
- JSP - JavaBean
- JSP - 自定義標籤
- JSP - 表示式語言
- JSP - 異常處理
- JSP - 除錯
- JSP - 安全
- JSP - 國際化
- JSP 有用資源
- JSP - 問答
- JSP - 快速指南
- JSP - 有用資源
- JSP - 討論
JSTL - Core <fmt:setLocale> 標籤
<fmt:setLocale> 標籤用於將給定的區域設定儲存在區域設定配置變數中。
屬性
<fmt:setLocale> 標籤具有以下屬性:
| 屬性 | 描述 | 必填 | 預設值 |
|---|---|---|---|
| 值 | 指定一個兩部分程式碼,表示 ISO-639 語言程式碼和 ISO-3166 國家程式碼。 | 是 | en_US |
| variant | 瀏覽器特定的變體 | 否 | 無 |
| scope | 區域設定配置變數的作用域 | 否 | 頁面 |
示例
資源包包含特定於區域設定的物件。資源包包含鍵值對。當您的程式需要特定於區域設定的資源時,您將所有鍵都保留為所有區域設定的通用鍵,但您可以擁有特定於區域設定的翻譯值。資源包有助於提供特定於區域設定的內容。
Java 資源包檔案包含一系列鍵到字串的對映。我們關注的方法涉及建立擴充套件java.util.ListResourceBundle類的已編譯 Java 類。您必須編譯這些類檔案並使其可用於 Web 應用程式的類路徑。
讓我們定義一個預設的資源包,如下所示:
package com.tutorialspoint;
import java.util.ListResourceBundle;
public class Example_En extends ListResourceBundle {
public Object[][] getContents() {
return contents;
}
static final Object[][] contents = {
{"count.one", "One"},
{"count.two", "Two"},
{"count.three", "Three"},
};
}
現在讓我們再定義一個資源包,我們將用於西班牙語區域設定:
package com.tutorialspoint;
import java.util.ListResourceBundle;
public class Example_es_ES extends ListResourceBundle {
public Object[][] getContents() {
return contents;
}
static final Object[][] contents = {
{"count.one", "Uno"},
{"count.two", "Dos"},
{"count.three", "Tres"},
};
}
讓我們編譯上述類Example.class和Example_es_ES.class,並將它們放在 Web 應用程式的 CLASSPATH 中。現在,您可以使用以下 JSTL 標籤來顯示這三個數字,如下所示:
<%@ 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:setLocale Tag</title>
</head>
<body>
<fmt:bundle basename = "com.tutorialspoint.Example">
<fmt:message key = "count.one"/><br/>
<fmt:message key = "count.two"/><br/>
<fmt:message key = "count.three"/><br/>
</fmt:bundle>
<!-- Change the Locale -->
<fmt:setLocale value = "es_ES"/>
<fmt:bundle basename = "com.tutorialspoint.Example">
<fmt:message key = "count.one"/><br/>
<fmt:message key = "count.two"/><br/>
<fmt:message key = "count.three"/><br/>
</fmt:bundle>
</body>
</html>
以上程式碼將生成以下結果:
One Two Three Uno Dos Tres
檢視<fmt:bundle>和<setBundle>標籤以瞭解完整概念。
jsp_standard_tag_library.htm
廣告