开发人员可以利用这些标签取代JSP页面上的Java代码,从而提高程序的可读性,降低程序的维护难度。
条件一:要在JSP页面中使用JSTL标签,需使用taglib指令引用标签库。
例如使用C标签库 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
条件二:Jstl包和standard包。
maven依赖pom.xml配置下载包:
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
或者直接下载这俩包,再导入。
JSTL和EL表达式遍历List集合:
<c:forEach items="${requestScope.studentlist}" var ="student">
<tr>
<td>${student.name}</td>
<td>${student.sex}</td>
<td>${student.age}</td>
</tr>
</c:forEach>