Java Reference
In-Depth Information
16
L ISTING 16.1
Continued
// Parameterless Constructor
public Counter() {
}
// Property Getter
public int getCount() {
// Increment the count property, with every request
count++;
return this.count;
}
// Property Setter
public void setCount(int count) {
this.count = count;
}
}
Now that you have defined your bean, let's look at how to integrate it into a JSP. Listing 16.2
contains the JSP that will use the Counter bean.
L ISTING 16.2
BeanCounter.jsp
<HTML>
<HEAD>
<TITLE>JSP Bean Example</TITLE>
</HEAD>
<BODY>
<!-- Set the scripting language to java -->
<%@ page language=”java” %>
<%@ page import=”Counter” %>
<!-- Instantiate the Counter bean with an id of “counter” -->
<jsp:useBean id=”counter” scope=”session” class=”Counter” />
<!-- Set the bean's count property to the value of -->
<!-- the request parameter “count”, using the -->
<!-- jsp:setProperty action. -->
<jsp:setProperty name=”counter” property=”count” param=”count” />
 
Search WWH ::




Custom Search