JSTL
를 이용 -> Java 코드를 없애기 위한 태그를 이용한 제어구조로 변경<%
List<Notice> list = (List<Notice>)request.getAttribute("list");
for(Notice notice : list) {
pageContext.setAttribute("notice", notice);
%>
<tr>
<td>${notice.id }</td>
<td class="title indent text-align-left"><a href="detail?id=${notice.id }">${notice.title }</a></td>
<td>${notice.writer_id }</td>
<td>${notice.hit }</td>
<td>${notice.files }</td>
</tr>
<% } %>
<c:forEach var="notice" items="${list}">
<tr>
<td>${notice.id }</td>
<td class="title indent text-align-left"><a href="detail?id=${notice.id }">${notice.title }</a></td>
<td>${notice.writer_id }</td>
<td>${notice.hit }</td>
<td>${notice.files }</td>
</tr>
</c:forEach>
다운로드
MavenRepositoryWebContent/WEB-INF/lib 경로에 JSTL.jar를 넣어준다.
디렉티브 설정
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
제어 담당
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:forEach var="notice" items="${list}">
<tr>
<td>${notice.id }</td>
<td class="title indent text-align-left"><a href="detail?id=${notice.id }">${notice.title }</a></td>
<td>${notice.writer_id }</td>
<td>${notice.hit }</td>
<td>${notice.files }</td>
</tr>
</c:forEach>
c:
->prifix="c"
: 식별자 ->http://java.sun.com/jsp/jstl/core
<http://java.sun.com/jsp/jstl/core:forEach>
</forEach>
<c:forEach>
</forEach>
public class ForTag extends TagSupport {
....
}
Servlet / JSP