JavaSercer Pages The bean used in this example, the com.ora.jsp.beans.counter.CounterBean, keeps a separate counter for each page where it’s used. It’s a class with just one method: public int getNextValue(String uri); The method increments the counter for the page identified by the uri argument and returns the new value. In Example 8.4, two actions are used to create one bean each for the session and application scopes. The bean placed in the session scope is found every time the same browser requests this page, and therefore counts hits per browser. The bean in the application scope, on the other hand, is shared by all users, so it counts the total number of hits for this page. A scriptlet is used to ask the request object for the URI of the current page. The URI is then passed as an argument to the bean’s getNextValue( ) method. A page is uniquely identified by its URI, so the bean uses the URI as a unique identifier to represent the counter it manages for each page. If you run this example, you should see a page similar to Figure 8.5. Figure 8.5. A page with session and application page hit counters As long as you use the same browser, the session and application counters stay in sync. But if you exit your browser and restart it, a new session is created when you access the first page. The session counter starts from 1 again but the application counter takes off from where it was at the end of the first session. Note that the bean described here keeps the counter values in memory only, so if you restart the server, both will start from 0 again. page 94
Hint: If you are looking for good and high quality web space to host and run your java application check Vision java web hosting services
This entry was posted
on Thursday, December 14th, 2006 at 11:40 am and is filed under Java.
You can follow any responses to this entry through the RSS 2.0 feed.
Responses are currently closed, but you can trackback from your own site.