Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 1.03 KB

23.md

File metadata and controls

39 lines (29 loc) · 1.03 KB

fn:length() - JSTL 函数

原文: https://beginnersbook.com/2013/12/fn-length-jstl-function/

JSTL 函数 fn:length()用于计算字符串的长度或查找集合中元素的数量。

语法

int length(Object)

此函数的返回类型为int。它返回作为参数提供的对象的长度。

fn:length()的示例

这里我们使用函数计算三个不同字符串的长度。

<%@ 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>JSTL fn:length() example</title>
</head>
<body>
<c:set var="string1" value="This is String1"/>
<c:set var="string2" value="Hi"/>
<c:set var="string3" value="string3"/>
Length of String1 is: ${fn:length(string1)}<br>
Length of String2 is: ${fn:length(string2)}<br>
Length of String3 is: ${fn:length(string3)}
</body>
</html>

输出:

fn-length-example