8. A collection of products is stored in the ServletContext in an attribute called catalog.
Which JSTL code structure iterates over each product in the collection and prints out the names of the products in an un-ordered list?
A. <ul>
<c:for var='product' items='${catalog]'>
<li><%=product.getName()%></li>
</c:for>
</ul>
B. <ul>
<c:for id='product' collection='${catalog]'>
<li><%=product.getName()%></li>
</c:for>
</ul>
C. <ul>
<c:forEach var='product' items='${catalog]'>
<li><%=product.getName()%></li>
</c:for>
</ul>
D. <ul>
<c:forEach id='product' collection='${catalog]'>
<li><%=product.getName()%></li>
</c:for>
</ul>
위의 문제는 올바른 forEach의 구조를 묻는 문제라고 보면 됩니다.
여기서 collection을 어떤 목록값을 가지는 배열이라고 보고 풀이해보면,
다음 JSTL 코드 구조 중에서 collection내부의 각각의 product를 반복하고, 정렬되지 않은 목록에서 products의 이름을 출력하는 것이 어느것이냐는 문제입니다.
위의 보기에서 올바른 구조는 C밖에 없으므로 답은 C입니다.
이 글은 스프링노트에서 작성되었습니다.