You can easily implement the MVC approach by using RequestDispatcher.forward in your servlets and jsp:getProperty or the JSP 2.0 expression language in your JSP pages. However, Struts offers a number of significant advantages over these techniques alone. Here is a summary:
* Centralized File-Based Configuration.
Rather than hard-coding information into Java programs, many Struts values are represented in XML or property files. This loose coupling means that many changes can be made without modifying or recompiling Java code, and that wholesale changes can be made by editing a single file. This approach also lets Java and Web developers focus on their specific tasks (implementing business logic, presenting certain values to clients, etc.) without needing to know about the overall system layout.
* Form Beans.
In JSP, you can use property=”*” with jsp:setProperty to automatically populate a JavaBean component based on incoming request parameters. Unfortunately, however, in the standard API this capability is unavailable to servlets, even though with MVC it is really servlets, not JSP pages, that should usually be the target of form submissions. Apache Struts extends this capability to Java code and adds in several useful utilities, all of which serve to greatly simplify the processing of request parameters.
* Bean Tags.
Apache Struts provides a set of custom JSP tags (bean:write, in particular) that let you easily output the properties of JavaBeans components. Basically, these are concise and powerful variations of the standard jsp:useBean and jsp:getProperty tags.
* HTML Tags.
Apache Struts provides a set of custom JSP tags to create HTML forms that are associated with JavaBeans components. This bean/form association serves two useful purposes:
o It lets you get initial form-field values from Java objects.
o It lets you redisplay forms with some or all previously entered values intact.
* Form Field Validation.
Apache Struts has builtin capabilities for checking that form values are in the required format. If values are missing or in an improper format, the form can be automatically redisplayed with error messages and with the previously entered values maintained.
This validation can be performed on the server (in Java), or both on the server and on the client (in JavaScript).
* Consistent Approach.
Struts encourages consistent use of MVC throughout your application.
Now, if these advantages sound significant, they were meant to. But, before you rush out and convert all your existing projects to Struts, look at the disadvantages as well.
Recent Comments