常規寫法
<%
response.setCharacterEncoding("GB2312");
ArrayList student = (ArrayList)request.getAttribute("list");
int size = student.size();
for(int i = 0;i<size;i++)
{
Student stu = (Student)student.get(i);
out.println("SID="+stu.getSid());
out.println("SName="+stu.getSname());
out.println("Score="+stu.getScore());
}
%>
將以上代碼片段用JSTL改寫:
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<body>
<table>
<c:forEach var="stu" items="${list}">
<tr>
<td>
SID=${stu.sid}
</td>
<td>
SName=${stu.sname}
</td>
<td>
Score=${stu.score}
</td>
</tr>
</c:forEach>
</table>
</body>
</html>