Although the beans are indeed bound to local variables, that is not the only behavior. They are also stored in one of four different locations, depending on the value of the optional scope attribute of jsp:useBean. The scope attribute has the following possible values: page, application, session, request.

The sample below shows the usage of a bean in topmost scope - application. The beas is used there to track count of page access. During this the firstPage property of that bean is set in to ways: once the bean is constructed its value is set to initial one; then its value is modified with each page link activation:

Simple bean to illustrate sharing beans through use of the scope attribute of jsp:useBean.

public class AccessCountBean {
  private String firstPage;
  private int accessCount = 1;

  public String getFirstPage() {
    return firstPage;

  public void setFirstPage(String page) {
    firstPage = page;

  public int getAccessCount() {
    return accessCount;

////////////// here is the code for one of the pages sharing that bean;
////////////// the rest pages will have quite the same contents except 
////////////// their titles:

<%@page language="java"%>

    <title>Shared Access Counts: Page 1</title>

  <jsp:useBean id="counter" class="test.AccessCountBean" 
    <jsp:setProperty name="counter" property="firstPage" 
    <table border=align="center">
      <tr><th>Shared Access Counts: Page 1</th></tr>
      Of SharedCounts1.jsp (this page),
      <a href="SharedCounts2.jsp">SharedCounts2.jsp</a>
      , and
      <a href="SharedCounts3.jsp">SharedCounts3.jsp</a>
      <jsp:getProperty name="counter" property="firstPage"/>
      was the first page accessed.
      Collectively, the three pages have been accessed
      <jsp:getProperty name="counter" property="accessCount"/>