Struts Tutorial
What is Struts?
Struts is a open source framework which make building of the web applications easier based on the java Servlet
and JavaServer pages technologies.
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.
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.
Struts is based on Model-View-Controller (MVC) design paradigm, it is an implementation of JSP Model 2 Architecture. For more of Model-View-Controller (MVC) click here . Consists of 8 Top-Level Packagesand approx 250 Classes and Interfaces.
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.
Client Browser
An HTTP request from the client browser creates an event. The Web container will respond with an HTTP response.
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.
Business logic
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.
Model
A model represents an application’s data and contains the 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.
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.