Sunday, October 14, 2012

Struts & Model-View-Controller (MVC) Architecture


Apache Struts is a free open-source framework for creating Java web applications.
Web applications differ from conventional websites in that web applications can create a dynamic response. Many websites deliver only static pages. A web application can interact with databases and business logic engines to customize a response.
Web applications based on JavaServer Pages sometimes commingle database code, page design code, and control flow code. In practice, we find that unless these concerns are separated, larger applications become difficult to maintain.
One way to separate concerns in a software application is to use a Model-View-Controller (MVC) architecture. The Model represents the business or database code, the View represents the page design code, and the Controller represents the navigational code. The Struts framework is designed to help developers create web applications that utilize a MVC architecture.
The framework provides three key components:
  • A "request" handler provided by the application developer that is mapped to a standard URI.
  • A "response" handler that transfers control to another resource which completes the response.
  • A tag library that helps developers create interactive form-based applications with server pages.
The framework's architecture and tags are buzzword compliant. Struts works well with conventional REST applications and with nouveau technologies like SOAP and AJAX.
Which version of Struts to use?
A beta release of Struts 2 is now available, and a stable release is anticipated by the end of the year. In the meantime, the prudent course would be to start new projects with WebWork 2.2, at least until there is a stable release of Struts 2.0.
WebWork 2 is going to be supported for some time to come, just as Struts 1 will be supported. Both products have a robust user community, and many of us have mature projects in production that will never be migrated to a new major release.
Is Struts 1 obsolete?
No.
There is a robust and vibrant community of developers using Struts 1 in production, and we expect that thousands of teams will continue to base new projects on Struts 1, and continue to support existing projects, for many, many years to come.
New and improved extensions for Struts 1 continue to appear regularly. In 2006 alone, we've seen releases of Hoople, Strecks, JSP Control Tags, Sprout, Spring Web Flow, DWR, Calyxo, FormDef, andJava Web Parts. There are dozens of books and hundreds of articles available to help people get started with Struts 1 or improve the application they already have.
Since the merger, Struts 1 has gone on to release a new minor version, Struts 1.3, and new 1.x releases are being planned. Struts 1 continues to be the most popular and best supported web application framework for Java.
Of course, if you are starting a new project, and have your choice of frameworks, this might be a good time to consider whether you would like to continue to use Struts 1 or whether it's time to try Struts 2.

What is Model-View-Controller (MVC) Architecture

 Model-View-Controller architecture is all about dividing application components into three different categories Model, View and the Controller. Components of the MVC architecture has unique responsibility and each component is independent of the other component. Changes in one component will have no or less impact on other component. Responsibilities of the components are: -
Model: Model is responsible for providing the data from the database and saving the data into the data store. All the business logic are implemented in the Model. Data entered by the user through View are check in the model before saving into the database. Data access, Data validation and the data saving logic are part of Model. -
View: View represents the user view of the application and is responsible for taking the input from the user, dispatching the request to the controller and then receiving response from the controller and displaying the result to the user. HTML, JSPs, Custom Tag Libraries and Resources files are the part of view component. -
Controller: Controller is intermediary between Model and View. Controller is responsible for receiving the request from client. Once request is received from client it executes the appropriate business logic from the Model and then produce the output to the user using the View component. ActionServlet, Action, ActionForm and struts-config.xml are the part of Controller. -

No comments:

Post a Comment