位置:首页 » 文章/教程分享 » JSTL fmt:setBundle标签

<fmt:setBundle>标签是用来加载资源包并将其存储在指定的范围变量或包配置变量。

属性:

<fmt:setBundle>标签具有以下属性:

属性 描述 必须 默认
basename 资源包家族公开作用域或配置变量的基本名称 Yes None
var 变量名称用来存储新包 No Replace default
scope 存储新的捆绑变量的范围 No Page

例子:


<%@ 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.codeinn.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