|
Your First Struts Application
Here's a tutorial to help you start building serious Web apps.
by Budi Kurniawan
Posted September 13, 2002
The old adage, "Work smarter, not harder," is sometimes a lot easier to say than to practice. But once you master Struts—a framework for building serious Web applications—you can develop applications much more rapidly than you do now. Unfortunately, most programmers find the required learning curve steep. This article, the first of a six-part series, provides a quick start for those who've been working with servlets or JSP pages but are new to Struts.
I'll teach you how to install and configure Struts, and present the specification and deployment descriptor of a small application built within the framework. I'll discuss the application in more detail in the second part of this series.
An important note before you start: Building this application requires a good understanding of the Model-View-Controller (MVC) paradigm in a Java Web application. If this is a new concept to you, please read "Almost All Java Web Apps Need Model 2."
First, though, you need to understand a few basics about Struts. It uses the Model 2 architecture, which is based on the MVC design pattern. Model 2 applications are ideal for serious developers because they create programs that are flexible, extensible, and easy to maintain. Model 2 is the recommended architecture even for simple applications, so it's crucial to have a framework on which you can build this kind of application quickly and easily. Apache's Jakarta Struts Project from Apache Software Foundation is such a framework, and this example will help you understand how to use it.
This example is a beginner's teaching tool, so it doesn't use the Struts capability fully. For example, it doesn't use Struts tag libraries or other interesting features, so the code is easier to understand. Also, in the interest of simplicity, it uses only a few files. Finally, you'll see Java code in the JSP pages that would be implemented using Beans in real-world applications, but this would needlessly complicate the example.
Now, before you can start, you need Struts in your machine. If you have not done so, download and configure Struts.
Installing Struts
Installing Struts is easy, and Struts does not need complicated configuration. First, download the Struts binary distribution from . At the time of writing, version 1.0 is the stable version, and 1.1 is in beta. (I used 1.1-b2 for the projects in this series.)
You can then extract the compressed binary distribution into a temporary directory. The installation directory has three files: README, INSTALL, and LICENSE. These are self-explanatory. Two directories will be created under the installation directory: lib and webapps. The lib directory contains the struts.jar file, the commons-*.jar files, and other files you need to deploy in every Struts application. The webapps directory contains eight .war files, which contain the documentation and some sample applications built using Struts.
Back to top
|