JSTL标准标签库 (使用foreach打印集合)

时间:2023-03-09 07:21:07
JSTL标准标签库 (使用foreach打印集合)

<%@page import="java.util.*"%>
<%@ page language= "java" contentType="text/html;charset=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>
        <meta charset="utf-8">
        <title>使用foreach</title>
    </head>
    <body>
        <%
        List list = new ArrayList();
        
        list.add("zhangsan1");
        list.add("zhangsan2");
        list.add("zhangsan3");
        list.add("zhangsan4");
        list.add("zhangsan5");
        
        request.setAttribute("all", list);
        
        
        pageContext.setAttribute("info", "nihao lovo, hello");
        %>
        <c:forEach items="${all}" var="mement">${mement}</c:forEach>
        
        <h3>查找lovo:${fn:contains(info,"lovo")}</h3>
        <h3>判断开头:${fn:startsWith(info,"lovo")}</h3>
        <h3>判断结尾:${fn:endsWith(info,"hello")}</h3>
        <h3>查找位置:${fn:indexOf(info,",")}</h3>
        
        
    </body>
</html>