The Ajax: Hello! Sample application for the server is also simple. The server implements services that the client side calls. There are two services the client side accesses. The first service is a Greeter service. The Greeter service reads messages sent from the client as a POST request. The second service is a servlet that handles GNU zip (GZIP) compression of files. The second service is accessed indirectly and is used only to compress the Dojo files that are returned from the server during application load. The second service is not necessary for the application to work, but was included as a simple example of techniques that can be used to improve performance of Web applications that load several files across the network. Since GZIP compresses text and most browsers support GZIP compressed content transparently, it is included as an example performance enhancer.
The greeter service is a basic servlet. It is designed to read in a JavaScriptTM Object Notation (JSON) formatted text string, and parse it into a JSONObject. Values are then accessed from the JSON Object. The servlet then takes these values and inserts them into a string. This string is then passed into a new JSONObject as a property named reply. The response JSONObject is then serialized into JSON formatted text and included as the body of the HTTP response. The source code for the service is available in the AjaxHello.ear file. Refer to the section on viewing source code for more information.
The compression service is an optional service that is used in the example application as a method for improving application load performance. When a HTTP request comes to the server that matches the patterns mapped to the servlet, the compression service looks at the request headers. If the request headers state it can support GZIP and other conditions are matched then the compression service locates the requested file in the Web archive and compresses it with a GZIP stream before sending the contents back to the requesting browser. The source code for the service is available in the AjaxHello.ear file. Refer to the section on viewing source code for more information.