---
title: "jstl 字符串函数"
author: "istone"
date: "2009-07-31T13:58:59Z"
tags: ["C", "C#", "C++", "JSP", "SUN"]
slug: "jstl"
draft: false
lastmod: "2009-07-31T13:58:59Z"
id: 437020
url: "https://istone.iteye.com/blog/437020"
---

原文地址：[http://tianke66.iteye.com/blog/332907](http://tianke66.iteye.com/blog/332907)

首先要导入JSTL1.1标签库jakarta-taglibs-standard-1.1.2,并且导入的路径改为  
   
&lt;%@ taglib uri="[http://java.sun.com/jstl/core](http://java.sun.com/jstl/core)"       prefix="c" %&gt;  
&lt;%@ taglib uri="[http://java.sun.com/jstl/fmt](http://java.sun.com/jstl/fmt)"        prefix="fmt" %&gt;  
将以上的路径改为:  
   
&lt;%@ taglib uri="[http://java.sun.com/jsp/jstl/core](http://java.sun.com/jsp/jstl/core)"       prefix="c" %&gt;  
&lt;%@ taglib uri="[http://java.sun.com/jsp/jstl/fmt](http://java.sun.com/jsp/jstl/fmt)"        prefix="fmt" %&gt;  
&lt;%@ taglib uri="[http://java.sun.com/jsp/jstl/functions](http://java.sun.com/jsp/jstl/functions)" prefix="fn"%&gt;  
&lt;%@ taglib uri="[http://jakarta.apache.org/taglibs/string-1.0.1](http://jakarta.apache.org/taglibs/string-1.0.1)" prefix="str" %&gt;  
   
&lt;c:if test="${fn:length(popularvideos.mWeblogTitle) &gt;= 15}"&gt;  
            ${fn:substring(popularvideos.mWeblogTitle,0,15)}......  
            &lt;/c:if&gt;  
        &lt;c:if test="${fn:length(popularvideos.mWeblogTitle) &lt; 15}"&gt;  
            ${popularvideos.mWeblogTitle}  
           &lt;/c:if&gt;  
   
注不能用&lt;c:choose&gt;&lt;c:when&gt;&lt;c:otherwise&gt;  
   
&lt;%@ taglib uri="[http://java.sun.com/jsp/jstl/functions](http://java.sun.com/jsp/jstl/functions)" prefix="fn"%&gt;

函数描述  
   
fn:contains(string, substring)  
 如果参数string中包含参数substring，返回true  
   
fn:containsIgnoreCase(string, substring)  
 如果参数string中包含参数substring（忽略大小写），返回true  
   
fn:endsWith(string, suffix)  
 如果参数 string 以参数suffix结尾，返回true  
   
fn:escapeXml(string)  
 将有特殊意义的XML (和HTML)转换为对应的XML character entity code，并返回  
   
fn:indexOf(string, substring)  
 返回参数substring在参数string中第一次出现的位置  
   
fn:join(array, separator)  
 将一个给定的数组array用给定的间隔符separator串在一起，组成一个新的字符串并返回。  
   
fn:length(item)  
 返回参数item中包含元素的数量。参数Item类型是数组、collection或者String。如果是String类型,返回值是String中的字符数。  
   
fn:replace(string, before, after)  
 返回一个String对象。用参数after字符串替换参数string中所有出现参数before字符串的地方，并返回替换后的结果  
   
fn:split(string, separator)  
 返回一个数组，以参数separator 为分割符分割参数string，分割后的每一部分就是数组的一个元素  
   
fn:startsWith(string, prefix)  
 如果参数string以参数prefix开头，返回true  
   
fn:substring(string, begin, end)  
 返回参数string部分字符串, 从参数begin开始到参数end位置，包括end位置的字符  
   
fn:substringAfter(string, substring)  
 返回参数substring在参数string中后面的那一部分字符串  
   
fn:substringBefore(string, substring)  
 返回参数substring在参数string中前面的那一部分字符串  
   
fn:toLowerCase(string)  
 将参数string所有的字符变为小写，并将其返回  
   
fn:toUpperCase(string)  
 将参数string所有的字符变为大写，并将其返回  
   
fn:trim(string)  
 去除参数string 首尾的空格，并将其返回