gamelan
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!


Linked Data Planet Conference & Expo


Developer Jobs

Be a Commerce Partner
Memory Upgrades
PDA Phones & Cases
Cell Phones
Prepaid Phone Card
Car Donations
Shop
Hurricane Shutters
Memory
Imprinted Gifts
Computer Deals
Find Software
Promote Your Website
Remote Online Backup
KVM over IP

 


This report shows 5 trends that will emerge to allow Application Development and Program Management professionals to meet business expectations, include:

Diversification of software supply chain
Shorter development and delivery cycles
Disruptive technologies and architectures, and More.
Register now for your free Internet.com membership to download your complimentary Forrester report.
Limited Time Offer!
Membership will also give you access to:
eBook library         Whitepapers         Webcasts
Newsletters         WinDrivers
Developer News -
SaaS Tool Offers Custom Database Development    May 9, 2008
Microsoft’s Automated Agent: Can We Talk?    May 7, 2008
Borland Finally Sells CodeGear    May 7, 2008
Red Hat Heads For The JON 2.0    May 7, 2008
Free Tech Newsletter -

Best Practices for Developing a Web Site: Checklists, Tips, Strategies & More. Download Exclusive eBook Now.

An Introduction to Struts
By Kevin Bedell

Go to page: 1  2  Next  

Introduction

Welcome to the first in a series of articles on Jakarta Struts (or simply, "Struts"), the Java/JSP-based framework for building Web-based applications. While later articles will get deep into the technology behind Struts, this first article provides an introduction to Struts and evaluates the case for using it. It tries to cut through the technology and put its finger on the "value add" that Struts provides.

"What Is Struts and Why Should I Care?"

Struts is an application development framework that is designed for and used with the popular J2EE (Java 2, Enterprise Edition) platform. It cuts time out of the development process and makes developers more productive by providing them a series of tools and components to build applications with. It is non-proprietary and works with virtually any J2EE-compliant application server. Struts falls under the Jakarta subproject of the Apache Software Foundation and comes with an Open Source license (meaning it has no cost and its users have free access to all its internal source code).

In addition to helping you work faster and having no cost, Struts also helps make your end work products better. The main reason for this, to quote from Eric Raymond's "The Cathedral and the Bazaar" (a classic book on open source development), is that "(g)iven a large enough beta-tester and co-developer base, almost every problem will be characterized quickly and the fix obvious to someone." In other words, so many people are using and developing Struts that bugs are found and get fixed quickly.

"Struts is a Web Application 'Framework'?"

The dictionary calls a framework "A structure for supporting or enclosing something else, especially a skeletal support used as the basis for something being constructed." This perfectly describes Struts—a collection of Java code designed to help you build solid applications while saving time. It provides the basic skeleton and plumbing; you focus on the layout and look of each room.

Interestingly, the dictionary offers an alternative definition of a framework: "A set of assumptions, concepts, values, and practices that constitutes a way of viewing reality." This describes Struts as well—it's a way of looking at things. Struts saves you time by allowing you to view complex applications as a series of basic components: Views, Action Classes, and Model components.

"... And Frameworks Are Important Because?"

Using a framework means that you don't have to spend time building your entire application. You can focus on coding the business logic and the presentation layer of the application—not the overhead pieces like figuring out how to capture user input or figuring out how to generate drop-down boxes on a Web page.

Using a framework also helps you encode best practices. The framework developers have put a lot of thought into the best approaches to application building—why reinvent this yourself?

Another benefit of using a framework is that it allows your code (at least in the case of Struts) to be highly platform independent. For example, the same Struts code should work under Tomcat on an old Windows machine as runs using Weblogic on Linux or Solaris in production. And this can be accomplished without even recompiling in many cases—the same Web application (or ". war" file) can simply be copied from one server to another.

Another extremely important benefit—especially if you're relatively new to Web development—is that it gives you a place to start. Any developer will tell you it's easier to take a basic application and modify it than it is to build something from scratch. This feature of Struts can save you days or weeks of planning and development.

Today, I create virtually nothing from scratch. Almost no one who is an experienced developer does. In fact, some of the greatest successes in software development were based on this exact idea. For example, in 1991 when Linus Torvalds began building the operating system that today is Linux, he began with the operating system Minix. He got a copy of the Minix source code, looked it over in detail, and used it as the basis for Linux. And while the first launch of Linux contained none of the original Minix code, Linus surely went further, faster because he had it to start with.

How Does Struts Work?

Struts is based on the time-proven Model-View-Controller (MVC) design pattern. The MVC pattern is widely recognized as being among the most well-developed and mature design patterns in use. By using the MVC design pattern, processing is broken into three distinct sections aptly named the Model, the View, and the Controller. These are described in the following subsections:

Model Components

Model components provide a "model" of the business logic or data behind a Struts program. For example, in a Struts application that manages customer information, it may be appropriate to have a "Customer" Model component that provides program access to information about customers.

It's very common for Model components to provide interfaces to databases or back-end systems. For example, if a Struts application needs to access employee information that is kept in an enterprise HR information system, it might be appropriate to design an "Employee" Model component that acts as an interface between the Struts application and the HR information system.

Model components are generally standard Java classes. There is no specifically required format for a Model component, so it may be possible to reuse Java code written for other projects.

View Components

View components are those pieces of an application that present information to users and accept input. In Struts applications, these correspond to Web pages.

View components are used to display the information provided by Model components. For example, the "Customer" Model component discussed above would need a View component to display its information. Usually, there will one or more View components for each Web page in a Struts application.

View components are generally built using JavaServer Page (JSP) files. Struts provides a large number of "JSP Custom Tags" (sometimes referred to as Struts Tags) which extend the normal capabilities of JSP and simplify the development of View components.

Controller Components

Controller components coordinate activities in the application. This may mean taking data from the user and updating a database through a Model component, or it may mean detecting an error condition with a back-end system and directing the user through special error processing. Controller components accept data from the users, decide which Model components need to be updated, and then decide which View component needs to be called to display the results.

One of the major contributions of Controller components is that they allow the developer to remove much of the error handling logic from the JSP pages in their application. (After all, if errors in processing occur, the Controller component forwards to an error-processing View component, not the primary results View component.) This can significantly simplify the logic in the pages and make them easier to develop and maintain.

Controller components in Struts are Java classes and must be built using specific rules. They are usually referred to as "Action classes."

Go to page: 1  2  Next  


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


Enterprise Java Archives

Flash Demo: Learn how IBM Information Server Blade is easy to manage, highly scalable and efficient.
Whitepaper: Enterprise Information Integration--Deployment Best Practices for Low-Cost Implementation
Guide to Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.
Intel Go Parallel Portal: Translating Multicore Power into Application Performance
Is it time to make your move to the multi-threaded and parallel processing world? Find out!



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: 7.0, Microsoft's Lucky Version?
Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Windows Server 2008
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES