jstl 格式化 fmt

<%@ taglib prefix='fmt' uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=utf-8" 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" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
        <style type="text/css">
                body {background-color: black;color: white;}
                span {text-align: center;color: green;background-color: yellow;}
                .notice {color: rgb(250,37,62);}
                hr { background-color: fuchsia; height: 5px;}
        </style>
  </head>
  
  <body>
          <fmt:bundle basename="jstl.jstl">
                  <span>从 .properties 文件中读取最简单的信息输出:</span>
                  <fmt:message key="basemsg" />
                  <hr/>
                  <span>从 .properties 文件中读取带有可填参数的信息,填入参数并输出:</span>
                  <fmt:message key="msgwithparam">
                          <span class="notice"><fmt:param value="param-1-value" />
                          <span class="notice"><fmt:param value="param-2-value" />
                  </fmt:message>
                  <hr/>
                  <span>数字 格式化并输出:</span><br/>
                  数字:<fmt:formatNumber value="1234567890" type="number"/><br/>
                  <!-- 定制数字格式时,# 表示按照默认格式来, -->
                  数字,定制了格式:<fmt:formatNumber value="1234567890" type="number" pattern="#,#00.0#" /><br/>
                  货币:<fmt:formatNumber value="35000" type="currency" /><br/>
                  百分比:<fmt:formatNumber value="0.317" type="percent" /><br/>
                  <hr/>
                  <span>格式化日期:</span><br/>
                  <jsp:useBean id="now" class="java.util.Date"></jsp:useBean>
                  <fmt:formatDate value="${now}" type="date" /><br/>
                  <fmt:formatDate value="${now}" type="both" dateStyle="long" timeStyle="long" /><br/>
                  <fmt:formatDate value="${now}" type="both" pattern="yyyy.MM.dd HH:mm:ss" /><br/>
                  <hr/>
                  <span>将字符串转化到正确的数字:<br/>
                  忽略第一个不符合数字条件的字符和其之后的所有字符,如果字符串不是以数字开头则报错</span><br/>
                  <fmt:parseNumber type="number" >123.02a</fmt:parseNumber><br/>
                  <fmt:parseNumber type="number" pattern="#,#00.0#">123</fmt:parseNumber><br/>
                  <fmt:parseNumber type="number" pattern="#,#00.0#">123.00a1</fmt:parseNumber><br/>
                  <fmt:parseNumber type="number" pattern="#,#00.0#">3saaa</fmt:parseNumber><br/>
                  
          </fmt:bundle>
                  
  </body>
</html>

你可能感兴趣的:(jstl,fmt)