End-to-End J2ME Application Development by Ex…

2008-02-23 10:11:28来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

Overview

The first Java technology blueprint, Java Pet Store, was released in 2001 as a showcase for Sun's J2EE technologies. The blueprint not only provides sample code for a multilayered, database-driven e-commerce application, it also furnishes design guidelines and demonstrates commonly used patterns. Since that first release, the Java blueprints have become one of the most important resources for developers wanting to learn the latest J2EE technologies and best practices.

The Smart Ticket blueprint adds a new dimension: mobility. It demonstrates how to build a complete end-to-end mobile commerce system for ordering movie tickets, using J2ME MIDP for a wireless front end and a J2EE application server and a relational database at the back end. Studying how this application is designed and built will greatly enhance your understanding of the problems of mobile entERPrise applications – and their solutions.

This article covers version 2.0 Early Access of the Smart Ticket code, released in April 2003. The screen shots and code samples in the early-access version may change slightly in the final release, but the lessons you learn from the design should still hold. Smart Ticket 1.2 is still available. It has the same model and back-end implementation as the version discussed here, so many of the details are applicable to both past and future releases. Unless otherwise noted, all source code in this article is copyrighted by Sun Microsystems.

Download and Installation

The Smart Ticket application is available from Sun's Blueprints web site. The .zip archive contains source code, Ant build scripts, and pre-built, deployable applications.

Smart Ticket contains a J2ME component and a J2EE component. Running it requires a J2EE application server (such as the Sun J2EE reference implementation, version 1.3 or higher), and either a MIDP 2.0-compatible device with Internet connectivity or a suitable emulator, such as the one in Sun's J2ME Wireless Toolkit 2.0. The Smart Ticket distribution contains specific instructions for building and deploying the application. To get started:

  1. Make sure you have these resources installed:

    • JDK v1.4.1 or higher
    • J2EE v1.3.1 or higher
    • J2ME Wireless Toolkit 2.0 or higher

  2. Set the following environment variables:

    • JAVA_HOME: JDK installation directory
    • J2EE_HOME: J2EE RI installation directory
    • J2MEWTK_HOME: J2ME Wireless Toolkit installation directory

  3. Start the J2EE server:

    J2EE_HOME/bin/cloudscape -start
    
    J2EE_HOME/bin/j2ee -verbose
    
    

  4. Deploy the J2EE application. Use the setup script as follows to invoke the deploy Ant task in setup.XML:

    setup deploy
    
    

  5. Point your browser to http://localhost:8000/smartticket and click on the Populate Database link to import mock theater and movie data into the database. This is a very slow process on older computers, so be patient! The mock data includes theaters in two Zip codes: 95054 and 95130.

  6. Start J2ME Wireless Toolkit 2.0 and run the MIDlet described in smart_ticket-client.jad.

Smart Ticket in Action

When you have the MIDlet running, take a brief tour to get the user's perspective. You'll find you can perform four kinds of tasks.

  • Manage user preferences: When you start the MIDP client for the first time, you'll be asked to create a profile with a username, password, preferred Zip codes for theater search, preferred day of the week and, optionally, credit-card numbers. Smart Ticket uses the account credentials to create a user account on the server side, and caches the preference data on the device. You could also configure the MIDP client to cache the credentials so that you don't need to sign in manually every time you want to purchase tickets or submit movie ratings. You can modify user preferences at any time.

    (Click image to enlarge.)
  • Search for films and purchase tickets: Once you've logged in, you can search among theaters, movies, and show times that reflect your preference data. Once you select a show, the MIDlet presents a seating map that shows available seats. This process involves a series of real-time queries to the J2EE server. Taking advantage of MIDP's rich UI, you can select a seat and make a reservation. The reservation is written to the server database and will be reflected on the seating map in the next search.

    标签:

    版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
    特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Hibernate实践(二)

下一篇:无线开发教程第一部分-从MIDlet开发开始