JSTL补遗

1) <fn:replace>函数
    用来替换字符串
  
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<head>
<title>Using JSTL Functions</title>
</head>
<body>

<c:set var="string1" value="This is first String."/>
<c:set var="string2" value="${fn:replace(string1, 
                                'first', 'second')}" />

<p>Final String : ${string2}</p>

</body>
</html>


    将string1中出现的firest替换为second
  输出:Final String : This is second String.


2) <fn;trim>
   去掉多余空格
  
<c:set var="str"  value="    Hello world!!!        Welcome to JavaBeat.  "></c:set>
             <p>Trimmed String is:</p>
	<c:out value="${fn:trim(str)}"></c:out>


3) 转换到大小写的
   <fn: toUpperCase> 

<c:set var="str" value="welcome to javabeat"></c:set>
<c:out value="${fn:toUpperCase(str)}"></c:out>

  还有<fn:toLowerCase>


4) <fn:split()> <fn:join()>
  
<c:set var="name" value="welcome-to-JavaBeat" />

    <c:set var="splitName" value="${fn:split(name,'-')}" />

    <c:set var="joinedName" value="${fn:join(splitName,' ')}" />



5)
   <fn:length>字符串的长度
  如:<c:set var="string1" value="JavaBeat" />
   Length of word JavaBeat is: ${fn:length(string1)}

6)esacapeXml()
    原样输出xml等标记
  <c:set var="testString"
value="This is <b>JSTL escapeXML example</b>
in this JSTL function tutorial."></c:set>
<br> Without escapeXml function : ${testString}

<br> Using escapeXml function : ${fn:escapeXml(testString)}

  使用了esacpe后,原样输出字符了
This is <b>JSTL escapeXML example</b>
in this JSTL function tutorial."


7)  fn: contains(string, substring)
     看是否包含子字符串,如果包含字符串,则返回true,否则返回false;
         <c:set var="str" value="JSP-JAVA服务器端页面"></c:set>
       <c:out value="服务器"/>
       {fn:contains(str,"服务器")
    输出:true

8)  <fn: substringBefore>
  这个标签比较少见:
   其目的是获得字符串中某个特定字符之前的子串,比如
  
<c:set var="str" value="hello world!!!! Welcome to JavaBeat"></c:set>
	<p>Characters after assigning substring:</p>
	${fn:substringBefore(str,'W')}


  输出:
   hello world!!!!

  同理有 <fn: substringAfter>

9)  <sql:setDataSource>
  
<!-- Connect to the database -->
	<sql: setDataSource var="ds" driver="com.mysql.jdbc.Driver"
		url="jdbc: mysql: //localhost/test" user="root" password="" />

The data is below:
	<br>

	<!--  Execute the SQL -->
	<sql:query dataSource="${ds}"
		sql="select * from employees where id >=100" var="result" />

	<!-- How may rows are returned -->
	<c:out value="The rows returned by SQL : ${result.getRowCount()}" />



你可能感兴趣的:(jstl)