Latest web development tutorials

fn JSTL: join () função

JSP Standard Tag Library JSP Standard Tag Library

fn: junte-se () para todos os elementos de um array utilizando o delimitador especificado em uma string.

gramática

fn: () sintaxe da função participar é a seguinte:

${fn:join([数组], <分隔符>)}

Exemplos Demonstração

Os exemplos a seguir demonstram as capacidades desta função:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ 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 函数</title>
</head>
<body>

<c:set var="string1" value="www w3big com"/>
<c:set var="string2" value="${fn:split(string1, ' ')}" />
<c:set var="string3" value="${fn:join(string2, '-')}" />

<p>字符串为 : ${string3}</p>

</body>
</html>

Nota: fn: função split retorna uma string com a divisão delimitador especificado em uma matriz de sub-string.

Os resultados são como se segue:

字符串为 : www-w3big-com

JSP Standard Tag Library JSP Standard Tag Library