Java Reference
In-Depth Information
cart. For our example, you will use the Counter bean and two almost identical JSPs. Each JSP
creates an instance of your bean and prints out the current value of the count property. The
two JSPs can be found in Listings 17.5 and 17.6, respectively.
L ISTING 17.5
SessionBean1.jsp
<%@ page errorPage=”errorpage.jsp” %>
<!-- Instantiate the Counter bean with an id of “counter” -->
<jsp:useBean id=”counter” scope=”session” class=”Counter” />
17
<html>
<head>
<title>Session Bean Example 1</title>
</head>
<body>
<H3>Session Bean Example 1</H3>
<center><b>The current count for the counter bean is: </b>
<%=counter.getCount() %></center>
</body>
</html>
L ISTING 17.6
SessionBean2.jsp
<%@ page errorPage=”errorpage.jsp” %>
<!-- Instantiate the Counter bean with an id of “counter” -->
<jsp:useBean id=”counter” scope=”session” class=”Counter” />
<html>
<head>
<title>Session Bean Example 2</title>
</head>
<body>
<H3>Session Bean Example 2</H3>
<center><b>The current count for the counter bean is: </b>
<%=counter.getCount() %></center>
</body>
</html>
You can see that the only difference between these two JSPs is the values of the HTML
<title> and <h3> tags.
 
Search WWH ::




Custom Search