📄 testattr.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><%= pageContext.getAttribute("beanList") %></code>:
<br>
<h5><%= pageContext.getAttribute("beanList") %></h5>
</p>
<br>
<p>
Prints the ArrayList using <code><webwork:property value="@beanList" /></code>:
<br>
<h5><webwork:property value="@beanList" /></h5>
</p>
<br>
<p>
Prints the first element of the ArrayList using <code><%= ((ArrayList)pageContext.getAttribute("beanList")).get(0) ></code>:
<br>
<h5><%= ((ArrayList)pageContext.getAttribute("beanList")).get(0) %></h5>
</p>
<br>
<p>
Prints the first element of the ArrayList using <code><webwork:property value="@beanList[0]" /></code>:
<br>
<h5><webwork:property value="@beanList[0]" /></h5>
</p>
<br>
<p>
Prints the name of the first element of the ArrayList using <code><%= ((Cookie)((ArrayList)pageContext.getAttribute("beanList")).get(0)).getName() ></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><webwork:property value="@beanList[0]/name" /></code>:
<br>
<h5><webwork:property value="@beanList[0]/name" /></h5>
</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -