⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testattr.jsp

📁 webwork source
💻 JSP
字号:
<%@ 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -