Brief introduction
In recent years, the trend of WEB application development has been the creation of rich Internet applications, most of which are implemented using asynchronous JavaScript + XML (Ajax). However, because writing JavaScript code is complex, this approach is not easy, especially when it is difficult to build large Web applications. So there's GWT: it allows us to build a rich, responsive WEB interface using Java programming instead of Ajax. GWT also offers all the benefits of Java development, such as excellent IDE support and advanced debugging capabilities. GWT can significantly improve productivity and enrich the user experience. In this article, I'll explain how to build a GWT application in Eclipse, and how to use the GWT tree and TreeItem widget to create a University Corporation of atmosphere Study (UCAR) Sample organizational structure. I want to explain how to implement lazy mounts, how to integrate with RESTful Web services, and how to implement GWT callback and custom exceptions. Use JSON as the data format for the RESTful Web service.
Software Requirements
First, you need to download the following packages and install them according to the installation Guide on the appropriate Web site.
Eclipse IDE for Java EE developers Galileo (Eclipse 3.5)
GWT 2.0
GWT Plug-in for Eclipse
MySQL 5.1 or Db2®express-c
Tomcat 6.x
RESTful Web Services
The RESTful WEB Service provides organization data for GWT clients. In this article, I don't discuss steps to implement the RESTful Web service; you just set up the database and deploy the WAR file to a Tomcat server. You may also need to modify several database properties in the configuration file, such as the database host, login name, and password.
Setting up the database
I use MySQL Community Server 5.1 as the database for this article. However, you can also use other databases such as DB2 express-c to download and install it on the host you choose (if you haven't done so yet). Then create the database gwtresttutorial and user gwtresttutorial, the password is gwtresttutorial. Connect the Gwtresttutorial database and log in as a gwtresttutorial. Download the SQL script from the download section, run the script to create the table, and insert the data in the table.
For the RESTful WEB service server to connect DB2 express-c or other DB2 series databases, the configuration used is very similar to the MySQL configuration in Listing 1, with the following modifications:
Use Com.ibm.db2.jcc.DB2Driver as Driverclassname.
Use jdbc:db2://
Copy the Db2jcc.jar and Db2jcc_license_cu.jar files from the DB2 express-c installation directory to the Web-inf/lib directory.
You may need to modify the downloaded Setup.sql script instead of the DB2 syntax.
Deploy the WAR file to a Tomcat server
Download the WAR file from the download section and save it to the Tomcat folder <tomcat_home>/webapps, where Tomcat_home is where the Tomcat server is installed.
After you deploy the war file to the <tomcat_home>/webapps directory, if the TOMCAT server is running, it extracts the war file into the Gwtresttutorial folder. Check <tomcat_home>/webapps/gwtresttutorial/web-inf/classes/applicationcontext.xml (listing 1) to ensure that the DataSource bean The configuration value matches the value used by the MySQL database. Note that if you make any modifications, you may need to restart the Tomcat server.
Listing 1. Configuring DataSource Beans in Applicationcontext.xml
1. <bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"& gt;
2. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
3. <property name="url" value="jdbc:mysql://localhost:3306/gwtresttutorial"/>
4. <property name="username" value="gwtresttutorial"/>
5. <property name="password" value="gwtresttutorial"/>
6. </bean>