|By Boris Minkin||
|November 22, 2005 01:00 PM EST||
In this article I'll show you how to develop and deploy a JSP Web application with WTP in less than an hour. I'll also cover the creation and deployment of a basic servlet and editing JSP with WTP. Let's develop the WTP application together but, first, we need to install the following software:
- J2SE 5.0 JRE: http://java.sun.com/j2se
- Eclipse 3.1: www.eclipse.org
- WTP 0.7.1: www.eclipse.org/webtools
- Tomcat 5.0: http://jakarta.apache.org/tomcat/
- MySQL 4.0.25: www.mysql.com
- MySQL Connector/J Driver 3.1: www.mysql.com/products/connector/j/
Our application will be a basic Web application implementing the following use cases:
- Customers need to register on the site to place orders.
- Customers can place orders.
- Customers can view their orders.
- Admin can list all registered customers.
The system will be implemented using a servlet programming model and MySQL database.
Configuring MySQL Database and the Data Source
By default, when MySQL gets installed, a TEST database is available. Be sure to launch C:\Mysql\winmysqladmin.exe to specify the user name and password (the first time you launch it, it lets you do it and also starts the database server). It's necessary to copy MySQL Connector/J JDBC Driver: mysql-connector-java-3.1.10-bin.jar to the Tomcat/common/lib directory, so the Tomcat server can recognize it.
To configure MySQL database access in Tomcat, we have to add a separate file called Listing 1: DBTest.xml; the file follows a convention of "application_name.xml" under $TOMCAT\conf\catalina\localhost directory. The only problem with this file is that it may get deleted when the application is undeployed, so if you undeploy and redeploy the application, you have to place this file into the same folder again (so it's a good idea to save it somewhere else). Looking inside the DBTest.xml file, please note that in our case we are using "ODBC" for the username and don't provide any password.
Building Our Web Application Using Web Tools and a Database
Before we can start working on the Web project, we must configure Tomcat 5.0 in Eclipse to be our default server. When Web Tools are installed in Eclipse, new perspectives and options are added, such as a J2EE perspective where you can create J2EE projects, Web projects, and Web services. New options are available under the Window-Preferences menu for configuring Tomcat servers with Eclipse. Go to Window - Preferences menu, under Server select - Installed Runtimes, click Add, and then specify Tomcat 5.0 server with the installed JRE and a path to the Tomcat installation directory (see Figure 1). Now create a Dynamic Web Project using the Web Tools wizard by selecting File-New-Other, then expanding Web-Dynamic Web Project.
We'll name the project DBTest, which will also become its context root. The Web module will be targeted to our default server: Tomcat. Click Finish and the DBTest Web project gets created. This project will contain all of our Web resources, such as HTML and JSP files, and servlets, and you'll be able to export it into a standard WAR file later, if needed.
Creating Supporting Domain Classes and Tables
Before creating servlets, let's create supporting classes to represent a customer and an order. The class diagram in Figure 2 depicts the Customer and Order relationship.
Note that when creating Customer and Order classes, we define corresponding fields as their public instance variables and then can automatically generate getters and setters from those fields. This can be easily done by going to Outline view (appears after you double-click on an existing class name or create a new class), selecting a class, and selecting "Source - Generate Getters and Setters..." from the right-button menu (see Figure 3).
Along with the classes, we'd have to create corresponding database tables in a MySQL database:
CREATE TABLE CUSTOMER (
ID INT PRIMARY KEY,
CREATE TABLE ORDERS (
ID INT PRIMARY KEY,
CUST_ID INT REFERENCES CUSTOMER,
Creating Database Command Classes
We'll create a special package with classes that implement a Command design pattern to perform necessary database updates. The Command pattern allows the classes to implement the common interface executing some particular command. Examples of the Command pattern in Java would be classes that implement the ActionListener interface with the actionPerformed() method. Our Command pattern interface for database integration is presented in Listing 2.
Classes implementing this command will be performing the actual database operations for reading and inserting rows into customer and order tables. The following use cases will be addressed:
- Customers want to register on the site in order to place orders (a new row is created in the customer table)
- Customers can place the order (the order gets created in the database for a particular customer)
- Customers can view the orders they have placed
- Admin can list all the customers
Based on these use cases, the following classes have implemented the DatabaseCommand interface (see Listings 3-6):
public class CreateCustomer implements DatabaseCommand
public class CreateOrder implements DatabaseCommand
public class ListCustomers implements DatabaseCommand
public class ListCustomerOrders implements DatabaseCommand
Finally, in order to execute our command classes, we will need to create a class that would access the database datasource, obtain a SQL connection, and then execute a particular database command. This class will implement a Singleton design pattern, which we'll call CommandExecutor:
Object o = CommandExecutor.getInstance().executeDatabaseCommand
(<<instance of the particular database command class goes here>>).
The CommandExecutor class will perform the datasource lookup as follows:
InitialContext ctx = new InitialContext();
Context envCtx = (Context) ctx.lookup("java:comp/env");
ds = (DataSource) envCtx.lookup("jdbc/TestDB");
This finds the reference to the data-source we have defined in DBTest.xml by resolving its reference in a Web deployment descriptor (web.xml), which we'll define in a section below. Listing 7 has the complete code of the Command Executor class.
"We've discovered that after shows 80% if leads that people get, 80% of the conversations end up on the show floor, meaning people forget about it, people forget who they talk to, people forget that there are actual business opportunities to be had here so we try to help out and keep the conversations going," explained Jeff Mesnik, Founder and President of ContentMX, in this SYS-CON.tv interview at 18th Cloud Expo, held June 7-9, 2016, at the Javits Center in New York City, NY.
Jul. 23, 2016 11:45 PM EDT Reads: 1,192
Internet of @ThingsExpo has announced today that Chris Matthieu has been named tech chair of Internet of @ThingsExpo 2016 Silicon Valley. The 6thInternet of @ThingsExpo will take place on November 1–3, 2016, at the Santa Clara Convention Center in Santa Clara, CA.
Jul. 23, 2016 11:15 PM EDT Reads: 1,845
When people aren’t talking about VMs and containers, they’re talking about serverless architecture. Serverless is about no maintenance. It means you are not worried about low-level infrastructural and operational details. An event-driven serverless platform is a great use case for IoT. In his session at @ThingsExpo, Animesh Singh, an STSM and Lead for IBM Cloud Platform and Infrastructure, will detail how to build a distributed serverless, polyglot, microservices framework using open source tec...
Jul. 23, 2016 11:00 PM EDT Reads: 2,214
The 19th International Cloud Expo has announced that its Call for Papers is open. Cloud Expo, to be held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA, brings together Cloud Computing, Big Data, Internet of Things, DevOps, Digital Transformation, Microservices and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportuni...
Jul. 23, 2016 10:15 PM EDT Reads: 2,407
From wearable activity trackers to fantasy e-sports, data and technology are transforming the way athletes train for the game and fans engage with their teams. In his session at @ThingsExpo, will present key data findings from leading sports organizations San Francisco 49ers, Orlando Magic NBA team. By utilizing data analytics these sports orgs have recognized new revenue streams, doubled its fan base and streamlined costs at its stadiums. John Paul is the CEO and Founder of VenueNext. Prior ...
Jul. 23, 2016 09:30 PM EDT Reads: 1,940
A critical component of any IoT project is what to do with all the data being generated. This data needs to be captured, processed, structured, and stored in a way to facilitate different kinds of queries. Traditional data warehouse and analytical systems are mature technologies that can be used to handle certain kinds of queries, but they are not always well suited to many problems, particularly when there is a need for real-time insights.
Jul. 23, 2016 08:45 PM EDT Reads: 1,646
CenturyLink has announced that application server solutions from GENBAND are now available as part of CenturyLink’s Networx contracts. The General Services Administration (GSA)’s Networx program includes the largest telecommunications contract vehicles ever awarded by the federal government. CenturyLink recently secured an extension through spring 2020 of its offerings available to federal government agencies via GSA’s Networx Universal and Enterprise contracts. GENBAND’s EXPERiUS™ Application...
Jul. 23, 2016 08:30 PM EDT Reads: 1,766
"My role is working with customers, helping them go through this digital transformation. I spend a lot of time talking to banks, big industries, manufacturers working through how they are integrating and transforming their IT platforms and moving them forward," explained William Morrish, General Manager Product Sales at Interoute, in this SYS-CON.tv interview at 18th Cloud Expo, held June 7-9, 2016, at the Javits Center in New York City, NY.
Jul. 23, 2016 08:30 PM EDT Reads: 2,016
Internet of @ThingsExpo, taking place November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with the 19th International Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world and ThingsExpo Silicon Valley Call for Papers is now open.
Jul. 23, 2016 08:00 PM EDT Reads: 2,410
Big Data engines are powering a lot of service businesses right now. Data is collected from users from wearable technologies, web behaviors, purchase behavior as well as several arbitrary data points we’d never think of. The demand for faster and bigger engines to crunch and serve up the data to services is growing exponentially. You see a LOT of correlation between “Cloud” and “Big Data” but on Big Data and “Hybrid,” where hybrid hosting is the sanest approach to the Big Data Infrastructure pro...
Jul. 23, 2016 08:00 PM EDT Reads: 1,786
The IoT is changing the way enterprises conduct business. In his session at @ThingsExpo, Eric Hoffman, Vice President at EastBanc Technologies, discussed how businesses can gain an edge over competitors by empowering consumers to take control through IoT. He cited examples such as a Washington, D.C.-based sports club that leveraged IoT and the cloud to develop a comprehensive booking system. He also highlighted how IoT can revitalize and restore outdated business models, making them profitable ...
Jul. 23, 2016 07:15 PM EDT Reads: 1,867
We all know the latest numbers: Gartner, Inc. forecasts that 6.4 billion connected things will be in use worldwide in 2016, up 30 percent from last year, and will reach 20.8 billion by 2020. We're rapidly approaching a data production of 40 zettabytes a day – more than we can every physically store, and exabytes and yottabytes are just around the corner. For many that’s a good sign, as data has been proven to equal money – IF it’s ingested, integrated, and analyzed fast enough. Without real-ti...
Jul. 23, 2016 07:00 PM EDT Reads: 869
I wanted to gather all of my Internet of Things (IOT) blogs into a single blog (that I could later use with my University of San Francisco (USF) Big Data “MBA” course). However as I started to pull these blogs together, I realized that my IOT discussion lacked a vision; it lacked an end point towards which an organization could drive their IOT envisioning, proof of value, app dev, data engineering and data science efforts. And I think that the IOT end point is really quite simple…
Jul. 23, 2016 06:15 PM EDT Reads: 793
With 15% of enterprises adopting a hybrid IT strategy, you need to set a plan to integrate hybrid cloud throughout your infrastructure. In his session at 18th Cloud Expo, Steven Dreher, Director of Solutions Architecture at Green House Data, discussed how to plan for shifting resource requirements, overcome challenges, and implement hybrid IT alongside your existing data center assets. Highlights included anticipating workload, cost and resource calculations, integrating services on both sides...
Jul. 23, 2016 06:00 PM EDT Reads: 1,884
"We are a well-established player in the application life cycle management market and we also have a very strong version control product," stated Flint Brenton, CEO of CollabNet,, in this SYS-CON.tv interview at 18th Cloud Expo, held June 7-9, 2016, at the Javits Center in New York City, NY.
Jul. 23, 2016 05:30 PM EDT Reads: 1,720
The IoT has the potential to create a renaissance of manufacturing in the US and elsewhere. In his session at 18th Cloud Expo, Florent Solt, CTO and chief architect of Netvibes, discussed how the expected exponential increase in the amount of data that will be processed, transported, stored, and accessed means there will be a huge demand for smart technologies to deliver it. Florent Solt is the CTO and chief architect of Netvibes. Prior to joining Netvibes in 2007, he co-founded Rift Technologi...
Jul. 23, 2016 05:00 PM EDT Reads: 939
Unless your company can spend a lot of money on new technology, re-engineering your environment and hiring a comprehensive cybersecurity team, you will most likely move to the cloud or seek external service partnerships. In his session at 18th Cloud Expo, Darren Guccione, CEO of Keeper Security, revealed what you need to know when it comes to encryption in the cloud.
Jul. 23, 2016 04:00 PM EDT Reads: 2,304
We're entering the post-smartphone era, where wearable gadgets from watches and fitness bands to glasses and health aids will power the next technological revolution. With mass adoption of wearable devices comes a new data ecosystem that must be protected. Wearables open new pathways that facilitate the tracking, sharing and storing of consumers’ personal health, location and daily activity data. Consumers have some idea of the data these devices capture, but most don’t realize how revealing and...
Jul. 23, 2016 04:00 PM EDT Reads: 1,980
What are the successful IoT innovations from emerging markets? What are the unique challenges and opportunities from these markets? How did the constraints in connectivity among others lead to groundbreaking insights? In her session at @ThingsExpo, Carmen Feliciano, a Principal at AMDG, will answer all these questions and share how you can apply IoT best practices and frameworks from the emerging markets to your own business.
Jul. 23, 2016 03:45 PM EDT Reads: 1,508
Basho Technologies has announced the latest release of Basho Riak TS, version 1.3. Riak TS is an enterprise-grade NoSQL database optimized for Internet of Things (IoT). The open source version enables developers to download the software for free and use it in production as well as make contributions to the code and develop applications around Riak TS. Enhancements to Riak TS make it quick, easy and cost-effective to spin up an instance to test new ideas and build IoT applications. In addition to...
Jul. 23, 2016 03:30 PM EDT Reads: 1,841