Latest web development tutorials

<fmt:setBundle> 標籤

JSP 標準標籤庫 JSP標準標籤庫

<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.w3big.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

JSP 標準標籤庫 JSP標準標籤庫