Sun Java Solaris Communities My SDN Account Join SDN
 
Tutorials & Code Camps

jGuru: Help: Understanding JSP Object Scope

 


[Exercise | API Docs | Short Course| Exercises]

Help is available for each task.

Task 1

Develop a simple counter bean, CounterBean.java.

Develop a bean which can maintain a count within say, an integer property. Provide at least a getter method for this property.

Task 2

Compile the counter bean.

You can compile the bean as javac CounterBean.java

Task 3

Deploy the bean within Tomcat.

Copy CounterBean.class to jakarta-tomcat\webapps\examples\WEB-INF\classes\com\jguru\CounterBean.class. You will need to create the directories below classes for the package the bean is in.

Task 4

Develop a JSP page, Counter.jsp, which creates two instances of the counter bean, one with session scope, and the other with application scope.

You can use the jsp:useBean tag for instantiating the beans. Make sure you provide the appropriate scope for the scope attribute.

Task 5

Deploy the JSP file for the example within Tomcat.

Assuming you have installed Tomcat in say, \jakarta-tomcat, copy the JSP file to \jakarta-tomcat\webapps\examples\jsp\jdc\counter\Counter.jsp

Task 6

Run the example.

From your browser (say, Netscape Navigator), access the URL http://localhost:8080/examples/jsp/jdc/counter/Counter.jsp

Now, start up a different browser (say, MSIE) access the URL http://localhost:8080/examples/jsp/jdc/counter/Counter.jsp

(Note: If you use only MSIE, you can simply double click on the browser icon again to run a second instance of MSIE as a separate process. This is important to ensure that the browser creates a new session and does not reuse the one created by an earlier instance.)

Click a few times within both browser to increment the counters for the beans with session and application scope. Observe the difference between the twocounts.

Copyright 1996-2000 jGuru.com. All Rights Reserved.