Skip to main content

The Express route to Web application development

Develop a Java Web application on WebSphere Application Server - Express that accesses DB2 UDB Express

Sham Lim (limss@my.ibm.com), IBM Virtual Innovation Center, IBM Malaysia
Sham Sham Lim works as a DB2 UDB Technical Presales Support for IBM Virtual Innovation Center. Sham Sham has DB2 certification in administration. She spends most of her time helping IBM Business Partners with DB2 technical related issues.

Summary:  This article introduces the Java developer to the basics of application with WebSphere Application Server - Express using DB2 Express for the data store. It covers the basic architecture of WebSphere Application Server - Express and DB2 UDB Express, explains terminology, and covers details you will need to know, from installation of the products, through configuration, to deploying a Java application.

Date:  13 May 2004
Level:  Introductory
Activity:  712 views

Get the products used in this article

If you've already purchased the right to get software online or on CD through the developerWorks Subscription, you have a single user license to use DB2 Universal Database Express, WebSphere Application Server - Express and other DB2®, Lotus®, Rational®, Tivoli®, and WebSphere® products -- including the Eclipse-based WebSphere Studio IDE -- to develop, test, evaluate, and demonstrate your applications. If you are not a subscriber, you can subscribe today.


Introduction to WebSphere Application Server - Express and DB2 UDB Express

WebSphere Application Server - Express is the simplest member in the WebSphere Application Server family. Because it is targeted towards small and medium businesses that may not require the complete range of functionality that other members offer, it contains only a subset of the full WebSphere Application Server architecture. For example, no EJB support is included.

WebSphere Application Server - Express consists of two major products:

  • Express Application Server - A full-production system for hosting applications on the Web
  • WebSphere Studio Site Developer (WSSD) - A development tool that allows you to create and test applications

Figure 1 shows you an overview of the architecture for WebSphere Application Server - Express.


Figure 1. WebSphere Application Server - Express overview
WebSphere Application Server - Express overview

Here are some of the terms used with WebSphere Application Server:

Application servers
Application servers are the primary runtime components that your applications will execute. You can have one or more application server defined in your configuration; however there is no workload distribution among application servers at the Express level.

Here are some of the major components in an application server:

  • Web container
    Each application server runtime has one logical Web container. This container processes servlets, JSP files and other types of server-side inclusions. The Web container configuration provides information about the application server component that handles servlet requests forwarded by the Web Server.
  • Embedded IBM HTTP Server
    In a typical application server environment, you will have a Web server that serves HTML pages. Requests that require dynamic content (using a JSP or servlet) are passed through to the application server. The Express Application Server provides an embedded Web server based on IBM HTTP Server. This embedded server can be used to serve the static Web pages for the application. Although not a fully configurable Web server, it provides the function needed by applications running in a WebSphere Application Server - Express environment.
  • Nodes
    A node is a logical grouping of WebSphere-managed processes that share a common configuration. A node is generally associated with the physical installation of Application Server. In the Express configuration of Application Server, there is only one node, called DefaultNode.
  • Cells
    A cell is an administrative concept used in the more advanced versions of Application Server. Application sedrvers are attached to nodes and nodes belong to a cell. In the Express configuration, there is one cell, called DefaultNode.

More WebSphere term definitions can be found here:
http://publib-b.boulder.ibm.com/Redbooks.nsf/RedbookAbstracts/sg246976.html?Open
http://publib-b.boulder.ibm.com/Redbooks.nsf/RedbookAbstracts/sg246555.html?Open

DB2 UDB Express is the lowest priced full-function relational database edition in the IBM DB2 family. It is designed specifically to help small and medium businesses integrate and manage their businesses.

Figure 2 shows an overview of DB2 UDB Express.


Figure 2. DB2 UDB Express overview
DB2 UDB Express overview

Here are some basic DB2 terms that you should be familiar with:

