How Do I use Jakarta Struts with Oracle9i JDeveloper?

An Oracle JDeveloper How To Document
May 2002

Note: This document is specifically for version 9.0.2. Later versions of JDeveloper have built-in Struts integration.

For the latest on integration between Struts and Oracle JDeveloper 10g see these resources:

Introduction to Oracle JDeveloper10g and Struts
Online Demo Struts basics in JDeveloper

Content

Introduction

This TechNote describes in detail how to configure and use Jakarta Struts with Oracle9i JDeveloper Production version 902. It describes how to download, install and run Struts examples applications inside of JDeveloper. It explains how to deploy a Struts application and it also provides a product sneak preview of the upcoming integrated Struts features in our next maintenance release of Oracle9i JDeveloper .

What is Struts?

Struts is an open source framework for building Web applications that integrates with J2EE technologies like Java Servlets, JavaServer Pages and JavaBeans. Struts enables Web application development which follow the Model-View-Controller (MVC) design paradigm.

MVC, also known as Model 2, is an application architecture which is divided into the following components:

  • Model - This is the data model which is usually developed by the end user of the Struts framework. This is typically the application's business logic and code to interact with a database.
  • View - In a generic sense, the View is comprised of the components which make up the application's user interface. Struts utilizes JSPs to serve as the view.
  • Controller - This is the program control logic which accepts user input and decides how to respond. The response is generated via the View components. Struts provides a front-end servlet which acts as a main application Web request dispatcher.
Struts Components

The Struts framework is made up of the following components:

  • The Action (Controller) servlet - Struts provides a ready to use servlet which receives application web requests and dispatches them to the different application components.
  • A set of JSP Tag libraries - Struts provides a set of useful tag libraries which perform varied tasks from HTML generation to application logic.
  • Example Applications - In order to make Struts easier to understand, several example applications are provided with the framework ready to run.
  • A Struts runtime library - The Struts runtime library contains the necessary libraries needed to run a Struts application. This file is deployed along with a completed Struts application.
  • Documentation - Struts provides a complete set of documentation in the framework.
A typical Struts application

The following diagram describes a very simple Struts application.


Figure 1. A Simple Struts Application

Figure 1 depicts a simplified Struts application. The application's Control program is the Struts Action servlet. It receives application Web requests and dispatches them to the various View components based on a set of rules defined in the Struts-config.xml file. The View components are comprised of JSPs using the the Struts custom tags as well as non JSP components such as an Action Class and a Form Class. The Action class can validate content submitted from an HTML form. The Form class is a Java representation of every field defined in the HTML form. The Action class actually uses the Form class (also referred to as Form Bean) to validate the contents of the form. To provide data to the application, a component or set of components allow for the interaction of the data Model and the application's View.

Using Struts in Oracle9i JDeveloper

Using Struts in JDeveloper is actually quite easy. The following steps show how to begin working with Struts within JDeveloper.

Step1: Download Struts

To obtain the latest copy of the Struts framework, go to: http://jakarta.apache.org/struts/. Locate the latest "release build" of Struts. At this time it is currently version 1.0.2. The entire framework is packaged into a single zip file. Unzip this file into a local area: d:\struts. As we unzip the archive we see the following directories:

  • lib - This directory contains the struts runtime library, struts.jar as well as the Struts custom tag libraries.
  • webapps - This directory contains the vaiorus example applications archived in J2EE WAR archives. A documentation application is also provided.

Once you've download and unzipped the struts archive you're ready to begin using Struts.

Step2: Install and Run the Struts Example Application

The next in getting familiar with using Struts with JDeveloper is to install and run the Struts "Example Application". The Struts "Example Application" provides a working example of a complete Struts application. By loading it into JDeveloper and observing how it runs, you will be able to quickly learn how a Struts application works. In this step you will use the "Create Project from existing WAR" feature to load the example application into a JDeveloper project.

Locate the "Create Project from existing WAR" wizard in the gallery and invoke it.


Figure 2. Creating a Project from an existing WAR

As the wizard appears it will allow you to locate the Struts Example application WAR file load it as a JDeveloper project.


