Browse Source

Using JSTL for servlet test

Patrick Falls 12 years ago
parent
commit
c9e166c503
2 changed files with 12 additions and 5 deletions
  1. 5 0
      servlet/pom.xml
  2. 7 5
      servlet/src/main/webapp/WEB-INF/jsp/fortunes.jsp

+ 5 - 0
servlet/pom.xml

@@ -23,6 +23,11 @@
             <version>2.1.2</version>
         </dependency>
 
+	<dependency>
+	  <groupId>jstl</groupId>
+	  <artifactId>jstl</artifactId>
+	  <version>1.2</version>
+	</dependency>
         <!-- @Inject -->
         <dependency>
             <groupId>javax.inject</groupId>

+ 7 - 5
servlet/src/main/webapp/WEB-INF/jsp/fortunes.jsp

@@ -1,3 +1,4 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 <%@ page import="hello.*,
                  java.util.*" %><%@ page session="false" %><%
 
@@ -15,10 +16,11 @@ List<Fortune> fortunes = (List)request.getAttribute("fortunes");
 <th>id</th>
 <th>message</th>
 </tr>
-<% for (Fortune fortune : fortunes) { %><tr>
-<td><%= fortune.getId() %></td>
-<td><%= Common.render(fortune.getMessage()) %></td>
+<c:forEach var="o" items="${fortunes}">
+<tr>
+<td><c:out value="${o.getId()}" /></td>
+<td><c:out value="${o.getMessage()}" /></td>
 </tr>
-<% } %>
+</c:forEach>
 </table></body>
-</html>
+</html>