springmvc使用JSTL标签库

今天使用SpringMvc,在页面上用JSTL来做标签库进行解析,方法是:

在JSP页面上引入<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

在pom.xml中引入JAR包:

            <dependency>  
                <groupId>javax.servlet</groupId>  
                <artifactId>jstl</artifactId>  
                <version>1.2</version>  
                <scope>runtime</scope>  
            </dependency>  
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>

注意不要引错包,不要写成

        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

也不要servlet-api.jar jsp-api.jar这些jar包

在jsp头添加<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

4、使用<c:foreach>标签

<c:forEach var="user"  items="${users}" >

     <tr><td>${user.userName }</tr>

</c:forEach>

注:在controller中已经把list集合set到httpServletRequest中了,c标签中直接取就行 req.setAttribute("users", list);

原文地址:https://www.cnblogs.com/htys/p/3769620.html