Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Apache Struts 2 helps you create an extensible development environment for your application, based on industry standards and proven design patterns.

Struts is a Model View Controller framework. Struts provides Controller and View components, and integrates with other technologies to provide the Model. The framework's Controller acts as a bridge between the application's Model and the web View.

...

Struts Tags in a nutshell

The Struts Tags help you create rich web applications with a minimum of coding. Much, and often most, of the coding effort in a web application goes into creating and maintain the pages. The Struts Tags reduce effort by reducing code.

Code Block
titleBefore Struts Tags (a partial form)


<% User user = ActionContext.getContext() %>
<form action="Profile!update.action" method="post">
 <table>
  <tr>
    <td> align="right"<label>First name:</label></td>
    <td><input type="text" name="user.firstname"
       value="<%=user.getFirstname() %> /></td>
   </tr>
...
   <td>
   <input type="radio" name="user.gender" value="0" 	 
     id="user.gender0" 
     <% if (user.getGender()==0) { %> 
     checked="checked" %> } %> />
     <label for="user.gender0">Female</label>
...

Looking over the markup, it's easy to see what why web development is hard! So far, we've only coded two controls, and there are six more to go! Let's finish the form using Struts 2 Tags.

Code Block
titleAfter Struts Tags (a complete form)

<s:actionerror/>
<s:form action="Profile!update" validate="true">
 <s:textfield label="Username" name="username"/>
 <s:password label="Password" name="password"/>
 <s:password label="(Repeat) Password" name="password2"/>
 <s:textfield label="Full Name" name="fullName"/>
 <s:textfield label="From Address" name="fromAddress"/>
 <s:textfield label="Reply To Address" name="replyToAddress"/>
 <s:submit value="Save" name="Save"/>
 <s:submit action="Register!cancel" value="Cancel" name="Cancel"
   onclick="form.onsubmit=null"/>
</s:form>

In about the same amount of code as two controls, the Struts Tags can a complete form with eight controls. Not only is there less code, but the code is easier to read and maintain.

Image Added

The Struts Tags also support validation and localization as a first-class features. So not only is there less code, but there more utility.

Struts configuration in a nutshell

...