Struts 2.x : A Framework from ASF :: Introduction
- What is Struts 2.0?
- What is Framework?
- Model View Controller?
- Where does Struts fit in?
- Struts 1.x and 2.x Comparison
- Struts 2.x Architecture
- Struts 2.x Framework Features
What is Struts 2.0? |
You should have following technologies as pre-requisite. if you are going to learn Struts Framework.
- Java
- Servlet/common
- Tomcat
- XML
Struts 2
It is based on WebWork2 framework not extention it contains both feature of webwork2(from OpenSymphony) & struts1 (from Apache)
What is Struts
- Struts is provided by the Apache Software Foundation (ASF), which is a non-profit organization and provides software projects.
- Struts is a part of one of such project- Jakarta Projects.
- Its Initial name was Jakarta Struts but its new name is Apache Struts.
- It is available under Apache License and is a free and open source software.
The Struts project was created by Craig R. McClanahan and donated to Apache Foundation in May 2000
Struts allows JSP/Servlet writers the ability to fashion their web applications using the MVC design pattern.
- The aim of the Struts Project was to provide an open-source framework upon which a web application can be designed by separating presentation logic and business logic.
- Struts solves the problem of coupling of data in web pages.
- The sections of the code that perform a task are separated and they communicate with each other in a pre-defined standard way.
What is Framework? |
What is Framework?
A framework is a set of classes and interfaces that cooperate to solve a specific type of software problem.
Framework Characteristics
- A framework is made up of multiple classes or components, each of which may provide an abstraction of some particular concept.
- The framework defines how these abstractions work together to solve a problem.
- The framework components are reusable.
- A good framework should provide generic behavior that can be utilized across many different types of applications.
Framework Drawbacks
- Frameworks are not flexible – Changes unacceptable to the provider.
- Frameworks impose a way of thinking – Design and code according to the framework.
- Frameworks increase the learning curve.
- Not suited for smaller applications.
Struts Advantage
- Provides a central organizational architecture for building and controlling MVC based web applications
- Enables clean separation between the code for functionality and the code for Presentation
- Built in internationalization (capability of input and display in multiple languages
- Built in extensible authentication and validation
- Allows modular development and easy integration with new components( including Enterprise Components) Separation of Web Oriented programming and Distributed functional programming
Drawback of Struts
Less transparent
- With Struts applications, there is a lot more going on behind the scenes than with normal Java-based Web applications. As a result, Struts applications are:
- Harder to understand
- Harder to benchmark and optimize
Rigid approach
The flip side of the benefit that Struts encourages a consistent approach to MVC is that Struts makes it difficult (but by no means impossible) to use other approaches.
Model View Controller? |
What is MVC Framework?
The Model View Controller design pattern is a technique used to separate Business logic/state (the Model) from User Interface (the View) and program progression/flow (the Control).
This pattern is very useful when it comes to modern web development:
- The majority of modern, high usage websites are dynamically driven. (Change in View, model)
- People well skilled at presentation (HTML writers) seldom know how to develop back-end solutions and visa versa.
- Separating business rules from presentation is good no matter what environment you develop in be it web or desktop.
MVC :: Model View Controller
The View
The view is how data is represented to the user. For instance the view in a web application may be an HTML page(using JSP), an image or other media.
The Model
The model represents the internal data in the system and the actions that can be taken to change that state.
Decide “How to do”
The Controller
The controller is the glue between the model and the view. It is responsible for controlling the flow of the program as well as processing updates from the model to the view and visa versa.
Decide “What to do”
Benefit of MVC
- Promotes Modularity
- Multiple views
- Abstraction
- Allows application to be defined in a flow-chart, use-case or activity diagram which is more easily transferred to implementation.
Where does Struts fit in? |
Where does Struts fit in?
Struts applications are hosted by a web container and can make use of services provided by the container, like handling requests via the HTTP and HTTPS protocol. This frees developers up to focus on building applications that solve a business problem.
Struts 1.x and 2.x Comparison |
Struts 1.x and 2.x Comparison
Struts 1.2 Architecture
Struts 1.2 Directory Structure
Struts 2.x High level Overview of Request Processing
Struts 2.x Architecture in details
Struts 2.3 Application Directory Structure
Struts 2.x Architecture |
Struts Life Cycle
Based on the above diagram, one can explain the user’s request life cycle in Struts 2 as follows:
- User sends a request to the server for requesting for some resource (i.e pages).
- The FilterDispatcher looks at the request and then determines the appropriate Action.
-
Configured interceptors functionalities applies such as validation, file upload etc.
Selected action is executed to perform the requested operation. - Again, configured interceptors are applied to do any post-processing if required.
- Finally the result is prepared by the view and returns the result to the user.
Struts 2.x Framework Features |
Here are some of the great features that may force you to consider Struts2:
- POJO forms and POJO actions : Struts2 has done away with the Action Forms that were an integral part of the Struts framework. With Struts2, you can use any POJO to receive the form input. Similarly, you can now see any POJO as an Action class.
- Tag support : Struts2 has improved the form tags and the new tags allow the developers to write less code.
- AJAX support : Struts2 has recognised the take over by Web2.0 technologies, and has integrated AJAX support into the product by creating AJAX tags, that function very similar to the standard Struts2 tags.
- Easy Integration : Integration with other frameworks like Spring, Tiles and SiteMesh is now easier with a variety of integration available with Struts2.
- Template Support : Support for generating views using templates.
- Plugin Support : The core Struts2 behaviour can be enhanced and augmented by the use of plugins. A number of plugins are available for Struts2.
- Profiling : Struts2 offers integrated profiling to debug and profile the application. In addition to this, Struts also offers integrated debugging with the help of built in debugging tools.
- Easy to modify tags : Tag markups in Struts2 can be tweaked using Freemarker templates. This does not require JSP or java knowledge. Basic HTML, XML and CSS knowledge is enough to modify the tags.
- Promote less configuration : Struts2 promotes less configuration with the help of using default values for various settings. You don’t have to configure something unless it deviates from the default settings set by Struts2.
- View Technologies: : Struts2 has a great support for multiple view options (JSP, Freemarker, Velocity and XSLT)
Recent Comments