Apache Struts
J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View component handles rendering of JSP/html – Controller component handles business logic Each component can be tweaked without knowledge of how another is implemented.
Pitfalls Most developers are not architects – Tier Leakage Without proper care, some components can leak into others. Examples – Embedded Java code in JSP – Actually rendering HTML in Servlet How can we ensure that our web app adheres to a strict MVC approach?
STRUTS! Struts forces you to apply true MVC design principles to your application – Provides rich tag libraries to allow access to objects from the View component – Allows for well-defined Action/Form relationships for the Controller, via XML – Easy mapping back to POJO for the Model component
Form Handling Proper handling of forms – Using the taglibs and form beans, Struts eliminates messy servlet code and populates objects on its own Validating forms and displaying error messages – Client-side validation via XML files – Server-side validation via the Action class – Displays errors in View using tags from the libraries
Other features Centralized file-based configuration – Struts-config.xml Form beans – Useful to populate JavaBean from incoming request parameter from JSP, if necessary Bean tags – To output the values of JavaBeans from JSP HTML tags – Custom JSP tags to create forms associated with JavaBeans Consistent Approach – Enforces better compliance to MVC design approach
Struts Weaknesses Long learning curve Documentation exists (books, online help etc.), but less than the documentation for JSP and Servlets Less transparency – makes it harder to understand, benchmark and optimize.
How did we research the subject? Read articles Read a book on Struts Searched for references, opinions online (Apache website, blogs, forums) Downloaded Struts and played around with it
Our position The numerous benefits of using Struts definitely out-weigh the weaknesses Even with the long learning curve, it is a lot faster/efficient than developing a custom framework Documentation will broaden and get better, which will also help with the long learning curve Next time we will use Struts…
The Future of Struts ?
Questions?