DB2 Administration Server (DAS)
The outer line in Figure 2 defines a physical machine (“My Server"). Any machine with DB2 installed with have one background process known as the DAS. The main purpose of the DAS is to provide remote administration support. Each physical machine should have one DAS server process.

Instance
An instance is a collection of processes which provide access to database(s). One instance can be used to provide services to one or more databases. You can have one or many instances on a machine, each instance acting as an independent server environment which can be stopped and restarted without affecting other instances.

Each instance also has its own configuration file, the Database Manager Configuration file (DBM CFG) for instance level security, performance variables, and communication configuration. There is one DBM CFG per instance.

Database
A database is a collection of tables, including data and related objects such as indexes, views, triggers, and stored procedures. The instance processes provide access to database data.

Each database has its own configuration file, called the Database Configuration file (DB CFG) at the database level.


Installing the WebSphere and DB2 UDB Express products

In a later exercise, we will be using IBM WebSphere Application Server Express V5.1 and IBM DB2 Universal Database Express V8.1. The trial versions of WebSphere Application Server Express and DB2 UDB Express can be downloaded from the following Web site:
http://www14.software.ibm.com/webapp/download/home.jsp.

We will not cover the step-by-step installation, as the process is assisted by wizards and is pretty straightforward. Here are a few steps you can take to verify that the installation has completed successfully:

  1. After you have completed the WAS Express installation, proceed to Start -> Programs -> IBM WebSphere Application Server Express 5.1 -> First Steps. Click on Verify Server Installation to verify that WebSphere Application Server - Express installed successfully. You should see the message “OK" at the end of each test.
  2. For DB2 UDB Express, after the installation, proceed to Start -> Programs -> IBM DB2 -> Set-up Tools -> First Steps to create a database called SAMPLE. Alternatively, you can do this in a DB2 Command Window (Start -> Programs -> IBM DB2 -> Command Line Tools -> Command Window) by executing db2sampl from C:\>DB2 Installation folder>\SQLLIB\bin\. We will use one of the tables in this database in our application later.
  3. The DB2 Control Center is the central point of administration for DB2. To check if the SAMPLE database has been created successfully, you can invoke DB2 Control Center from Start -> Programs -> IBM DB2 -> General Administration Tools -> Control Center. As you see in Figure 3, to display all the DB2 systems that your system has cataloged, expand the object tree by clicking on the + sign next to Systems. The left portion of the screen lists available DB2 systems. In this example, the system LIMSS contains a DB2 instance, DB2, in which the database SAMPLE is located. When a table is highlighted, all the related details are shown on the right portion of the screen.

Figure 3. DB2 Control Center
DB2 Control Center

Let's move on now to considering the application itself.


Develop a Java Web application using WebSphere Studio Site Developer

The J2EE specification is the standard for developing, deploying and running enterprise Web applications. IBM WebSphere Application Server V5 has completed the full J2EE certification test suite. The product supports all of the J2EE 1.3 APIs and exceeds many with its extensions. You can check the list of J2EE-compatible products posted by Sun Microsystems at http://java.sun.com/j2ee/compatibility.html.

Figure 4 shows the J2EE packaging and is helpful for understanding the components of a J2EE appication.


Figure 4. J2EE packaging
J2EE packaging

As you can see from Figure 4, an enterprise application project (MyApp.ear) contains the hierarchy of resources that are required to deploy an enterprise (J2EE) application. It can contain a combination of Web modules, EJB modules, JAR files and application client modules. Enterprise application projects are exported as enterprise archive (EAR) files that include all files defined in the enterprise application project as well as the appropriate module archive file for each J2EE module project defined in the deployment descriptor, such as Web archive (WAR) files and EJB JAR files.

WebSpere Application Server - Express does not support EJB components, so the typical enterprise application and deployed with this product will consist primarily of Web modules and supporting JAR files.

WSSD provides different perspectives which provide different ways of viewing and working with resources. A perspective consists of a set of views, editors and toolbar options suited to the task most likely performed within that perspective. You can use different perspectives such as the Web perspective, Data perspective or Server perspective in WSSD during the application development stage.

For example, the Server perspective is designed with the server or unit test environment operation in mind. There is a view for the server console, a view that shows server configurations, a view that allows you to start and stop servers and so forth. (See Figure 5.)


Figure 5. Server perspective in WSSD
Server perspective in WSSD

In our exercise, we will primarily be using the Web perspective to develop our Web project components.

Since the intent here is to give you an overview of deploying a Java Web application on WebSphere Application Server - Express using DB2 UDB Express, we are going to develop a simple solution that will input the user ID and password to the backend database on DB2 UDB Express. Once the connection is established successfully, the application will display employee records in a table.

In the following section, we will step through the creation of our example. As we want to quickly get an application completed, the programming model I used in this exercise may not be suitable for your environment. For this example, the page presentation is tightly coupled to the business logic, which will hinder the future scalability of the application. In addition to that, this example does not include exception handling. Be aware that this is a learning example, and use the architecture that best suits your environment.


Creating the application

Step 1 – Create MyFirstTest Web project

We are going to create our Web project now. From the Web perspective (Window -> Open Perspective -> Web), do the following:

  1. Select File -> New -> Dynamic Web Project.
  2. Enter the project name, MyFirstTest, and verify that the Configure advanced options check box is selected. This will allows you to select the enterprise application for this project.
  3. Click Next.
  4. Besides the EAR Project list box, click New, and enter MyFirstTestEar as the project name.
  5. Click Finish. this will create the MyFirstTestEar Enterprise Application Project.
  6. Verify that the J2EE 1.3 level is selected. The context root will default to the Web project name.
  7. Click Next.
  8. Click Next.
  9. Click Finish.

This new Web project will be created with the appropriate directory structure, the style sheet and Web deployment descriptor (web.xml). A module entry for this Web module is also added to the enterprise application deployment descriptor (application.xml). Figure 6 shows the directory structure created for the Web project you have just defined.


Figure 6. Directory structure for MyFirstTest Web project
Directory structure for MyFirstTest Web project

Step 2 - Create index.html

This page will serve as the main page of your application. We will create a form in this html page that will use the user ID and password input by the user to establish a connection to the backend database.

From the Web perspective, under the MyFirstTest/WebContent directory, create the index.html file as follows:

  1. Locate the MyFirstTest/WebContent folder then right-click -> New -> HTML file.
  2. On the New HTML File window, verify that the folder name is set to MyFirstTest/WebContent, and the Markup language to HTML. Enter the new HTML name index and click Next.
  3. On the second window, leave the default values and click Finish. The new HTML should come up in the HTML editor with the following initial text: "Place content here.".
  4. Change this text to "Congratulations!". Verify that the Design tab is selected and set the cursor on the new text. On the bottom left, select the Attributes tab. The Paragraph section should appear. Select heading 1, and the character string size should increase.
  5. Set the cursor under the new text, and enter new text "You have successfully deployed your first Java application on the Express Application Server." and select heading 3 in the Attribute pane.
  6. Set the cursor under the text you have just created. Enter the following additional new text: "Next, we are going to establish a connection to your backend database, DB2 UDB Express. Please log on using the ID and password you used to create the SAMPLE database." and select normal in the Attribute pane.
  7. Set the cursor under the text you have just created. On the tool bar, select Insert -> Form and Input Fields -> Form. A new form should appear. On the Attribute pane, enter logonEmployee.jsp in the Action field and select the Post radio button for the method.
  8. Set the cursor in the new form and click the Insert -> table icon on the tool bar. On the pop-up window, enter 3 rows and 2 columns and click OK. A new table should appear. In the first row, first column, enter the text "User ID:". In the second row, first column, enter the text "Password".
  9. Set the cursor in the third row, first column of the table, then right click Insert Input Fields -> Submit Button. In the pop-up window, enter "SUBMIT" in the Name field, "SUBMIT" in the Label field, and click OK.
  10. Set the cursor in the first row, second column of the table, then right click Insert Input Fields -> Text Field. In the pop-up window, enter "UserID" in the Name field, "20" in the Columns field, "20" in the Maximum length field, and click OK.
  11. Set the cursor in the second row, second column of the table, then right click Insert Input Fields -> Text Field. In the pop-up window, enter "Password" in the Name field, "20" in the Columns field, "20" in the Maximum length field, select the Password radio button, and click OK.
    Your index.html should look like the one below in Figure 7.
    Figure 7. Your index.html design
    Your index.html design
  12. The design of the page has been completed. Switch to the Source tab to see the codes that have been generated so far. To prevent erroneous data from being submitted, we are going to add form validation to this page. I have prepared the JavaScript code (formvalidation.txt) in advance (see downloads). What you need to do is to copy the script definition from formvalidation.txt and paste into the HEAD section in the index.html page as follows:
    …..
    <HEAD>
    ….
    </TITLE>
    Paste the script here
    </HEAD>
    

  13. Add the onsubmit handler to your FORM tag. When a user presses the Submit button, the code placed in the onsubmit handler is executed before the form is submitted to the server. If the return value from the code is false, the submittion is cancelled.
    <FORM ACTION="logonEmployee.jsp" METHOD="POST" ONSUBMIT="return validateForm(this)">
    

Step 3 – Create the errorPage.jsp

Instead of displaying a standard server page that shows all the errors, we will create a custom error JSP that is customized with the ‘look and feel’ that we want.

  1. Locate the MyFirstTest/WebContent folder, then right-click New -> JSP file.
  2. On the New JSP File window, verify that the folder name is set to MyFirst Test/WebContent and the Markup language to HTML. Enter the new JSP named errorPage.jsp and cllick Next.
  3. Take the default values for the rest of the windows and click Next.
  4. On the last window, leave the default values and click Finish. The new JSP should come up in the JSP editor.
  5. You might use the wizards or write it manually. The JSP editor should show the new errorPage page with the following initial text: “Place content here". Change this text to “Error Page". Verify that the Design tab is selected, and set the cursor on the new text. On the bottom left, select the Attributes tab; the Paragraph section should appear. Select heading 1; the character string size should increase.
  6. Set the cursor under the new text, and enter new text “An error has been detected:" and select heading 2 in the Attribute pane.
  7. Set the cursor under the new text then select JSP -> Insert Expression.
  8. A new expression icon should appear on the Design window and the jsp:expression editor should come up on the bottom left corner. Enter the following text in that editor: request.getAttribute("Error").
  9. Set the cursor on a new line, select Insert -> Link. Enter the following: <%=request.getContextPath()%>/index.html
    in the URL column and change the text in the Link text to “Go back to Login Page".
    Your errorPage.jsp should look like the one below in Figure 8:

    Figure 8. Your errorPage.jsp design
    Your errorPage.jsp design
  10. Save your changes and close the JSP. Proceed to Step 4 to create the loginEmployee.jsp.

Step 4 – Create the loginEmployee.jsp

If the return value of validateForm() in index.html is true, the user ID and password input will be submitted to the loginEmployee.jsp.

  1. Locate the MyFirstTest/WebContent folder, then righ-click New -> JSP file.
  2. On the New JSP File window, verify that the folder name is set to MyFirstTest/WebContent and the Markup language to HTML. Enter the new JSP name loginEmployee.jsp and click Next.
  3. Take the default values for the rest of the windows and click Next.
  4. On the last window, leave the default values and click Finish. The new JSP should come up in the JSP editor.
  5. You might use the wizards or write it manually: The JSP editor should show the new login page with the following initial text: "Place content here". Change this text to "Welcome to the MyFirstTest Employee Page". Verify that the Design tab is selected, and set the cursor on the new text. On the bottom left, select the Attributes tab; the Paragraph section should appear. Select heading 2; the character string size should increase.
  6. Now, set the cursor on a new line, and select Insert -> Table. On the pop-up window, enter 2 rows and 4 columns and click OK. A new table should appear.
  7. In the first row, first column, enter the text "EMP NO". On the bottom left, select the Attributes tab. Set the Cell type to Header. Repeat the same operation for the second, third, and fourth columns with the following text: "FIRST NAME", "LAST NAME", "JOB".
  8. In the second row, first column, select JSP -> Insert Expression. An expression editor should come up. Select the icon and then select the Attributes tab in the bottom left pane. You should see the jsp:expression editor. In that editor, enter EmpNo. Repeat the same operation for the second, third and fourth columns, and enter the following in the jsp:expression editor: LastName, FirstName, Job.
  9. Switch to the Source tab. Import java.sql.* as follows:
    <%@ page language="java"
    contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"
    import="java.sql.*"
    %>

  10. You should also see the following code has been generated:
    …
    <TABLE border="1">
        <TBODY>
    		<TR>
    			<TH>EMP NO</TH>
    			<TH>LAST NAME</TH>
    			<TH>FIRST NAME</TH>
    			<TH>JOB</TH>
    		</TR>
    		<TR>
    			<TD><%=EmpNo%></TD>
    			<TD><%=LastName%></TD>
    			<TD><%=FirstName%></TD>
    			<TD><%=Job%></TD>
    		</TR>
    	</TBODY>
    </TABLE>
     …

  11. Set the cursor in between the first </TR><TR> and select JSP -> Insert Scriptlet. You should see <%%> being added as follows:
     ….
     <TH>Job</TH>
     </TR>
     <%%>
      <TR>
      <TD><%=EmpNo%></TD>

  12. Switch back to the Design pane. You should now see a scriptlet icon appear on the page. Select the icon and right click Attributes. The jsp:scriptlet editor should appear on the bottom left. Paste the code from PartA.txt (from the article downloads) in that editor.
  13. Switch back to the Source pane. Set the cursor between the </TR></TBODY>. Select JSP -> Insert Scriptlet. You should see <%%> being added as follows:
    ….
    <TD><%=Job%></TD>
    </TR>
    <%%>
    </TBODY>
    ….	

  14. Switch back to the Design pane. You should now see a scriptlet icon appear on the page. Select the icon and right click Attributes. The jsp:scriptlet editor should appear on the bottom left. Paste the code from PartB.txt (from the article downloads) in that editor.

    The loginEmployee.jsp will also instantiate a JavaBean so that you can reference the bean in this JSP file. Before we proceed to add the useBean tag, we will first create the MakeConnection.java and SearchEmployee.java outlined in Step 5 and Step 6. Please proceed to Step 5 to create the java files; we will come back to add the useBean tag later.

    We are going to add a <jsp:useBean> tag which will result in a empBean bean being instantiated if no bean with the same id and scope can be found. After it is instantiated, you can reference the bean in the JSP file.

  15. Set the cursor above the “Welcome to the MyFirstTest Employee Page" heading and then select JSP -> Insert Bean. On the Insert Bean window, enter the ID empBean. Click on the Browse button next to the Class column. Enter SearchEmployee in the Search a class column. Verify that SearchEmployee is in the matching types list and emppkg – MyFirstTest/JavaSource is in the Qualifer list. Then press OK. Make sure the Class field now contains the text “emppkg.SearchEmployee".
  16. From the Scope, select Request. Then press OK to finish. You should see a new useBean tag on the Design window.

    Your logonEmployee.jsp should look like the one below in Figure 9:


    Figure 9. Your logonEmployee.jsp design
    Your logonEmployee.jsp design
  17. Save your changes and close the JSP. There should be no “Broken Link" message and no errors at the console by now. However, if there are any, you can review the messages and correct the problem. Otherwise, it means we are ready to deploy our application which we will cover in the next section.

Step 5 – Create the MakeConnection Servlet

In this step, we will create a new servlet that use the user ID and password input in the index.html to establish a connection to our backend database, DB2 UDB Express.

  1. We are going to create a package before we proceed to create the servlet. From the Web perspective, locate the /MyFirstTest/Java Resources folder. Right click New -> Package. Enter “emppkg" in the pop-up window and then press Finish. You should see a package – emppkg is created under /MyFirstTest/Java Resources folder.
  2. To create a new servlet named MakeConnection.java in the emppkg package, locate the /MyFirstTest/Java Resources folder, then select the emppkg package, right click New -> Servlet to open the New Servlet wizard.
  3. Make sure the Folder text field contains the text /MyFirstTest/JavaSource and that the Java package is emppkg.
  4. Enter in a Class Name of MakeConnection
  5. Verify that the Superclass is javax.servlet.http.HttpServlet. Click Next to continue.
  6. Make sure that the Add to web.xml options are selected. Verify that the URL is mapped to /MakeConnection. Click Finish to create the servlet.
  7. The MakeConnection.java should come up in the editor.
  8. Erase all the pre-generated code in MakeConnection.java. Copy the code from MakeConnection.txt (from the article downloads) and paste it in MakeConnection.java.
  9. Save your changes and close.
  10. Proceed to Step 6 to create the SearchEmployee Servlet.

Step 6 – Create the SearchEmployee Servlet

After the connection to the SAMPLE database is established, we are going to retrieve the details of all the employees by calling another servlet named SearchEmployee.

  1. To create a new servlet named SearchEmployee.java in the emppkg package, locate the /MyFirstTest/Java Resources folder, then select the emppkg package, and right click New -> Servlet to open up the New Servlet wizard.
  2. Make sure the Folder text field contains the text /MyFirstTest/JavaSource and that the Java package is emppkg.
  3. Enter in a Class Name of SearchEmployee.
  4. Verify that the Superclass is javax.servlet.http.HttpServlet. Click Next to continue.
  5. Make sure that the Add to web.xml options are selected. Verify that the URL is mapped to /SearchEmployee. Click Finish to create the servlet.
  6. The SearchEployee.java should come up in the editor.
  7. Erase all the pre-generated code in SearchEmployee.java. Copy the code from SearchEmployee.txt (from the article downloads and paste it in SearchEmployee.java.
  8. Save your changes and close.
  9. By now, you should have both the MakeConnection and SearchEmployee created. Please proceed to #15 in Step 4 above to add the useBean tag.

Deploy your application to WebSphere test environment and Express Application Server

WebSphere Application Server - Express provides two application server environments for the deployment of applications:

  • WebSphere test environment
    This is an instance of Express Application Server that is installed as a part of Studio Site Developer. It is used to test applications as you are developing them.
  • Express Application Server
    This is a standalone application server that is used to run the applications in a production environment. It can be installed on the same machine as Studio Site Developer or on a remote system.

The easiest way to get started with testing applications is to begin with the WebSphere test environment. As we have developed our application in the previous section, we can now deploy our application to the WebSphere test environment to have it tested.

To use the test environment, we need to do the following:

  1. Create a server and server configuration
    Now, we are going to create a test environment server for our application. You can do this either from the Web perspective or the Server perspective. In this exercise, we will create it directly from the Web perspective. From the Web perspective, follow the steps as shown in Figure 10 to create the test environment server.
    Figure 10. Setting up test environment server
    Setting up test environment server
  2. Publish the enterprise application to the server
    If you have not changed the server preferences from the default, your application, MyFirstTest will be published to the test environment automatically as shown in Figure 11:
    Figure 11. Publishing MyFirstTest application to the test environment
    Publishing MyFirstTest application to the test environment

    After the publishing is done, the server server1 will also be started automatically. You should see the message 'Server server1 open for e-business' in the console view. This indicates that the server is started successfully. Our application – index.html – will also open in a Web browser.

  3. Update the server configuration for application-specific values
    We are still not done at this point, close the Web browser and stop server1 since we have not updated the server configuration with the JDBC driver and data source for the SAMPLE database.

    JDBC 2.0 provides 2 methods of establishing database connections. The first method id done by using the driver manager interface. This is a carry over from JDBC 1.0 and is expensive in terms of performance. Using this method, a connection is created each time you access the database from your program, thereby incurring a substantial processing overhead.

    An alternative way of handling database connections is to use data source objects. By using data source objects, you have access to a pool of connections to a data source. Connection pooling improves performance as a data source object creates a connection as soon as it is instantiate. When a servlet or other client wants to use a connection, it looks up a data source object by name from a JNDI server. The data source object then returns a connection to the client. When the client has finished with the connection, it releases it. The data source object then returns the connection to the available pool.

    Because of the advantages of connection pooling, using data source objects is the preferred method of handling database connections in Web applications. We will use data source objects in this exercise.

    Switch to the Servers tab in the bottom pane. You should see the status of WebSphere Express v5.1 Test Environment is set to Started. To stop the server, right click in the Servers view and select Stop. The status will then be changed to Stopping and in the end, the Console view will open automatically, showing you server1 has been stopped.

    Switch back to the Servers tab in the Web perspective. Double click the test server to open the configuration. Switch to the Data source tab. The first step is to add a JDBC provider to the configuration. This tells the server which JDBC driver class to use to access the database.

    You should see a Cloudscape driver and data source information is predefined in the configuration. It is used to support the sample applications shipped with WAS Express.

    Click Add beside the JDBC provider list. Select IBM DB2 in upper window and DB2 Legacy CLI-based Type 2 JDBC Driver in lower window. Click Next. The name can be anything, in this exercise, we will name it as DB2 JDBC Driver. The implementation class name and class path you see are the default for the DB2 JDBC provider. Note that the driver db2java.zip must be available in the class path specified. The class path uses a variable ${DB2_JDBC_DRIVER_PATH} which we will define later.

    Now, follow the steps as shown in Figure 12 to define the Data Source Resource.


    Figure 12. Adding a data source
    Adding a data source

    In the Modify Data Source screen, change the Name to SAMPLE and make sure the JNDI name is jdbc/SAMPLE, which match the name we specified in MakeConnection.java. Click Next and make sure the value for databaseName is set to SAMPLE. Click Finish and you are done with defining the data source.

    The class path variable, ${DB2_JDBC_DRIVER_PATH} which was defined earlier has not been defined yet. Switch over to the Variables tab. The variable, DB2_JDBC_DRIVER_PATH is predefined in the node settings, but the value is empty. Follow the steps as shown in Figure 13 to define the location of the driver.


    Figure 13. Define the location of the DB2 JDBC Driver
    Define the location of the DB2 JDBC Driver

    Save all the changes you have made and close the configuration.

  4. Start the server
    The next step is to start the server. Select WebSphere Express V5.1 Test Environment in the Servers view in the bottom pane. Right click and select Start.

    The Console view will open automatically, showing you the server runtime messages. If you see problems or if the server doesn’t start, review the console messages, correct the problem and try again.

    You should see the message "Server server1 open for e-business" in the console view which indicates that the server is started successfully.

  5. Run the application
    Follow the steps as shown in Figure 14 to run MyFirstTest application.
    Figure 14. Run your application
    Run your application

    The application will open in a Web browser as you can see in Figure 15.


    Figure 15. Test the application
    Test the application

Now we are going to exercise the application code. Use the ID and password you used to create the SAMPLE database to establish a connection to DB2 UDB Express. If the ID and password you supplied are invalid, you will be directed to an error page. Otherwise, a list of employees with their details will be displayed as shown in Figure 16 below:


Figure 16. List of employees with their details
List of employees with their details

We have tested our application in the WebSphere test environment and there are no errors in the application. Make sure you stop the server first, right click in the Servers views and select Stop. The next thing to do is to deploy the application to the Express Application Server as an enterprise application.

In a typical production environment, applications are normally managed from the administrative console. In this exercise, we will export our application – MyFirstTest to an EAR file and place it on the application server for deployment.

From the Web perspective, follow the steps as shown in Figure 17 to export the MyFirstTest Enterprise Application to an EAR file.


Figure 17. Export MyFirstTest to an EAR file
Export MyFirstTest to an EAR file

The next step is to install the EAR file that was exported in the earlier step as a WebSphere Application Server Express Enterprise Application. We will use the facilities of WebSphere Administrative Console to perform the installation.

As the administrative console application is installed by default on server1, it must be started in order to access to the application. You can start the server from Start -> Programs -> IBM WebSphere Application Server – Express 5.1 -> Start Application Server.

Open a browser and enter this URL: http://localhost:7090/admin to start the WebSphere Administrative Console. During WAS Express installation, one virtual host – admin_host – is defined which is used to access to the WebSphere Administrative Console. It is configured to match the requests to port 7090.

At installation, the administrative console can be accessed by anyone with a Web browser access to the server. If you want to perform user authentication, this requires that the WebSphere global security be enabled. This part will be skipped in our exercise.

Follow the steps as shown in Figure 18 to install the EAR file as an enterprise application with the use of Administrative Console.


Figure 18. Install new application, MyFirstTest.ear
Install new application, MyFirstTest.ear

The next page has 4 steps. Select the defaults for each step and continue. On the final step click Finish. You should see a message “Application MyFirstTestEar" installed successfully. You must save the configuration at this point. Click on Save to Master Configuration and then click on the Save button. You should be returned back to the Administrative Console home page.

Next, we will create the JDBC Provider and Data Source Resources for the application. Follow the steps as shown in Figure 19 to define the JDBC provider and data source.


Figure 19. Define JDBC provider and data source
Define JDBC provider and data source

We have finished defining the JDBC Provider; let’s continue to define the Data Source Resource.

In the left frame of the Administrative Console, select Resources -> JDBC Providers. Select teh JDBC provider you have just created, namely DB2 Legacy CLI-based Type 2 JDBC Driver. In the Additional Properties tab on the page, select Data Sources.

On the Data Sources pages, click on New. Follow the steps as shown in Figure 20 to create a new data source.


Figure 20. Create a new data source
Create a new data source

Now select SAMPLE from the list of existing sources. In the Additional Properties tab of the page, select Custom Properties. Click on the databaseName link in the Custom Properties table. Fill in the value of the databaseName as Sample and click OK. Save the configuration.

Another variable we need to specify is the location of the DB2 JDBC drivers on the server. Follow the steps as shown in Figure 21 to define the location of the driver.


Figure 21. Specify the location of the DB2 JDBC drivers
Specify the location of the DB2 JDBC drivers

We are now ready to test the MyFirstTest application deployed to Express Application Server.

In the left frame of the Administrative Console, select Applications -> Enterprise Applications, and make sure the status of MyFirstTestEar is started.

Open a browser to test the application. The URLs for the application will be the same as the WebSphere Studio Site Developer environment – http://localhost:7080/MyFirstTest/.

Test your application and verify that the application was correctly deployed to the application server. If there are no errors in the application, it means you have successfully deployed your application in Express Application Server.

Congratulations, you have now completed all the exercises!


Conclusion

In this article I have presented a basic overview of WebSphere Application Server - Express and DB2 UDB Express. I have also outlined the steps to develop a simple Java Web application using WSSD, and showed you how to deploy and run it on WebSphere Application Server - Express accessing DB2 UDB Express.

Topics like security, session management, usage of other perspectives and custom JSP tags that can be used to replace scriptlet Java code are not covered in this article. For more information, please refer to the handbooks listed under the Resources section.



Download

NameSizeDownload method
files.zip2.2 KB FTP | HTTP

Information about download methods


Resources

About the author

Sham Sham Lim works as a DB2 UDB Technical Presales Support for IBM Virtual Innovation Center. Sham Sham has DB2 certification in administration. She spends most of her time helping IBM Business Partners with DB2 technical related issues.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Information Management, WebSphere
ArticleID=14627
ArticleTitle=The Express route to Web application development
publish-date=05132004
author1-email=limss@my.ibm.com
author1-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Special offers