Info |
---|
The framework documentation is written for active web developers and assumes a working knowledge about how Java web applications are built. For more about the underlying nuts and bolts, see the Key Technologies Primer. |
Apache Struts 2 Architecture in a Nutshell
...
The Struts Tags help you create rich web applications with a minimum of coding. Often, much of the coding effort in a web application goes into the pages. The Struts Tags reduce effort by reducing code.
Code Block | ||
---|---|---|
| ||
| ||
<% User user = ActionContext...getContext() %> <form action="Profile_update.action" method="post"> <table> <tr> <td><td align="right"<label>First><label>First name:</label></td> <td><input type="text" name="user.firstname" value="<%=user.getFirstname() %> /></td> </tr> <tr> <td> <input<td><input type="radio" name="user.gender" value="0" id="user.gender0" id="user.gender0" <% if (user.getGender()==0) { %> checked="checked" %> } %> /> <label for="user.gender0">Female</label> </tr> </table> </form> ... |
Looking over the markup, it's easy to see why Java web development without the aid from a modern framework is hard! So far, we've only coded two controls, and there are six more to go! Let's rewrite and finish the form using Struts Tags.
|
|
...
A web application uses a deployment descriptor to initialize resources like filters and listeners. The web deployment descriptor is formatted as a XML document and named web.xml
. Struts can either initializes initialize its resources by scanning your classes using Java packages declared in this web.xml
file, or you can have full control over the configuration via a configuration file, named struts.xml
. These resources include action mappings, to direct input to server-side Action classes, and result types, to select output pages.
Here's a typical configuration (struts.xml
) for a login workflow:
Code Block | ||||
---|---|---|---|---|
| ||||
<struts> <package name="default" extends="struts-default"> <action name="Logon" class="mailreader2.Logon"> <result name="input">/pages/Logon.jsp</result> <result name="cancel" type="redirect-actionredirectAction">Welcome</result> <result type="redirect-actionredirectAction">MainMenu</result> <result name="expired" type="chain">ChangePassword</result> </action> <action name="Logoff" class="mailreader2.Logoff"> <result type="redirect-actionredirectAction">Welcome</result> </action> </package> </struts> |
The framework provides general-purpose defaults, so we can start using Struts right away, "out of the box". Any factory defaults can be overridden in an application's configuration, as needed.
...
An alternate set of JARs for Java 4 are also available. See the "J4" distribution.
Excerpt |
---|