Run:
  JspScopeListener
   

View:
scope.jsp
  listener source
 
 

 

JspScopeListener Sample

This sample illustrates using a JspScopeListener to allow JSP objects attached to scope to be notified when they are going "out of scope". The sample implements a generic listener that redispatches the "out of scope" notification to the registers object/method. In using this listener object, scope.jsp is able to simulate page event handlers for request and page "out of scope" notification.

This sample creates and attaches a listener object to the request and page scopes. It registers local methods to handle "out of scope" notifications forwarded by the listener. To illustrate this, the sample keeps two counters. The first is a page count. The second counts the number of included files. The current page count is logged when the page goes out of scope. The included page count is logged when the request goes out of scope. The sample then proceeds to include itself five times.

After running the sample you will need to check your server's log to see the output/results. On some systems the log goes to the console. You should see 6 messages indicating a page count of 1 followed by a single message indicating 5 includes occurred.