JavaServer Page

October 24, 2006

616 CHAPTER 15 USING STRUTS, XDOCLET, AND

Filed under: JavaServer Page — webmaster @ 3:26 am

CHAPTER 15 USING STRUTS, XDOCLET, AND OTHER TOOLS 617 The UserCounterController is simply grabbing an attribute out of the application scope and putting it into the request scope. However, you could easily add more complex logic in this method. In this example, you re storing the attribute in the request attribute for simplicity, but it could also be stored in the ComponentContext using the following code: tilesContext.putAttribute(UserCounterListener.COUNT_KEY, userCounter); This would ensure that the attribute was only available for this tile. To configure struts-resume to use this controller, we edited tiles-config.xml file (in web/WEB-INF). We decided we wanted to display this Current Users counter in the header of the page and since we only defined the header in the “baseLayout” definition, this was an easy change. Before the change, the header tile was simply pointing to the header.jsp file:
To make the header tile controller-enabled, we created a new definition for it and pointed to it from the baseLayout definition:
This means that for each page that the “.header.userCount” tile appears on, UserCounterController.perform() will be called. To display the counter in the header.jsp, we then added the following JSP code: < %-- Check to ensure "userCounter" is in request, if not, don't display --%>

:

To test it, we logged in to the struts-resume application with two different browsers, which created two different sessions. After the sessions were created, the User Counter text in the header (see Figure 15-14) shows that there are currently two users active in the application. We realize this may not be a precise count, but it s about as accurate as it gets with web applications.

Note: If you are looking for good and high quality web space to host and run your jsp application check Lunarwebhost jsp web hosting services

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.

Powered by Java Web Hosting