Struts 2 – Makes developer's life easier

When ever a new framework got released, first questions from developers are, A) Will this make my life easier? B) more documentation? C) Is it easy to understand and intuitive? As soon as, Apache released initial details about Struts 2, I got a sense that it is the framework for next generation. Now after reading some good books and documentations, I can strongly say that yes, struts 2 is the next generation framework for web development. Now we are in the position of talking about less configuration, and less coding, struts 2 is the answer for that. 

MVC Shift:

A fundamental change from Struts 1 is, constitute of Model-Viewer-Controller pattern, beans/EJBs are no longer a model rather the action servlet itself act as a model and action. The filters, interceptors are the controllers for Struts 2. 

Controller – Dispatcher Filters, Interceptors

Model – Action Servlet

View – JSPs 

Configuration Changes:

As per Struts 2, Filters and Interceptors can act as controller, this is really good because filters are basic J2EE servlets and highly reusable. So filters will be configured in web.xml and interceptors would be configured in struts.xml. One more change is struts.xml would be placed in classes dir not in WEB-INF dir. 

The nightmare of maintaining multiple struts xml files of struts 1 was answered really well in struts 2. In Struts2, we can include other struts configuration files in struts xml file. This would improve maintainability and modularize of multiple struts xml files. 

Action Classes: 

Action classes are now a POJO (Plain Old Java Objects), for sake of naming convention, we have to use execute name for method. But that can be changed by using configurations. Action classes would have an execute method and bunch of getters/setters. One interesting thing is, there is no need of getting many model beans and setting it in request scope, and then display it in JSP. Struts 2 is using highly intuitive ONGL (Object Graph Navigational Language) to access objects from value stack. It is not required that we have to champion of ONGL to use Struts 2, because Struts 2 provides JSP tags to get object data from stacks. Since we are dealing with low level language here, a basic understanding of ONGL is nice to have. 

Dependency Injection

Struts 2 are highly depend on dependency injection to access other business service objects. I don’t want to dive into details about dependency injection here, because now everybody knows what is dependency injection and its advantages etc. 

Interceptors

One good thing about Struts 2 is, introduction of interceptors, it is very useful for cross cutting functionalities and simplifies some reusable business logics. Interceptors are like a use-as-you-want basis, really good for plug-n-play, very loosely coupled. 

Free maker, Velocity Support

There are something we can’t configure so far in web application because they are consider an independent entity of web applications, but Struts 2 tries to integrate Free Maker, Velocity (template tools) also configurable. This is something required greater understanding before using it. 

Source:

http://struts.apache.org/2.x/docs/guides.html

http://infoq.com/minibooks/startingstruts2

http://www.ognl.org/2.6.9/Documentation/html/LanguageGuide/ 

Comments

Anonymous said…
Subba,
Good overview of Struts2. Thanks for sharing.

Popular posts from this blog

Coupon Crazy

Google's Killer Application.

Uncontrolled Musing