fmt:message key为el表达式

来源

http://www.cnblogs.com/yangy608/archive/2011/11/10/2244300.html


将<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>

改为<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>即可

<fmt:message key="acctType${l.acctType}"/>

资源文件:

acctType0=其他
acctType1=个人储蓄账户
acctType2=个人结算账户(储蓄)
acctType3=个人结算账户(对公)

日期表示

<fmt:formatDate value="${isoDate}" type="both"/>2004-5-31 23:59:59


<%@ page language="java" contentType="text/html; charset=gb18030"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
     <head>
       <title>My JSP 'fmt.jsp' starting page</title>
     </head>
 
     <body>
      <c:set var="salary" value="3540.2301"/>
      <c:set var="total" value="56225.2301"/>
      <fmt:setLocale value="en_US"/>
      currency:<fmt:formatNumber value="${salary}" type="currency" currencyCode="USD"/><br>
      percent:<fmt:formatNumber value="${salary/total}" type="percent" maxFractionDigits="4"/><br>
      <hr>
      <jsp:useBean id="now" class="java.util.Date"></jsp:useBean>
      <fmt:setLocale value="zh_CN"/>
      full--><fmt:formatDate value="${now}" type="both" dateStyle="full" timeStyle="full"/><br>
      long--><fmt:formatDate value="${now}" type="both" dateStyle="long" timeStyle="long"/><br>
      medium--><fmt:formatDate value="${now}" type="both" dateStyle="medium" timeStyle="medium"/><br>
      default--><fmt:formatDate value="${now}" type="both" dateStyle="default" timeStyle="default"/><br>
      short--><fmt:formatDate value="${now}" type="both" dateStyle="short" timeStyle="short"/><br>
     </body>
</html>
=================================================================================

JSP 国际化-格式化货币和日期
.格式化货币

世界上许多国家都有不同的货币格式和数字格式惯例。针对特定的本地化环境正确地格式化和显示货币是本地化的一个重要部分。

<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<html>
<head>

<title>Currency Formatting</title>
</head>
<body>
<h1>Currency Formatting and locales</h1>

<h3>English, Great Britain</h3>
<fmt:setLocale value="en_GB"/>
<fmt:formatNumber type="currency" value="80000"/><br/>

<h3>English, USA</h3>
<fmt:setLocale value="en_US"/>
<fmt:formatNumber type="currency" value="80000"/><br/>

<h3>French, France</h3>
<fmt:setLocale value="fr_FR"/>
<fmt:formatNumber type="currency" value="80000"/><br/>

<h3>Japanese, Japan</h3>
<fmt:setLocale value="ja_JP"/>
<fmt:formatNumber type="currency" value="80000"/><br/>

<h3>Korean, Korea</h3>
<fmt:setLocale value="ko_KR"/>
<fmt:formatNumber type="currency" value="80000"/><br/>

<h3>Spanish, Spain</h3>
<fmt:setLocale value="es_ES"/>
<fmt:formatNumber type="currency" value="80000"/><br/>

<h3>Arabic, Egypt</h3>
<fmt:setLocale value="ar_EG"/>
<fmt:formatNumber type="currency" value="80000"/><br/>

<h3>Using Local Numeric Formatting for Different Currency</h3>
<h4>English, Great Britan</h4>
<fmt:setLocale value="en_GB"/>
<fmt:formatNumber type="currency" value="80000"/><br/>
<fmt:formatNumber type="currency" value="80000" currencyCode="EUR"/><br/>

</body>
</html>
.格式化日期

类似于数字和货币格式化,本地化环境还会影响生成日期和时间的方式。

<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<html>
<head>
<title>Date Formatting</title>
</head>
<body>
<h1>Date Formatting and locale</h1>
<fmt:timeZone value="EST">
<jsp:useBean id="currentTime" class="java.util.Date"/>

<h3>English, Great Britain</h3>
<fmt:setLocale value="en_GB"/>
<fmt:formatDate type="both" dateStyle="full" timeStyle="full" value="${currentTime}"/><br/>

<h3>English, USA</h3>
<fmt:setLocale value="en_US"/>
<fmt:formatDate type="both" dateStyle="full" timeStyle="full" value="${currentTime}"/><br/>

<h3>French, France</h3>
<fmt:setLocale value="fr_FR"/>
<fmt:formatDate type="both" dateStyle="full" timeStyle="full" value="${currentTime}"/><br/>

<h3>Japanese, Japan</h3>
<fmt:setLocale value="ja_JP"/>
<fmt:formatDate type="both" dateStyle="full" timeStyle="full" value="${currentTime}"/><br/>

<h3>Korean, Korea</h3>
<fmt:setLocale value="ko_KR"/>
<fmt:formatDate type="both" dateStyle="full" timeStyle="full" value="${currentTime}"/><br/>

<h3>Spanish, Spain</h3>
<fmt:setLocale value="es_ES"/>
<fmt:formatDate type="both" dateStyle="full" timeStyle="full" value="${currentTime}"/><br/>

<h3>Arabic, Egypt</h3>
<fmt:setLocale value="ar_EG"/>
<fmt:formatDate type="both" dateStyle="full" timeStyle="full" value="${currentTime}"/><br/>

</fmt:timeZone>
</body>
</html>

<fmt:formatDate>动作的属性

type: 可以是time,date或both。控制是否只生成时间,只生成日期,或者时间日期都生成。

dateStyle: 可以是short, medium, long 或 full(default)。控制打印日期使用的具体格式。

timeStyle: 可以是short, medium, long 或 full(default)。控制打印时间使用的具体格式。

value: 这是一个java.util.Date 类型的值,用于生成日期和时间。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值