java jstl fmt fn 标签

来源:互联网 发布:sql between and的用法 编辑:程序博客网 时间:2024/06/10 16:59
  1. <%@ taglib prefix='fmt' uri="http://java.sun.com/jsp/jstl/fmt" %> 
  2. 输出 .properties 文件中的信息 <fmt:bundle basename="deploy_config">  
     <fmt:message key="jdbc_url"></fmt:message>
     </fmt:bundle>

    其中 <fmt:bundle basename="deploy_config"> 指定了资源文件的位置,例如: fmt 表示类根路径下的deploy_config.properties 文件,my.deploy_config 表示 包my下的deploy_config.properties文件;

     

    <fmt:message key="jdbc_ur" />表示读取 key为jdbc_ur的值,并输出;

  3. 格式化数字fmt:formatNumber

    <fmt:formatNumber value="12" type="currency"pattern="$.00"/> -- $12.00

    <fmt:formatNumber value="12" type="currency"pattern="$.0#"/> -- $12.0

    <fmt:formatNumber value="1234567890"type="currency"/> --$1,234,567,890.00(那个货币的符号和当前web服务器的 local 设定有关)

    <fmt:formatNumber value="123456.7891"pattern="#,#00.0#"/> -- 123,456.79

    <fmt:formatNumber value="123456.7"pattern="#,#00.0#"/> -- 123,456.7

    <fmt:formatNumber value="123456.7"pattern="#,#00.00#"/> -- 123,456.70

    <fmt:formatNumber value="12" type="percent"/> -- 1,200% (type 可以是currency、 number、和percent)。


    符号                 意义
                       一个数位
                       一个数位,前导零和追尾零不显示
                        小数点分割位置
    ,                    组分隔符的位置
                        负数前缀
                      用100乘,并显示百分号
    其他任何符号   在输出字符串中包括指定符号

  4. <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>   
      
    fn:contains 判断字符串是否包含另外一个字符串 <c:if test="${fn:contains(name, searchString)}">    
    fn:containsIgnoreCase 判断字符串是否包含另外一个字符串(大小写无关) <c:if test="${fn:containsIgnoreCase(name, searchString)}">    
    fn:endsWith 判断字符串是否以另外字符串结束 <c:if test="${fn:endsWith(filename, ".txt")}">    
    fn:escapeXml 把一些字符转成XML表示,例如 <字符应该转为&lt; ${fn:escapeXml(param:info)}    
    fn:indexOf 子字符串在母字符串中出现的位置 ${fn:indexOf(name, "-")}    
    fn:join 将数组中的数据联合成一个新字符串,并使用指定字符格开 ${fn:join(array, ";")}    
    fn:length 获取字符串的长度,或者数组的大小 ${fn:length(shoppingCart.products)}    
    fn:replace 替换字符串中指定的字符 ${fn:replace(text, "-", "&#149;")}    
    fn:split 把字符串按照指定字符切分 ${fn:split(customerNames, ";")}    
    fn:startsWith 判断字符串是否以某个子串开始 <c:if test="${fn:startsWith(product.id, "100-")}">    
    fn:substring 获取子串 ${fn:substring(zip, 6, -1)}    
    fn:substringAfter 获取从某个字符所在位置开始的子串${fn:substringAfter(zip, "-")}    
    fn:substringBefore 获取从开始到某个字符所在位置的子串 ${fn:substringBefore(zip, "-")}    
    fn:toLowerCase 转为小写 ${fn:toLowerCase(product.name)}    
    fn:toUpperCase 转为大写字符 ${fn:UpperCase(product.name)}    
    fn:trim 去除字符串前后的空格 ${fn:trim(name)}


原创粉丝点击