Showing posts with label MVC Pattern. Show all posts
Showing posts with label MVC Pattern. Show all posts

Sunday, June 14, 2009

Struts Framework in Brief

Jakarta Struts is open source implementation of MVC 2 (Model-View-Controller) pattern for the development of web based applications. Jakarta Struts is robust architecture and can be used for the development of application of any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java. Struts is a Web-based user interface framework also an open source framework. It is a matured and proven framework, which has been used in many J2EE projects.

Struts framework was created by Craig R. McClanahan and donated to the Apache Software Foundation in 2000. The Project now has several committers, and many developers are contributing to overall to the framework.

Struts is a open source framework which make building of the web applications easier based on the java Servlet and JavaServer pages technologies. The core of the Struts framework is a flexible control layer based on standard technologies like Java Servlets, JavaBeans, ResourceBundles, and XML, as well as various Jakarta Commons packages. Struts encourages application architectures based on the Model 2 approach (MVC 2), a variation of the classic Model-View-Controller (MVC) design paradigm.

Struts frames work is based on three components.

Model: A model represents an application’s data and contains the busuiness logic for accessing and manipulating that data. Any data that is part of the persistent state of the application should reside in the model objects. The business objects update the application state. ActionForm bean represents the Model state at a session or request level, and not at a persistent level. Model services are accessed by the controller for either querying or effecting a change in the model state. The model notifies the view when a state change occurs in the model. The JSP file reads information from the ActionForm bean using JSP tags. Components like business logic /business processes and data are the part of model.

The business logic updates the state of the model and helps control the flow of the application. With Struts this is done with an Action class as a thin wrapper to the actual business logic.

View: The view is responsible for rendering the state of the model. The presentation semantics are encapsulated within the view, therefore model data can be adapted for several different kinds of clients.The view modifies itself when a change in the model is communicated to the view. A view forwards user input to the controller.The view is simply a JSP file. There is no flow logic, no business logic, and no model information just tags. Tags are one of the things that make Struts unique compared to other frameworks like Velocity. HTML, JSP are the view components.

Controller: The controller is responsible for intercepting and translating user input into actions to be performed by the model. The controller is responsible for selecting the next view based on user input and the outcome of model operations.The Controller receives the request from the browser, and makes the decision where to send the request. With Struts, the Controller is a command design pattern implemented as a servlet. The struts-config.xml file configures the Controller. Action Servlet of Struts is part of Controller components which works as front controller to handle all the requests.

Struts provides its own Controller component and integrates with other technologies to provide the Model and the View. For the Model, Struts can interact with standard data access technologies, like JDBC and EJB, as well as most any third-party packages, like Hibernate, iBATIS, or Object Relational Bridge. For the View, Struts works well with JavaServer Pages, including JSTL and JSF, as well as Velocity Templates, XSLT, and other presentation systems.

Struts is a set of cooperating classes, servlets, and JSP tags that make up a reusable MVC 2 design. This definition implies that Struts is a framework, rather than a library, but Struts also contains an extensive tag library and utility classes that work independently of the framework.

Developing web application using struts frame work is fairly complex, but it eases things after it is setup. It encourages software development following the MVC design pattern. Many web applications are JSP-only or Servlets-only. With JSP and Servlets, Java code is embedded in the HTML code and the Java code calls println methods to generate the HTML code respectively. Both approaches have their advantages and drawbacks. Struts gathers their strengths to get the best of their association.

Read more...

Friday, June 12, 2009

Model View Controller (MVC) Design Pattern

Model-View-Controller (MVC) is a design pattern put together to help control change. MVC decouples interface from business logic and data. The MVC (Model-View-Controller) architecture the client request is first intercepted by a servlet referred as controller servlet, this servlet handles the initial processing of the request and determines which JSP page to display next. Here the controller servlet is the single point of entry, there is a clear sepration of business logic, presentation output and request processing.

MCV architecture is a way of decomposing an application into three parts:

Model : The model contains the core of the application's functionality. The model encapsulates the state of the application. Sometimes the only functionality it contains is state. It knows nothing about the view or controller.The model maintains the state and data that the application represents.

View: The view provides the presentation of the model. It is the look of the application. The view can access the model getters, but it has no knowledge of the setters. In addition, it knows nothing about the controller. The view should be notified when changes to the model occur.The view allows the display of information about the model to the user.

Controller: The controller reacts to the user input. It creates and sets the model.The controller allows the user to manipulate the application.

MVC Design Pattern comprised of two models.
  • MVC Model 1 is a Page Centric Architechure
  • MVC Model 2 is a Serlet Centric Architechure
Struts frame work extensively makes use of MVC 2 Architecture

MVC was originally applied in the graphical user interaction model of input, processing and output. In Struts, the view is handled by JSPs and presentation components, the model is represented by Java Beans and the controller uses Servlets to perform its action.

Read more...
Blog Widget by LinkWithin

JS-Kit Comments

  © Blogger template Newspaper III by Ourblogtemplates.com 2008

Back to TOP