你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

Java Web实战详细教程(二十四)JSTL标签和EL表达式实战

2021/12/22 23:15:27

        在上一篇文章中,我们讲解了JSTL标签和EL表达式的用法,本篇文章,我们将所学的知识运用到贯穿项目中。
        将以下学生展示界面的JSP替换成JSTL和EL。
在这里插入图片描述
其中EL表达式是Java Web自带的,JSTL需要加入jar包,需要在lib下加入jstl.jar。
在这里插入图片描述
在要使用JSTL的页面引入核心库:

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

构建表格:

<table id="data" class="table table-striped table-bordered">
			<tr>
				<th>ID</th>
				<th>姓名</th>
				<th>性别</th>
				<th>年龄</th>
			</tr>
		<c:forEach items="${list}" var="stu">
			<tr class="stu">
				<td>${stu.id }</td>
				<td>${stu.name }</td>
				<td>${stu.gender }</td>
				<td>${stu.age }</td>
			</tr>
		</c:forEach>
		</table>