TAILIEUCHUNG - Bắt đầu với IBM Websphere smash - p 8

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

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.