An Introduction to struts

Source: Internet
Author: User
Tags old windows websphere application server
Document directory
  • Introduction
  • "What is struts and why shoshould I care? "
  • "Struts is a Web application 'framework '? "
  • "... And frameworks are important because? "
  • How does struts work?
  • "Bottom line benefits of MVC"
  • Case study: Right Hand Manager Software
  • Conclusions
  • About the author

An Introduction to struts
By Kevin Bedell

 

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 shoshould 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. it is a non-proprietary and works with exactly 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 calla 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 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 shocould 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 your 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 usually ally 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.

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 MERS MERs.

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 wowould 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 extends erver page (JSP) files. struts provides a large number of "jsp m 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 ."

"Bottom line benefits of MVC"

Remember the earlier definition that described a framework as "a set of assumptions, concepts, values, and practices that constitutes a way of viewing reality? "This is one of the most powerful benefits of the MVC pattern. it allows developers to think about (and Design) complex applications as a series of relatively simple model, view, and controller components. this leads to better, more consistent, and more easily maintainable designs. in addition, it helps avoid the common pitfall of having each developer on a project choose a different approach for their work.

Case study: Right Hand Manager Software

When Dennis Doubleday and others on his team at right hand Manager software (http://www.righthandmanager.com) were evaluating how they wanted to do development, they decided right away that they wanted to use a framework that was based on the MVC design pattern. this demo-came after having built a number of applications based on the J2EE platform. on previous projects, Dennis says "we spent a lot of time developing the re-usable framework and not our application."

In other words, they wanted a framework that allowed them to focus on building their application without spending a of lot of time writing the code that organized and coordinated processing. after reviewing a number of other competing frameworks, they settled on struts for a number of reasons-some technical and some not. the struts technical features that were important to them were:

  • Struts performs well.
  • Struts has a sound neural tural model with a modest learning curve.
  • Struts is very solid and stable.
  • Struts has a strong set of M tag libraries that simplify JSP development.

Also, according to Dennis, "struts is very competitive technically, but to my mind the biggest advantages struts has over competing technologies are practical." These features are:

  • Ongoing development by a large number of committed users/developers
  • Knowledgeable and responsive project leadership
  • Generally quick (and sometimes near-instant) problem resolution via the struts mailing list or archives
  • Access to source code
  • Strong connection to and commitment to future integration with forward-looking technologies like jstl and Java Server faces
  • Increasing mind share that we recommend CT will make it easier to hire new developers already familiar with the Framework"

How have things worked out for them? Again, according to Dennis, "we are very happy with the way it is working out so far. there is very little burden on us to understand or implement the plumbing of our application; we simply create our action and Form class extensions and our application model beans."

Their results have been faster, more consistent development, and have excellent support. plus, the platform they are building on is stable and constantly being improved. oh-and by the way-it's free and you can get all the source code if you want it.

Conclusions

So, the question arises, shocould you consider adopting struts? Of course, your answer depends on your particle circumstances and environment, but here are some criteria to consider:

  • Are you using the J2EE platform (that is, developing applications using J2EE-compliant servers such as WebLogic Server, WebSphere Application Server, Jakarta Tomcat, JBoss, Iplanet, and so forth )? If the answer to this is yes, Struts is likely worth considering.
  • Do your developers have Java expertise? Although this isn't a "make or break" criterion, it helps. if your developers don't have Java experience but you are dedicated to moving to Java anyway, Struts may actually make the transition easier.
  • Are you building applications that need to work in a web browser? This is the niche that struts fills. If the answer is no, Struts isn't for you. Unless you have requirements for browser-based application delivery, Struts won't add much value.
  • Are you building applications now that use JavaServer Pages (JSP )? If so, you shoshould definitely be looking at struts. It may increase your developer productivity significantly.
  • Is your development team considering building a "Custom framework" for Building Web-based applications? If so, ask them to justifyNotUsing struts. anything they wocould build on their own wowould likely not undergo near the amount of testing and development that struts has. while they may have good reasons for not using it, Struts shocould definitely be on their radar.

To summarize, Struts is an application "Framework" for Building Web-based applications in Java using the J2EE platform. struts makes developers more productive by giving them prebuilt components to assemble applications from. struts was built using industry best practices including the MVC design pattern and it can be deployed in a wide range of environments.

If you are using the Java/J2EE platform-and especially if you are currently developing applications using extends erver pages (JSP)-You shocould be considering struts for the development of browser-based applications.

About the author

Kevin Bedell has a degree in engineering from Michigan tech and an MBA from the crummer Graduate School of Business at rol?college. portions of this article were adapted from material in his upcoming book for SAMs Publishing,Struts kick start(ISBN: 0-672-32472-5). A companion PowerPoint presentation suitable for presenting these ideas to a management group is available at http://www.strutskickstart.com.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.