• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    數據庫中JSTL字符串處理函數

    發布: 2010-11-09 11:10 | 作者: 網絡轉載 | 來源: 領測軟件測試網采編 | 查看: 86次 | 進入軟件測試論壇討論

    領測軟件測試網

    數據庫中JSTL字符串處理函數

    JSTL使用表達式來簡化頁面的代碼,這對一些標準的方法,例如bean的getter/setter方法,請求參數或者context以及session中的數據的訪問非常方便,但是我們在實際應用中經常需要在頁面調用對象的某些方法,例如我需要調用字符串的length方法來獲取字符串的長度時,在以往的開發過程中我們必須把對象先轉為String類,然后在調用其length方法,這樣的代碼繁瑣而且容易出錯。

    因此JSTL內置了幾個用于字符串操作的方法,可以直接在表達式中使用,大大的簡化了代碼,提供代碼的可讀性。在JSTL的表達是中要使用一個函數,其格式如下

    ${ns:methodName(args....)}

    在使用這些函數之前必須在JSP中引入標準函數的聲明

    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

    下面是JSTL中自帶的方法列表以及其描述

    函數名 函數說明 使用舉例
    contains 判斷字符串是否包含另外一個字符串 <c:if test="${fn:contains(name, searchString)}">
    containsIgnoreCase 判斷字符串是否包含另外一個字符串(大小寫無關) <c:if test="${fn:containsIgnoreCase(name, searchString)}">
    endsWith 判斷字符串是否以另外字符串結束 <c:if test="${fn:endsWith(filename, ".txt")}">
    escapeXml 把一些字符轉成XML表示,例如<字符應該轉為&lt; ${fn:escapeXml(param:info)}
    indexOf 子字符串在母字符串中出現的位置 ${fn:indexOf(name, "-")}
    join 將數組中的數據聯合成一個新字符串,并使用指定字符格開 ${fn:join(array, ";")}
    length 獲取字符串的長度,或者數組的大小 ${fn:length(shoppingCart.products)}
    replace 替換字符串中指定的字符 ${fn:replace(text, "-", "•")}
    split 把字符串按照指定字符切分 ${fn:split(customerNames, ";")}
    startsWith 判斷字符串是否以某個子串開始 <c:if test="${fn:startsWith(product.id, "100-")}">
    substring 獲取子串 ${fn:substring(zip, 6, -1)}
    substringAfter

    獲取從某個字符所在位置開始的子串

    ${fn:substringAfter(zip, "-")}
    substringBefore 獲取從開始到某個字符所在位置的子串 ${fn:substringBefore(zip, "-")}
    toLowerCase 轉為小寫 ${fn.toLowerCase(product.name)}
    toUpperCase 轉為大寫字符 ${fn.UpperCase(product.name)}
    trim 去除字符串前后的空格 ${fn.trim(name)}

    函數名     函數說明
    contains 判斷字符串是否包含另外一個字符串 <c:if test="${fn:contains(name, searchString)}">
    containsIgnoreCase 判斷字符串是否包含另外一個字符串(大小寫無關) <c:if test="${fn:containsIgnoreCase(name, searchString)}">
    endsWith 判斷字符串是否以另外字符串結束 <c:if test="${fn:endsWith(filename, ".txt")}">
    escapeXml 把一些字符轉成XML表示,例如<字符應該轉為&lt; ${fn:escapeXml(param:info)}
    indexOf 子字符串在母字符串中出現的位置 ${fn:indexOf(name, "-")}
    join 將數組中的數據聯合成一個新字符串,并使用指定字符格開 ${fn:join(array, ";")}
    length 獲取字符串的長度,或者數組的大小 ${fn:length(shoppingCart.products)}
    replace 替換字符串中指定的字符 ${fn:replace(text, "-", "?")}
    split 把字符串按照指定字符切分 ${fn:split(customerNames, ";")}
    startsWith 判斷字符串是否以某個子串開始 <c:if test="${fn:startsWith(product.id, "100-")}">
    substring 獲取子串 ${fn:substring(zip, 6, -1)}
    substringAfter 獲取從某個字符所在位置開始的子串
    ${fn:substringAfter(zip, "-")}
    substringBefore 獲取從開始到某個字符所在位置的子串 ${fn:substringBefore(zip, "-")}
    toLowerCase 轉為小寫 ${fn.toLowerCase(product.name)}
    toUpperCase 轉為大寫字符 ${fn.UpperCase(product.name)}
    trim 去除字符串前后的空格 ${fn.trim(name)}



    JSTL中自帶的方法列表
    面是JSTL中自帶的方法列表以及其描述
    contains
    判斷字符串是否包含另外一個字符串
    <c:if test="${fn:contains(name, searchString)}">

    containsIgnoreCase
    判斷字符串是否包含另外一個字符串(大小寫無關)
    <c:if test="${fn:containsIgnoreCase(name, searchString)}">

    endsWith
    判斷字符串是否以另外字符串結束
    <c:if test="${fn:endsWith(filename, ".txt")}">

    escapeXml
    把一些字符轉成XML表示,例如<字符應該轉為<
    ${fn:escapeXml(param:info)}

    indexOf
    子字符串在母字符串中出現的位置
    ${fn:indexOf(name, "-")}

    join
    將數組中的數據聯合成一個新字符串,并使用指定字符格開
    ${fn:join(array, ";")}

    length
    獲取字符串的長度,或者數組的大小
    ${fn:length(shoppingCart.products)}

    replace
    替換字符串中指定的字符
    ${fn:replace(text, "-", "?")}

    split
    把字符串按照指定字符切分
    ${fn:split(customerNames, ";")}

    startsWith
    判斷字符串是否以某個子串開始
    <c:if test="${fn:startsWith(product.id, "100-")}">

    substring
    獲取子串
    ${fn:substring(zip, 6, -1)}

    substringAfter
    獲取從某個字符所在位置開始的子串
    ${fn:substringAfter(zip, "-")}

    substringBefore
    獲取從開始到某個字符所在位置的子串
    ${fn:substringBefore(zip, "-")}

    toLowerCase
    轉為小寫
    ${fn.toLowerCase(product.name)}

    toUpperCase
    轉為大寫字符
    ${fn.UpperCase(product.name)}

    trim
    去除字符串前后的空格
    ${fn.trim(name)}

    今天將JSP的項目從Tomcat 5.5.12移植到Jboss AS去,偶然發現了一個奇怪的問題。"org.apache.jasper.JasperException: This absolute uri (http://java.sun.com/jsp/jstl/core) cannot be resolved in either web.xml or the jar files deployed with this application "

        由于JSTL1.0和JSTL1.1的聲明語句不一樣。

    JSTL 1.0 的聲明是:
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

    JSTL1.1 的聲明是:
    <%@ taglib prefix="c" uri=http://java.sun.com/jsp/jstl/core %>

    如果你使用的JSTL庫和你在JSP中的聲明不一致。就會報上面提到的Exception。

    另外,要注意的是:Tomcat是先引用"TOMCAT_HOME/shared/lib"下面的庫,再引用web項目下面的"WEB-INF/lib'的庫。

    還有就是,jBuilder自帶庫中的JSTL有兩個配置,一個是"JSTL"(1.0),一個是"JSTL1.1"(1.1),注意在做項目的時候別引用錯了。

    還有一個技巧是:如何判斷JSTL的兩個庫文件(standar.jar和jstl.jar)的版本?展開jar文件在"META-INF"目錄下的MANIFEST.MF文件,其中"Specification-Version"指名的就是版本號。

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/

    TAG: 函數 數據庫 字符 JSTL


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備2023014753號-2
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>