testattr.jsp

来自「webwork source」· JSP 代码 · 共 54 行

JSP
54
字号
<%@ taglib uri="webwork" prefix="webwork" %>
<%@ page import="java.util.ArrayList, javax.servlet.http.Cookie" %>
<html>
<body>
<%
  // this scriptlet sets up an ArrayList of JavaBeans and puts it into a page-scoped attribute
  // I'm using Cookies as JavaBeans...
  ArrayList beanList = new ArrayList();
  for (int i = 0; i < 20; i++) {
    Cookie cookie = new Cookie("cookie" + i, String.valueOf(i));
    beanList.add(cookie);
  }
  pageContext.setAttribute("beanList", beanList);
%>
<p>
A scriptlet builds an ArrayList of Cookies and inserts it into the current page as an attribute named "beanList"...
</p>
<p>
Prints the ArrayList using <code>&lt;%= pageContext.getAttribute("beanList") %&gt;</code>:
<br>
<h5><%= pageContext.getAttribute("beanList") %></h5>
</p>
<br>
<p>
Prints the ArrayList using <code>&lt;webwork:property value="@beanList" /&gt;</code>:
<br>
<h5><webwork:property value="@beanList" /></h5>
</p>
<br>
<p>
Prints the first element of the ArrayList using <code>&lt;%= ((ArrayList)pageContext.getAttribute("beanList")).get(0) &gt;</code>:
<br>
<h5><%= ((ArrayList)pageContext.getAttribute("beanList")).get(0) %></h5>
</p>
<br>
<p>
Prints the first element of the ArrayList using <code>&lt;webwork:property value="@beanList[0]" /&gt;</code>:
<br>
<h5><webwork:property value="@beanList[0]" /></h5>
</p>
<br>
<p>
Prints the name of the first element of the ArrayList using <code>&lt;%= ((Cookie)((ArrayList)pageContext.getAttribute("beanList")).get(0)).getName() &gt;</code>:
<br>
<h5><%= ((Cookie)((ArrayList)pageContext.getAttribute("beanList")).get(0)).getName() %></h5>
</p>
<br>
<p>
Prints the name of the first element of the ArrayList using <code>&lt;webwork:property value="@beanList[0]/name" /&gt;</code>:
<br>
<h5><webwork:property value="@beanList[0]/name" /></h5>
</p>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?