Figure 3. Specifying the location of the Struts example application.

It also allows you to define the location of your Web Module. This is the root directory where the files will be placed. In this example I've chosen to place them in subdirectory under my project directory.

After the wizard completes it's task, you will have a new project loaded with Struts Example Application files.


Figure 4. The Struts Example Application loaded into JDeveloper

In figure 4 we see the example applications inside of a JDeveloper project. Notice that I changed the Struts example project to display in "Category" view. This is changeable on the JDeveloper navigator toolbar. (highlighted in red)

After successfully loading the application into JDeveloper, the next step is to run it!

Before running the application, you must add the Struts.jar runtime library as well as the Oracle XML parser library. This is done by editing the project properties by double-clicking on the project in the navigator. To add a new library for the Struts runtime click on New and define the location of the struts.jar library. Then make sure to add the library to the project. Now add the Oracle XML parser library to the project as well.


Figure 5. Configuring the Struts Example Project Libraries

Once the libraries have been added, you can successfully compile and run the example application! To run, simply select the file index.jsp in the navigator and select "Run index.jsp" from the context menu. This will launch the embedded OC4J and start the application.


Figure 6. Running the Example Application in JDeveloper

The example application contains a running example of how to use the various custom tag libraries as well as how to define the application mappings in the Struts-config.xml file. The Struts-config.xml file is located in the WEB-INF/lib node in the JDeveloper navigator. Also notice that this application provides a "Walking Tour of the Example Application" link. By clicking on this link, you will be able to see a live tour of each of the elements of the application and see how they work.

Once you've spent some time in discovering how the example application works, it is now time to start building your own Struts applications. Fortunately the Struts framework provides a blank application to get started.

Step2: Install and Run the Struts Blank Application

The Struts "Blank" application provides a complete starter application which you can then modify. Specifically it contains a starter JSP page, an example application resource file as well as an example struts-config.xml file.

Installing the Struts "Blank" application is just as easy as installing the "Example" application. We simply use the "Create Project from existing WAR" again and select the "Struts-Blank.war" file instead. You must also remember to add the struts.jar library as well.

Deploying a Struts Application

Since a Struts application is really just a J2EE Web application, it can easily be packaged into a Web Archive (WAR) file and loaded onto any J2EE compliant application server. Assembling a WAR file for your Struts application is quite easy. Simply invoke the Create WAR, deployment profile from the JDeveloper Gallery and accept all of the defaults in the wizard. This will create a new deployment profile and add it to your project. A nice thing to notice is that the Struts runtime jar file is automatically packaged into the WAR file so any further configuration of the deployment server is not needed!


Figure 7. Packaging your Struts Application as a WAR file.

Once the deployment profile is created, you can either deploy the application to an actual WAR file which could be transferred to a J2EE application server or you could deploy it directly to Oracle9i Application Server.

Upcoming Struts Features in Oracle9i JDeveloper !

The next maintenance release of Oracle9i JDeveloper will contain several new powerful features to further enable Struts development.
These include:

  • Embedded Struts Framework - The Struts framework will be installed into JDeveloper by default. No longer need to download and install manually.
  • Pre-Loaded Struts Tag Libraries - The Struts Tag Libraries will be pre-loaded onto the Component Palette.
  • Struts Configuration Wizard - A simple to use wizard to enable editing of the struts-config.xml file.
  • Struts Application Wizard - Turns your existing project into a Struts enabled project.
  • Struts Action Class Wizard - Generates Java starter code for a Struts Action class.
  • Struts Form Bean Wizard - Generates Java starter code for a Struts Form bean.
  • BC4J JSP Struts Application Wizard - Generates a fully functional Business Component for Java JSP application.

Summary

Struts now provides a common methodology for assembling enterprise J2EE Web applications where there was none in the past. Web application developers are finding themselves adopting the Struts application development framework and methodology instead of devising their own. Oracle9i JDeveloper understands the need for a framework methodology will continue to enhance Struts developer's capabilities and productivity by offering more and more productivity enhanced Struts development features.

References

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy