52 Chapter 3 Your First Handler and Beyond Event Handling in Java When performance is important, Java can be used in place of Groovy for event handling. We discuss Java in more detail in later chapters, but the pattern is similar to Groovy and PHP. You need to create a class with a null constructor to handle the requests, with naming corresponding to the resource. So, we could create java/ like Listing . Listing Java Event Handler public class Bookmarks { public void onGET() { . } public void onPOST() { . } public void onPUT() { . } public void onDELETE() { . }. | 52 Chapter 3 Your First Handler and Beyond Event Handling in Java When performance is important Java can be used in place of Groovy for event handling. We discuss Java in more detail in later chapters but the pattern is similar to Groovy and PHP. You need to create a class with a null constructor to handle the requests with naming corresponding to the resource. So we could create java like Listing . Listing Java Event Handler public class Bookmarks public void onGET . public void onPOST . public void onPUT public void onDELETE Creating a Client So far we ve covered the basics of creating a simple RESTful service. What we need now is a client that end users can use. Earlier we used Poster which is quite useful for unit testing our services. However for some odd reason end users are not usually very happy formulating JSON messages in Poster. If we were to release our application with Poster as the front-end client the Human-Computer Interaction people would probably faint. We can create our user interface using three primary technologies Groovy Templates PHP and Dojo. Earlier in this chapter we learned that as part of the application directory structure there are a few client-oriented directories. Of particular interest at this point is the public directory. Groovy Templates Using Groovy templates we can create a client that accesses the RESTful service on the server side. Groovy templates are very much like JSPs. They embed Groovy code inside HTML. Groovy script elements are surrounded by and and expression elements by and . In the public directory create a file named . We ll start by simply displaying the contents of our bookmark database. To do this we start by calling the GET method on a connection to our service as shown in Listing . Download from Creating a Client 53 Listing Calling the GET Method resp http localhost 8080 resources bookmarks This connection retrieves a