EL表达式中fn函数
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中自带的方法列表以及其描述
| 函数名 | 函数说明 | 使用举例 |
| 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表达 ...
随机推荐
- spring aop 理解
aop简介 aop是spring 的两大特性之一,还有IOC.主要提供面向切面的编程思想,区分于面向对象编程. aop原理(动态代理+反射) 在一个方法体中,可能会存在很多其他的方法调用,我们可以把每 ...
- Linux可以明文传输密码的工具sshpass
普通ssh只能手动输入密码,但是sshpass可以明文指定密码,但不建议使用,太不安全了.
- hdu4035之经典慨率DP
Maze Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Submi ...
- JAVAssist---动态改动注解
ITOOV3.0開始了,须要研究一些技术难点,先来说一个我认为比較有趣的技术点吧.需求是这种.我们须要动态的切换数据源,又因为我们是通过实体单元的注入来完毕的.实体单元是通过注解的形式注入的.这样假 ...
- Eclipse搭建Gradle环境
转自:http://blog.sina.com.cn/s/blog_4b20ae2e0102uz4t.html 1.上Grandle官网下载Gradle,地址:http://www.gradle.or ...
- 一个 MVC 框架以 MVVM 之「魂」复活了!
GitHub: https://github.com/houfeng/mokit Mokit 最初编写于 2012 年,是一个面向移动应用的前端 mvc 框架,v3 版本进行了大量的重构或重写,并尽可 ...
- 登入爱丽网后台(非JS绕过、非盲打、非IP欺骗)
后台: http://wed.27.cn/marry/marryadmin/web/login.php 不难猜解到后台管理的相关页面名称(不存在的页面服务器返回404,而存在的页面会直接跳转到上面的登 ...
- TensorFlow目标检测(object_detection)api使用
https://github.com/tensorflow/models/tree/master/research/object_detection 深度学习目标检测模型全面综述:Faster R-C ...
- 在css加载完毕后执行后续代码
最近在写项目的framework,写个JQueryMessageBox的类,以使用jquery ui中的dialog()来显示消息框,为了使方法方便调用,便加入了自动判断页面是否加入了ui.js和ui ...
- mysql 下 计算 两点 经纬度 之间的距离
公式如下,单位米: 第一点经纬度:lng1 lat1 第二点经纬度:lng2 lat2 round(6378.138*2*asin(sqrt(pow(sin( (lat1*pi()/180-lat2* ...