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表达 ...
随机推荐
- Android Studio安装后提示No JVM installation found解决办法
Android Studio安装后提示No JVM installation found解决办法 问题描述:Android Studio安装完毕,打开时出现提示"No JVM install ...
- css中!important的优先级问题
css中!important的优先级在主页面中写>在外部引用的css文件 之前我一直以为css的样式不管写在哪里只要加上!important那么它的优先级就是最高的,事实上并不是这样的,尤其在动 ...
- Use two picogate devices for bidirectional level-shifting
In new mixed-voltage systems, it is often necessary to level-shift a control signal from a high leve ...
- WICED -- Wireless Internet Connectivity for Embedded Devices
Broadcom's Wireless Internet Connectivity for Embedded Devices (WICED™) platform (pronounced "w ...
- cadence学习(1)常规封装的建立
1.建立焊盘. (1)首先要获得datasheet(或可用pcb matrix ipc-7531标准的可查询封装软件)中元器件的封装信息. (2)建立.pad文件.打开PCB Editor Utili ...
- windows样式(style)参考
[WTL] 窗体Style的含义比较有用的设置:(1)WS_POPUP:弹出式窗体,没有标题栏!WS_BORDER:细的黑边框WS_OVERLAPPED:一般的有标题栏的窗体,见多了.WS_CHILD ...
- matlab 人面检测
Create a detector object. faceDetector = vision.CascadeObjectDetector;Read input image. I = imread(' ...
- XML 简单介绍
先附上一张XML 大概图:详解见博客内容. 一.定义 XML(EXtensible Markup Language) :可扩展标记语言. 设计的用途:用来描述,存储,传输数据信息. 二.特色 1.单纯 ...
- C++对C的改进(1)
本文地址:http://www.cnblogs.com/archimedes/p/cpp-change1.html,转载请注明源地址 新的初始化方法 C提供的初始化方法 int x = 1024; C ...
- [Python爬虫] 之五:Selenium 处理滚动条
selenium并不是万能的,有时候页面上操作无法实现的,这时候就需要借助JS来完成了. 当页面上的元素超过一屏后,想操作屏幕下方的元素,是不能直接定位到,会报元素不可见的.这时候需要借助滚动条来拖 ...