# LAB-5558: Developing Revolutionary Web Applications, Using Ajax Push or Comet

Expected Duration: 120 minutes
Contacts: Carol McDonald Doris Chen Justin Bolter

Introduction | Exercise 0 | Exercise 1 | Exercise 2 | Exercise 3 | Exercise 4 | Summary
Prerequisites System Software Notations Exercises Resources Questions Last Updated: May 11th, 2009 Join the asynchronous Web revolution! Emerging Ajax techniques -- variously called Ajax Push, Comet, and HTTP streaming -- are bringing revolutionary changes to Web application interactivity, moving the Web into the Participation Age. Because Ajax-based applications are almost becoming the de facto technology for designing Web-based applications, it is more and more important that such applications react on the fly, to both client and server events. Ajax can be used to enable the browser to request information from the Web server but does not allow a server to push updates to a browser. Comet solves this problem. It is a technology that enables Web servers to asynchronously push events to Web clients, enabling event driven operations and functions, previously unheard of with traditional Web applications, to approach the capabilities of desktop applications. In this lab, you will use NetBeans IDE to rapidly develop rich web application and then you will use Glassfish Application server to deploy the application. This lab provides an brief introduction to the asynchronous web, AJAX polling, long polling, and Streaming, explaining the Bayeux protocol, Cometd, Grizzly Comet implementation on GlassFish. Different approaches and best practices to develop comet application will also be discussed. You will learn how to develop the chat application, how to implement distance learning slideshow application, how to access Restful web services and database, how to manage a chat application from the server and how to develop a two-player distributed game application. Attendees will take away the tactics they need in order to add multiuser collaboration, notification and other Comet features to their application, whether they develop with Dojo, jQuery, jMaki, or Prototype and whether they deploy on Jetty, Tomcat, or the GlassFish Application Server. Copyright
    Copyright  2009 Sun Microsystems, Inc. All rights reserved. Sun, Sun Microsystems,
    the Sun logo, Solaris, Java, the Java Coffee Cup logo, JavaOne, the JavaOne logo,
    and all Solaris-based and Java-based marks and logos are trademarks or registered
    trademarks of Sun Microsystems, Inc. in the United States and other countries.
### Prerequisites This hands-on lab assumes you have some basic knowledge of, or programming experience in, the following technologies: Java™ language programming Exposure to AJAX, Java Script programming preferred ### System Requirements Supported OSes: Solaris™M 8/9/10 Operating System (OS), OpenSolaris™ Operating System (OS), Linux, Windows, Mac OS X 10.4+ Memory requirement: 512MB Disk space requirement: 650-750 MB depends on the OS. See the requirement for more detail. ### Software Needed For This Lab Please install the following set of software. If you have any questions on installation, please feel free to send questions to the lab forum mentioned below. A Java SE software installation, version 1.6.0 or more recent NetBeans IDE 6.5.1 and above. GlassFish v3 version glassfish-v3-ea-b44.zip ### Notations Used in This Documentation `<lab_root>` - directory into which lab zip file is unzipped This document uses `<lab_root>` to denote the directory under which you have unzipped the lab zip file of this hands-on lab. The name of the lab zip file of this hands-on lab is 5558_cometajax.zip. Once you unzipped the lab zip file under `<lab_root>`, it will create a subdirectory called cometajax. For example, under Solaris, if you have unzipped the lab zip file in the /home/dant directory, it will create /home/dant /cometajax directory. This lab will use multiple Firefox profiles. Instructions to set this up are in Exercise 0. FOR JAVAONE 2009 MACHINE PROVIDED LABS: We have setup the profiles for you already. To launch Firefox, open a terminal window and type the command: `ff` Then select User 1 or User 2 depending on if this is the first or second browser you are opening. The lab machines are running Java Desktop System over Solaris 10 In order to open a terminal window in Java Desktop System, right click any point in the background of the desktop, and select Open Terminal in the pop-up menu. The following source code editors are provided on the lab machines vi (type vi in a terminal window) emacs (type emacs in a terminal window) jedit (type jedit in a terminal window) NetBeans IDE (either click NetBeans IDE icon or type netbeans in a terminal window) ### Lab Exercises Exercise 0: Install and configure the lab environment (10 minutes) Exercise 1: Build a comet chat application (20 minutes) Exercise 2: Build a comet slideshow application (20 minutes) Exercise 3: Server Interact with Chat Application (20 minutes) Exercise 4: Build a two way tic-tac-toe game (40 minutes) ### Additional Resources Lab presentation Cometd framework and its Bayeux protocol support in Grizzly – Jean-Francois Arcand's blog Using the Grizzly Comet API – Sun document on developing web applications Dojo Toolkit – Dojo home page dojo.cometd – Cometd.org page at the Dojo Foundation Grizzly – Project Grizzly home page GlassFish Application Server – home page for the GlassFish Community The Aquarium – news from the GlassFish Community ### Where To Go For Help For general questions and feedback on JavaOne Hands-On Labs, please use the JavaONE_HOL_Forum. You can send your questions about grizzly and comet to the grizzly public users alias: users@grizzly.dev.java.net Back to top To exercises | ### Related Resources Java SE for Business Compatibility Performance Security Mobility Timezone Updates ##### Related Downloads XML and Web Services Java Media Framework ##### Popular Topics JDK 6 Adoption Guide Java Platform Migration Guide Garbage Collection Tuning Troubleshooting Java SE ##### Sun Resources BigAdmin (sysadmin resources) Sun Web Learning Center Java Training ##### Related Sites java.com java.net NetBeans Java EE SDK OpenJDK Project Open-Source Java Project ### Getting Started? New to Java Center Java Tutorial: Getting Started Tutorials Java SE Training