In order to illustrate the effects of components having global scope, let’s return to our original example of a component being modified by a form, but this time we’ll create a new component named /test/service/NewPerson. We’ll also create two new JavaServer Pages named person.jsp and entry.jsp. The entry.jsp page presents a form in which you can submit the name and age properties, while the person.jsp page displays the values of those properties.

Here is entry.jsp:

<%@ taglib uri="/dspTaglib" prefix="dsp" %>
<dsp:page>

<html>
<head><title>Form Entry</title></head>
<body><h1>Form Entry</h1>

<dsp:form action="person.jsp" method="POST">
<p>Name: <dsp:input bean="/test/services/NewPerson.name" type="text"/>
<p>Age: <dsp:input bean="/test/services/NewPerson.age" type="text" value="30"/>
<p><input type=submit name=submit value="Push Me">
</dsp:form>

</body>
</html>

</dsp:page>

Here is person.jsp:

<%@ taglib uri="/dspTaglib" prefix="dsp" %>
<dsp:page>

<html>
<head><title>A Person</title></head>
<body><h1>A Person</h1>

<table border>
  <tr>
    <td>Name</td>
    <td>
      <dsp:valueof bean="/test/services/NewPerson.name">No Name</dsp:valueof>
    </td>
  </tr>
  <tr>
    <td>Age</td>
    <td>
      <dsp:valueof bean="/test/services/NewPerson.age">No Age</dsp:valueof>
    </td>
  </tr>
</table>

</body>
</html>

</dsp:page>

And here is <ATG2007.3dir>/home/localconfig/test/services/NewPerson.properties:

$class=Person
name=Bill
age=28

If you enter new property values for the NewPerson component through entry.jsp, then the component is changed as you would expect.

If you have two different browsers on your machine (such as Netscape Navigator and Microsoft Internet Explorer), try accessing the entry.jsp and person.jsp pages from the second browser. The values in the NewPerson component should change again. But now if you return to your original browser and access person.jsp, you’ll notice that the values there are the same as the values that were set by the other browser. In other words, two users on different browsers are manipulating the same component and possibly overwriting each other’s changes. Obviously, this is a problem for Internet applications that need to handle thousands of users at a time.

 
loading table of contents...