fmt 国际化格式标签库(读取application.properties文件)
2014-06-05 10:10
429 查看
国际化格式标签库包括国际化,消息和数字日期格式化:
(1) 国际化:<fmt:setLocale> <fmt::requestEncoding>
如:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ page language="java" contentType="text/html; charset=gb2312" import="java.util.*"%>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<title>Insert title here</title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<c:set var="todayValue" value="<%=new Date() %>"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
中文-大陆:<fmt:setLocale value="zh"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:formatDate value="${todayValue}"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
中文-台湾<fmt:setLocale value="zh_tw"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:formatDate value="${todayValue}"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
中文-新加坡<fmt:setLocale value="zh_sg"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:formatDate value="${todayValue}"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
英文:<fmt:setLocale value="en"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:formatDate value="${todayValue}"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</html>
页面输出:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
中文-大陆: 2007-12-25
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
中文-台湾 2007/12/25
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
中文-新加坡 25-十二月-07
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
英文: Dec 25, 2007
(2)消息标签:<fmt:bundle> <fmt:message> <fmt:setBundle> <fmt:param>
如:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ page language="java" contentType="text/html; charset=gb2312" import="java.util.*"%>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<title>bundle test</title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:bundle basename="dbconn">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
数据库驱动程序名:<fmt:message key="driverName"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
连接字符串:<fmt:message key="connString"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
用户名:<fmt:message key="userName"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
密码:<fmt:message key="password" var="password"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<c:out value="${password}"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
名字:<fmt:message key="name"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
动态提示信息:<fmt:message key="messageTemp"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</fmt:bundle>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!-- 修改.properties文件中某个键的动态值 -->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<c:set var="todayTemp" value="<%=new Date() %>"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:setBundle basename="dbconn"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
动态提示信息:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:message key="messageTemp">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:param>王四</fmt:param>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:param value="${todayTemp}"></fmt:param>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</fmt:message>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</html>
其对应的读取文件为dbconn.properties(当然是放在web-inf/classes下了),内容为:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#SQL Server
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
driverName=com.microsoft.jdbc.sqlserver.SQLServerDriver
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
connString=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDatabase
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
userName=sa
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
password=123456
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
name=陈三
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
messageTemp=myname is {0},today is {1,date}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
其页面输出为:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
数据库驱动程序名:com.microsoft.jdbc.sqlserver.SQLServerDriver
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
连接字符串:jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDatabase
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
用户名:sa
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
密码: 123456
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
名字:陈三
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
动态提示信息:myname is {0},today is {1,date}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
动态提示信息: myname is 王四,today is 2007-12-25
解释一下其中的几个标签:
<fmt:bundle>标签用于绑定数据源.properties文件;
<fmt:bundle basename="源文件名,且不能带后缀哦,如上例就可以了" prefix=""> 语句,代码等 </fmt:bundle>
<fmt::message>标签用于从指定的资源文件中把指定的键值取出来;
<fmt:message key="" [var="varname"] [bundle=""] [scope="page|..."]/> 如果用到var的话就不会在页面直接输出,而需要用到<c:out>标签来进行页面的输出,如上例;
<fmt:message>标签可以配合<fmt:param>标签来进行设定<fmt:message>标签指向键的动态值,如上例;
<fmt:setBundle>标签用于设置默认的数据来源;
<fmt:setBundle>标签用来设置默认的数据来源; <fmt:setBundle basename="" [ var=""] [scope="" ] />
(3)
<fmt:formatNumber>标签用于根据设定的区域将数据格式化输出;
<fmt:formatDate>标签用于格式化输出日期和时间;
<fmt:parseDate>标签用于把字符串类型的日期和时间转换成日期型数据类型;
<fmt:setTimeZone>标签用于设定默认的时区;
<fmt:timeZone>标签用于设定在本签体内有效的时区;
(1) 国际化:<fmt:setLocale> <fmt::requestEncoding>
如:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ page language="java" contentType="text/html; charset=gb2312" import="java.util.*"%>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<title>Insert title here</title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<c:set var="todayValue" value="<%=new Date() %>"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
中文-大陆:<fmt:setLocale value="zh"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:formatDate value="${todayValue}"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
中文-台湾<fmt:setLocale value="zh_tw"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:formatDate value="${todayValue}"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
中文-新加坡<fmt:setLocale value="zh_sg"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:formatDate value="${todayValue}"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
英文:<fmt:setLocale value="en"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:formatDate value="${todayValue}"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</html>
页面输出:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
中文-大陆: 2007-12-25
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
中文-台湾 2007/12/25
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
中文-新加坡 25-十二月-07
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
英文: Dec 25, 2007
(2)消息标签:<fmt:bundle> <fmt:message> <fmt:setBundle> <fmt:param>
如:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ page language="java" contentType="text/html; charset=gb2312" import="java.util.*"%>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<title>bundle test</title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:bundle basename="dbconn">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
数据库驱动程序名:<fmt:message key="driverName"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
连接字符串:<fmt:message key="connString"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
用户名:<fmt:message key="userName"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
密码:<fmt:message key="password" var="password"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<c:out value="${password}"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
名字:<fmt:message key="name"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
动态提示信息:<fmt:message key="messageTemp"/><br>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</fmt:bundle>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!-- 修改.properties文件中某个键的动态值 -->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<c:set var="todayTemp" value="<%=new Date() %>"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:setBundle basename="dbconn"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
动态提示信息:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:message key="messageTemp">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:param>王四</fmt:param>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<fmt:param value="${todayTemp}"></fmt:param>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</fmt:message>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</html>
其对应的读取文件为dbconn.properties(当然是放在web-inf/classes下了),内容为:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#SQL Server
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
driverName=com.microsoft.jdbc.sqlserver.SQLServerDriver
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
connString=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDatabase
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
userName=sa
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
password=123456
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
name=陈三
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
messageTemp=myname is {0},today is {1,date}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
其页面输出为:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
数据库驱动程序名:com.microsoft.jdbc.sqlserver.SQLServerDriver
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
连接字符串:jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDatabase
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
用户名:sa
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
密码: 123456
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
名字:陈三
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
动态提示信息:myname is {0},today is {1,date}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
动态提示信息: myname is 王四,today is 2007-12-25
解释一下其中的几个标签:
<fmt:bundle>标签用于绑定数据源.properties文件;
<fmt:bundle basename="源文件名,且不能带后缀哦,如上例就可以了" prefix=""> 语句,代码等 </fmt:bundle>
<fmt::message>标签用于从指定的资源文件中把指定的键值取出来;
<fmt:message key="" [var="varname"] [bundle=""] [scope="page|..."]/> 如果用到var的话就不会在页面直接输出,而需要用到<c:out>标签来进行页面的输出,如上例;
<fmt:message>标签可以配合<fmt:param>标签来进行设定<fmt:message>标签指向键的动态值,如上例;
<fmt:setBundle>标签用于设置默认的数据来源;
<fmt:setBundle>标签用来设置默认的数据来源; <fmt:setBundle basename="" [ var=""] [scope="" ] />
(3)
<fmt:formatNumber>标签用于根据设定的区域将数据格式化输出;
<fmt:formatDate>标签用于格式化输出日期和时间;
<fmt:parseDate>标签用于把字符串类型的日期和时间转换成日期型数据类型;
<fmt:setTimeZone>标签用于设定默认的时区;
<fmt:timeZone>标签用于设定在本签体内有效的时区;
相关文章推荐
- 关于用<fmt:message>标签读取springmvc配置的国际化资源文件显示为???key???的错误原因
- net控件中数据导到Excel的格式 首先,我们了解一下excel从web页面上导出的原理。当我们把这些数据发送到客户端时,我们想让客户端程序(浏览器)以excel的格式读取它,所以把mime类型设为:application/vnd.ms-excel,当excel读取文件时会以每个cell的格式呈现数据,如果cell没有规定的格式,则excel会以默认的格式去呈现该cell的数据。这样就给我们提供了自定义数据格式的空间,当然我们必须使用excel支持的格式。下面就列出常用的一些格式: 1) 文本
- 用java代码实现从excel表格读取数据然后写入生成国际化配置文件properties
- applicationContext.xml中设置读取jdbc.properties文件
- springboot的application.properties配置文件的配置项读取
- xml读取properties配置文件,web.xml读取properties,properties格式,properties在eclipse创建
- fmt 国际化格式标签库
- select 标签 properties文件读取值 未完待续
- 使用ResourceBundle国际化资源文件读取properties详解
- XMLUtil工具类读取XML或properties格式的配置文件
- Spring Boot默认配置文件application.properties配置格式
- java读取ApplicationResources.properties资源文件
- Spirng 如何读取配置文件application.properties
- xml读取properties配置文件,web.xml读取properties,properties格式,properties在eclipse创建
- jstl fmt标签的关于国际化和取资源文件的说明
- Java Application下读取properties配置文件
- java处理国际化和读取properties文件代码片段
- java读取ApplicationResources.properties资源文件 (转贴)
- SpringBoot内部配置:“application.properties配置”和”使用XML配置”,读取属性文件中的内容,日志配置,Profile配置(学习:SpringBoot实战)
- Spring-boot中读取核心配置文件application和自定义properties配置文件的方式