<fmt:setBundle> 標籤
<fmt:setBundle>標籤用來載入一個資源束,然後將它存儲在作用域中已命名的變數或bundle配置變數中。
語法格式
<fmt:setBundle baseName="<string>" var="<string>" scope="<string>"/>
屬性
<fmt:setBundle>標籤有如下屬性:
屬性 | 描述 | 是否必要 | 默認值 |
---|---|---|---|
basename | 資源束家族基礎名稱,暴露給作用域變數或配置變數 | 是 | 無 |
var | 存儲新資源束的變數 | 否 | Replace default |
scope | 變數的作用域 | 否 | Page |
實例演示
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ 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 標籤</title> </head> <body> <fmt:setLocale value="en"/> <fmt:setBundle basename="com.zaixian.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