<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@taglib uri="http://beehive.apache.org/netui/tags-html-1.0" prefix="netui"%>
<%@taglib uri="http://beehive.apache.org/netui/tags-databinding-1.0" prefix="netui-data"%>
<%@taglib uri="http://beehive.apache.org/netui/tags-template-1.0" prefix="netui-template"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page import="com.bea.content.*" %>
<netui:html>
<head>
<netui:base/>
</head>
<netui:body>
<!-- for loop to display all the items -->
<table border="1">
<tr>
<td>Title</td>
<td>Author</td>
<td>E-mail</td>
</tr>
<c:forEach var="node" items="${pageFlow.currentPage}">
<c:set var="nodeValue" scope="page" value="${node}"/>
<%
Node node= (Node)pageContext.getAttribute("nodeValue");
Property titleProp = node.getProperty("Title");
%>
<tr>
<td><c:if test="<%=titleProp != null %>"><%=titleProp.getValue().getStringValue()%></c:if></td>
<td></td>
<td></td>
</tr>
</c:forEach>
</table>
</netui:body>
</netui:html>使用forEach中的变量node:
用<c:set var="nodeValue" scope="page" value="${node}"/>将变量"node" set 到pageContext中,再通过pageContext.getAttribute("nodeValue");获得。
<%
Node node= (Node)pageContext.getAttribute("nodeValue");
Property titleProp = node.getProperty("Title");
%>
注意:在set 标签中,如果属性scope="request"即通过request.getAttribute("nodeValue");获得,如果scope="session"即通过request.getSession().getAttribute("nodeValue");获得。

本文介绍了一种使用JSP与JSTL标签库进行页面内容展示的方法,特别是如何利用<c:forEach>标签循环遍历并显示数据集合中的每一项。此示例还展示了如何设置和获取页面上下文中的变量。

5064





