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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM