Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier...

11
Apache Struts

Transcript of Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier...

Page 1: Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.

Apache Struts

Page 2: Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.

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.

Page 3: Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.

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?

Page 4: Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.

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

Page 5: Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.

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

Page 6: Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.

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

Page 7: Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.

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.

Page 8: Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.

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

Page 9: Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.

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…

Page 10: Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.

The Future of Struts

• ?

Page 11: Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.

Questions?