小白教程
所有教程
关于
Search
172.70.126.42
172.70.126.42
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Jstl format bundle tag”的源代码
本页内容
上一节:
Jstl_format_parsedate_tag
下一节:
Jstl_format_setlocale_tag
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:<fmt:bundle>}}[[Category:jsp jstl|19]] = <fmt:bundle> 标签 = [[jsp jstl|JSP 标准标签库]] <fmt:bundle>标签将指定的资源束对出现在<fmt:bundle>标签中的<fmt:message>标签可用。这可以使您省去为每个<fmt:message>标签指定资源束的很多步骤。 举例来说,下面的两个<fmt:bundle>块将产生同样的输出: <sample title="" desc="" lang="jsp" hererun="1"> <fmt:bundle basename="com.xiaobai.Example"> <fmt:message key="count.one"/> </fmt:bundle> <fmt:bundle basename="com.xiaobai.Example" prefix="count."> <fmt:message key="title"/> </fmt:bundle> </sample> === 语法格式 === <sample title="" desc="" lang="jsp" hererun="1"> <fmt:bundle baseName="<string>" prefix="<string>"/> </sample> === 属性 === <fmt:bundle>标签有如下属性: {| class="table table-striped table-hover" ! '''属性''' ! '''描述''' ! '''是否必要''' ! '''默认值''' |- | basename | 指定被载入的资源束的基础名称 | 是 | 无 |- | prefix | 指定<fmt:message>标签key属性的前缀 | 否 | 无 |} == 程序示例 == 资源束包含区域特定对象。资源束包含键值对。当您的程序需要区域特定资源时,可以将所有的关键词对所有的locale共享,但是也可以为locale指定转换后的值。资源束可以帮助提供指定给locale的内容。 一个Java资源束文件包含一系列的键值对。我们所关注的方法涉及到创建继承自java.util.ListResourceBundle 类的已编译Java类。您必须编译这些类然后放在您的Web应用程序的CLASSPATH中。 让我们来定义一个默认的资源束: <sample title="" desc="" lang="jsp" hererun="1"> package com.xiaobai; 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"}, }; } </sample> 编译以上文件为 Example.class,然后放在Web应用程序的CLASSPATH能找到的地方。现在可以使用JSTL来显示这三个数字了,就像这样: <sample title="" desc="" lang="jsp" hererun="1"> <%@ 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:bundle 标签</title> </head> <body> <fmt:bundle basename="com.xiaobai.Example" prefix="count."> <fmt:message key="one"/><br/> <fmt:message key="two"/><br/> <fmt:message key="three"/><br/> </fmt:bundle> </body> </html> </sample> 运行结果如下: <sample title="" desc="" lang="jsp" hererun="1"> One Two Three </sample> 将其改为无prefix属性: <sample title="" desc="" lang="jsp" hererun="1"> <%@ 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:bundle 标签</title> </head> <body> <fmt:bundle basename="com.xiaobai.Example"> <fmt:message key="count.one"/><br/> <fmt:message key="count.two"/><br/> <fmt:message key="count.three"/><br/> </fmt:bundle> </body> </html> </sample> 运行结果如下: <sample title="" desc="" lang="jsp" hererun="1"> One Two Three </sample> 可以查看[[jstl format setlocale tag|<fmt:setLocale>]]和[[jstl format setbundle tag|<fmt:setBundle>]]来获取更多信息。 [[jsp jstl|JSP 标准标签库]]
返回至“
Jstl format bundle tag
”。
上一节:
Jstl_format_parsedate_tag
下一节:
Jstl_format_setlocale_tag