JSP之JSTL_functions

<?xml version="1.0" encoding="UTF-8" ?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">

<description>JSTL 1.1 functions library</description>
<display-name>JSTL functions</display-name>
<tlib-version>1.1</tlib-version>
<short-name>fn</short-name>
<uri>http://java.sun.com/jsp/jstl/functions</uri>

<function>
    <description>
      Tests if an input string contains the specified substring.
    </description>
    <name>contains</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>boolean contains(java.lang.String, java.lang.String)</function-signature>
    <example>
      &lt;c:if test="${fn:contains(name, searchString)}">
    </example>
</function>

<function>
    <description>
      Tests if an input string contains the specified substring in a case insensitive way.
    </description>
    <name>containsIgnoreCase</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>boolean containsIgnoreCase(java.lang.String, java.lang.String)</function-signature>
    <example>
      &lt;c:if test="${fn:containsIgnoreCase(name, searchString)}">
    </example>
</function>

<function>
    <description>
      Tests if an input string ends with the specified suffix.
    </description>
    <name>endsWith</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>boolean endsWith(java.lang.String, java.lang.String)</function-signature>
    <example>
      &lt;c:if test="${fn:endsWith(filename, ".txt")}">
    </example>
</function>

<function>
    <description>
      Escapes characters that could be interpreted as XML markup.
    </description>
    <name>escapeXml</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>java.lang.String escapeXml(java.lang.String)</function-signature>
    <example>
      ${fn:escapeXml(param:info)}
    </example>
</function>

<function>
    <description>
      Returns the index withing a string of the first occurrence of a specified substring.
    </description>
    <name>indexOf</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>int indexOf(java.lang.String, java.lang.String)</function-signature>
    <example>
      ${fn:indexOf(name, "-")}
    </example>
</function>

<function>
    <description>
      Joins all elements of an array into a string.
    </description>
    <name>join</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>java.lang.String join(java.lang.String[], java.lang.String)</function-signature>
    <example>
      ${fn:join(array, ";")}
    </example>
</function>

<function>
    <description>
      Returns the number of items in a collection, or the number of characters in a string.
    </description>
    <name>length</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>int length(java.lang.Object)</function-signature>
    <example>
      You have ${fn:length(shoppingCart.products)} in your shopping cart.
    </example>
</function>

<function>
    <description>
      Returns a string resulting from replacing in an input string all occurrences
      of a "before" string into an "after" substring.
    </description>
    <name>replace</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>java.lang.String replace(java.lang.String, java.lang.String, java.lang.String)</function-signature>
    <example>
      ${fn:replace(text, "-", "•")}
    </example>
</function>

<function>
    <description>
      Splits a string into an array of substrings.
    </description>
    <name>split</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>java.lang.String[] split(java.lang.String, java.lang.String)</function-signature>
    <example>
      ${fn:split(customerNames, ";")}
    </example>
</function>

<function>
    <description>
      Tests if an input string starts with the specified prefix.
    </description>
    <name>startsWith</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>boolean startsWith(java.lang.String, java.lang.String)</function-signature>
    <example>
      &lt;c:if test="${fn:startsWith(product.id, "100-")}">
    </example>
</function>

<function>
    <description>
      Returns a subset of a string.
    </description>
    <name>substring</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>java.lang.String substring(java.lang.String, int, int)</function-signature>
    <example>
      P.O. Box: ${fn:substring(zip, 6, -1)}
    </example>
</function>

<function>
    <description>
      Returns a subset of a string following a specific substring.
    </description>
    <name>substringAfter</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>java.lang.String substringAfter(java.lang.String, java.lang.String)</function-signature>
    <example>
      P.O. Box: ${fn:substringAfter(zip, "-")}
    </example>
</function>

<function>
    <description>
      Returns a subset of a string before a specific substring.
    </description>
    <name>substringBefore</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>java.lang.String substringBefore(java.lang.String, java.lang.String)</function-signature>
    <example>
      Zip (without P.O. Box): ${fn:substringBefore(zip, "-")}
    </example>
</function>

<function>
    <description>
      Converts all of the characters of a string to lower case.
    </description>
    <name>toLowerCase</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>java.lang.String toLowerCase(java.lang.String)</function-signature>
    <example>
      Product name: ${fn:toLowerCase(product.name)}
    </example>
</function>

<function>
    <description>
      Converts all of the characters of a string to upper case.
    </description>
    <name>toUpperCase</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>java.lang.String toUpperCase(java.lang.String)</function-signature>
    <example>
      Product name: ${fn:UpperCase(product.name)}
    </example>
</function>

<function>
    <description>
      Removes white spaces from both ends of a string.
    </description>
    <name>trim</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>java.lang.String trim(java.lang.String)</function-signature>
    <example>
      Name: ${fn:trim(name)}
    </example>
</function>

</taglib>

使用方法


上述是http://java.sun.com/jsp/jstl/functions的源代码

用来弥补JSTL在处理字符串上的缺陷

使用的方式

一、

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

二、

在WEB-INF目录下创建functions.ltd

然后将上述代码拷进去

<%@ taglib prefix="fn" uri="/WEB-INF/functions.tld" %>

或则

<%@ 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, "-", "•")}
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)}
时间: 2024-10-14 14:24:51

JSP之JSTL_functions的相关文章

不用动手术的肝脏清洗法

几乎每个人体内都有肝胆结石,或许很多人只知道胆结石,不知道肝脏内也有结石,也不知道其实很多胆结石的初期就是在肝脏内形成的,更不知道吃夜宵.晚饭在7点之后吃.吃油炸食品.甚至喝水较少也会导致肝胆结石.就以上几个不良生活习惯,我们每个人占多少?简单的讲,肝脏是人体内最大的器官,它是人体的解毒工厂,它的构造极其复杂,所以至今为止,人类无法设计出人造肝脏,它的复杂度仅次于脑组织.所以让肝脏维持正常功能直接关系着人体的健康.肝脏可以使激素,酒精以及某些有害药物在体内失效.各种人体无法代谢的毒素都会由肝脏负

导演与明星老婆离婚 恋亲手捧红干女儿

http://www.ehotelier.cn/Thread.jsp?tid=182934http://www.ehotelier.cn/Thread.jsp?tid=182940http://www.ehotelier.cn/Thread.jsp?tid=182946http://www.ehotelier.cn/Thread.jsp?tid=182951http://www.ehotelier.cn/Thread.jsp?tid=182957http://www.ehotelier.cn/T

jsp获取当前项目跟路径

在jsp中获取当前项目的根路径: <% String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";%> 可以使用${basePath}获取.

Jsp通过Filter实现UrlRewriter原理

web.xml文件: 1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=&q

jsp声明周期

https://www.w3cschool.cn/jsp/jsp-life-cycle.html 几点注意: jsp初始化期: 容器载入jsp文件后,它会在为请求提供任何服务前调用jspinit()方法.如果需要执行自定义的jsp初始化任务,就重写jspinit()方法就行了. public void jspInit() { //代码 } 一般来讲程序只初始化一次,servlet也是一样的.通常情况下您可以在jspInit()方法中初始化数据库连接打开文件和创建查询表. jsp执行期: jspS

JSP、JSTL、EF学习笔记

JSP 1)Java Server Page,在html中嵌入java代码 2)九个内置(隐式)对象 request response out page pageContext config session application Exception 3)JSP指令 <%@ page ... %> Page指令,定义页面属性 eg:<%@ page language="java" contentType="text/html;charset=UTF-8&qu

【JSP】配置错误页面

1,使用JSP方式 如果配置是Jsp时,需要把isErrorPage设置为true, 以及设置 <%@ page language="Java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8" isErrorPage="true"%> 错误页面: <%@page import="java.io.PrintStream"

jsp映射为其他地址上去 ???

在web.xml 里面配置servlet不起作用,所以配置jsp,然后在jsp里面跳转到servlet去   ???  第八天中的<08-jsp常用标签.avi> 在web.xml里面先设定 14.jsp 为默认首页,然后在14.jsp 里面设定跳转到servlet 代码里面去 映射到其他地址去:

关于tomcat JSP虚拟目录的这点事儿!

最简单的情况当然是将.jsp文件放在C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ROOT目录下,运行tomcat, 在浏览器中直接访问http://localhost:8080/HelloWorld.jsp  即可运行.jsp文件 而在实际的开发运用中,我们是不可能将Tomcat应用程序安装在系统盘如C盘. 所以,我们需要运用到设置虚拟目录的知识: 为创建虚拟目录以在浏览器中运行jsp文件:1:假设我们将tomca