EL表达式中fn函数 (转载)
因此JSTL内置了几个用于字符串操作的方法,可以直接在表达式中使用,大大的简化了代码,提供代码的可读性。在JSTL的表达是中要使用一个函数,其格式如下
${ns:methodName(args....)}
在使用这些函数之前必须在JSP中引入标准函数的声明
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
下面是JSTL中自带的方法列表以及其描述
函数名 | 函数说明 | 使用举例 |
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表示,例如<字符应该转为< | ${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)} |
函数 |
描述 |
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 首尾的空格,并将其返回 |
http://blog.csdn.net/qingwangyoucao/article/details/6218069
EL表达式中fn函数的使用及截取字符串
文章分类:Java编程 关键字: el表达式中fn函数的使用及截取字符串
fn函数:
- 使用前在Jsp页面的首部加上以下代码:
- <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
- 下面是JSTL中自带的方法列表以及其描述
- 函数名 函数说明 使用举例
- 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表示,例如 <字符应该转为< ${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)}
- 使用前在Jsp页面的首部加上以下代码:
- <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
- 下面是JSTL中自带的方法列表以及其描述
- 函数名 函数说明 使用举例
- 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表示,例如 <字符应该转为< ${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)}
函数 描述
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 首尾的空格,并将其返回
EL表达式中fn函数 (转载)的更多相关文章
- EL表达式中fn函数
JSTL 使用表达式来简化页面的代码,这对一些标准的方法,例如bean的getter/setter方法,请求参数或者context以及 session中的数据的访问非常方便,但是我们在实际应用中经常需 ...
- El表达式和fn函数一起使用
如下: ${a%1>0?a:(fn:substringBefore(a, "."))}
- EL表达式中如何截取字符串
EL表达式中如何截取字符串 可以截取,用fn函数:<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/ ...
- java、el表达式中保留小数的方法
Java中: import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; p ...
- EL表达式中引用隐式变量
除了在jsp中9大隐式变量(在前面文章也叫预定义变量)在转化成为servlet后_jspService中可以看到: public void _jspService(final javax.servle ...
- 关于EL表达式中requestScope和param区别
今天演示EL表达式的时候发现自己jsp的基础实在是薄弱,在这个很简单的问题上迷惑了很久. 首先在看遇到的问题: 在浏览器地址输入,表示传入一个参数test,值为123 http://localhost ...
- 在jsp中怎么使用Cookie?el表达式中获取cookie的问题
初学jsp,不清楚cookie的使用方法,希望高手指点一下! 一般来说有两种办法,在JSP中使用Java的嵌入脚本. 例如: 写入Cookie <html> <head>. ...
- EL表达式中的11个隐式对象
EL表达式中定义了11个隐式对象,使用这些隐式对象可以很方便地读取到Cookie.HTTP请求消息头字段.请求参数.Web应用程序中的初始化参数的信息,EL表达式中的隐式对象具体如下: 隐式对象 作用 ...
- JS中如何使用EL表达式中的对象
JS中如何使用EL表达式中的对象 2017年09月25日 15:33:09 lhpnba 阅读数:4859 1.js中使用el表达式要加双引号或单引号:'${list}' 2.js变量获取el表达 ...
随机推荐
- 【转】Eclipse里项目名有红叉,但是展开后里面又没有红叉叉
Eclipse里项目名有红叉,但是下面的每一个文件都没有红叉 有三种可能: 1:classpath有问题 2:编译级别有问题 3:jar包有问题,我碰过从maven上获取了问题jar包,工程里提示能找 ...
- docker镜象
1.安装好docker后,用docker命令的时候有时候会报错:Post http:///var/run/docker.sock/v1.19/images/create?fromImage=ubunt ...
- 开关WIFI脚本
title wifi管理color A@echo on@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@echo 1.启用并设定虚拟WiFi网卡;@echo 2.开启无线网络; ...
- VIM使用学习笔记 : 按键说明
VIM有三种模式: 一般模式 上下左右移动光标,删除字符或删除整行,复制粘贴 编辑模式 i I i O a A r R 进入编辑模式 命令模式 在一般模式种输入 : / ?,可 ...
- 新建Oracle数据库时,提示使用database control配置数据库时,要求在当前oracle主目录中配置监听程序
新建一个oracle数据库时,当提示使用database control配置数据库时,要求在当前oracle主目录中配置监听程序等字样的时候,问题是那个监听的服务没有启动,解决方法如下: 打开cmd命 ...
- BZOJ3052——糖果公园
0.题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3052 1.题目大意:给定一颗n个点的无根树,每个点有一个颜色,要进行q次操作,有两种操 ...
- python 字典 注意点
dict()构造函数直接从键-值对序列创建字典: >>> >>> dict([('sape', 4139), ('guido', 4127), ('jack', 4 ...
- matlab随笔(三)
把矩阵变成行向量(矩阵元素的排列是从上到下,从左到右): 1.先转置,转成行向量 A = >> A=A' A = >> a=A(:)' a = 2.reshape函数 A = ...
- 2016全国研究生数学建模A题多无人机协同任务规划——基于分布式协同多旅行商MTSP遗传算法
MTSP问题是指:有Ⅳ个城市,要求旅行商到达每个城市各一次,且仅一次,并[旦 1到起点,且要求旅行路线最短.而多旅行商问题M个旅行商从同一个城市(或多个城市)出发.分羽走一条旅路线,且总路程缀短.有关 ...
- OpenMP求完数
源代码: #include "stdafx.h" //必须写在首行,因为其前面的include都会被忽略 #include "omp.h" #include & ...