Struts is an open source MVC framework for building Java web applications. It uses the MVC pattern and includes configurable components like actions, interceptors, and results. Struts 2 combines Struts 1 and WebWork and supports features such as AJAX, validation, dependency injection, and theming. The framework follows conventions where actions are POJOs mapped to requests and results in configuration files, with interceptors handling processing between the controller and views.
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Struts
1.
2. It was Developed by Apache.
Struts is a open source framework for building java based
web applications.
It uses Model-View-Controller(MVC) design pattern.
Struts framework is designed to help developers create web
applications that utilize a MVC architecture.
Apache Struts Project offers Two major versions:
Struts1 is recognized as the most popular web applications
framework for java.
Struts2 was the developed by combining Struts1 and
WebWork.
Struts2 = WebWork + Struts1
3. Open Source framework
Configurable MVC components
POJO based action
Ajax support (asynchronous java and xml script)
Integration support (hibernate, spring)
Various Result Types
Various Tag support (checkbox,image,submit etc)
Theme and template support (Tiles plug-in)
4. Action Classes:-Struts 2 framework Action class implements Action interface
and other interfaces are optional .
Threading Model:- Struts 2 framework instantiated Action object for each
request, so there are no thread-safety issues.
Servlet Dependency:- The Struts 2 framework servlet contexts are represented
as simple Maps because it is not coupled to a container allowing Actions to be
tested in isolation.
Testability:- Struts 2 Actions can be tested by instantiating the Action, setting
properties, and invoking methods. Dependency Injection support also makes
testing simpler.
Expression Language:- Struts 2 can use "Object Graph Navigation Language"
(OGNL).
Type Conversion:- Struts 2 uses OGNL for type conversion. The framework
includes converters for basic and common object types and primitives.
Validation:- Struts 2 supports manual validation via the validate method and
also contain the Sub Framework validation .
Control of Action Execution:- Struts 2 supports creating different lifecycles on
a per Action basis via Interceptor Stacks. Custom stacks can be created and
used with different Actions, as needed.
5. Convention problem:-The Struts2 framework more follow the
convention.
Harder to learn:-Struts are harder to learn, benchmark and
optimize
6.
7. Model
Internal state of the application composed of both the data
model and business logic. In struts2 action act as model
serves two roles:
I. Acts as a encapsulation
II. The action serves as a position of data transfer
View:
It provides user interface that presents a representation of
application.
Configuration Files:
Create configuration files to couple the Action, View and
Controllers. These files are struts.xml, web.xml,
struts.properties.
8. Controller: It maps the request to actions.
The filter dispatcher act as controller and is a servlet filter
that inspects each incoming request to determine which
stuts2 action should handle request.
Interceptors will perform the invocation of action. They are
invoked and executed before and after the action or
request processing. Interceptors also perform tasks such as
data validation ,type conversion and file uploads.
Controller also provides or handles:
• ActionServlet(provided by Struts)
• RequestProcessor(provided Struts)
• Action(provided by developer)
• Action mapping(specified by developer)
9. 1. Create the directory structure.
2. Create input page
3. Provide the entry of controller in(web.xml)file
4. Create the action class POJO
5. Map the request in(struts.xml)file and define the view
components
6. Create view components(jsp pages)
7. Load jar files
8. Start server and deploy project.
10.
11.
12.
13. This is simple bean class. In struts 2, action is POJO (Plain Old
Java Object). It has one extra method execute i.e. invoked by
struts framework by default.
14. It is the important file from where struts framework gets
information about the action and decides which result to be
invoked.
15. It is the view component the displays information of the
action. Here, we are using struts tags to get the information.