Java/JSP/Bean Scope
Версия от 18:01, 31 мая 2010; (обсуждение)
Содержание
Using Beans and Page Scope
<HTML>
<HEAD>
<TITLE>Using Beans and Page Scope</TITLE>
</HEAD>
<BODY>
<H1>Using Beans and Page Scope</H1>
<jsp:useBean id="bean1" class="beans.Counter" scope="page" />
<%
bean1.setCounter(bean1.getCounter() + 1);
%>
The counter value is: <jsp:getProperty name="bean1" property="counter" />
</BODY>
</HTML>
Using Beans and Session Scope
<HTML>
<HEAD>
<TITLE>Using Beans and Session Scope</TITLE>
</HEAD>
<BODY>
<H1>Using Beans and Session Scope</H1>
<jsp:useBean id="bean1" class="beans.Counter" scope="session" />
<%
bean1.setCounter(bean1.getCounter() + 1);
%>
The counter value is: <jsp:getProperty name="bean1" property="counter" />
</BODY>
</HTML>
Using Bean Scope Application
<%@ page errorPage="errorpage.jsp" %>
<jsp:useBean id="counter" scope="application" class="beans.Counter" />
<html>
<body>
<center><b>The current count for the counter bean is: </b>
<%=counter.getCount() %></center>
</body>
</html>
Using Bean Scope Page
<%@ page errorPage="errorpage.jsp" %>
<jsp:useBean id="counter" scope="page" class="beans.Counter" />
<html>
<head>
<title>Page Bean Example</title>
</head>
<body>
<H3>Page Bean Example</H3>
<center><b>The current count for the counter bean is: </b>
<%=counter.getCount() %></center>
</body>
</html>