Struts & spring framework issuesPresentation Transcript
Struts & Spring Framework
Struts is an open-source web application
framework from apache for developing Java EE
It was originally created by Craig McClanahan and
donated to the Apache Foundation in May, 2000.
Formerly located under the Apache Jakarta
Project and known as Jakarta Struts, it became a
top-level Apache project in 2005.
It uses and extends the Java Servlet API to
encourage developers to adopt a model-view-
controller (MVC) architecture.
Struts offers a set of tag libraries to support the
faster development of the different layers of the
The Struts Framework is a standard for developing
well-architected Web applications. It has the following
Based on the Model-View-Controller (MVC) design
paradigm, distinctly separating all three levels:
◦ Model: application
◦ View: presentation of data (JSP, HTML)
◦ Controller: routing of the application flow
Implements the JSP Model 2 Architecture
Stores application routing information and request
mapping in a single core file, struts-config.xml
◦ Model: application state(Represent Data Layer)
◦ View: presentation of data (JSP, HTML)(represent the data
processed by the model component)
◦ Controller: routing of the application flow(Responsible for
interaction b/w model & controller ·
All incoming requests are intercepted by the Struts servlet
The Struts Configuration file struts-config.xml is used by the
controller to determine the routing of the flow.
This flows consists of an alternation between two
FromView to Action: A user clicks on a link or submits a
form on an HTML or JSP page.The controller receives the
request, looks up the mapping for this request, and forwards
it to an action.The action in turn calls a Model layer
(Business layer) service or function.
From Action toView: After the call to an underlying
function or service returns to the action class, the action
forwards to a resource in theView layer and a page is
displayed in a web browser.
Spring is a light weight and open source
framework created by Rod Johnson in 2003.
Spring is a complete and a modular framework, i.e. ,
spring framework can be used for all layer
implementations for a real time application.
Spring can be used for the development of
particular layer of a real time application unlike
struts [ only for front end related ] and hibernate [
only for database related ], but with spring we can
develop all layers.
Spring framework is said to be a non-invasive means it doesn’t
force a programmer to extend or implement their class from any
predefined class or interface given by Spring API, in struts we used
to extend Action Class right that’s why struts is said to be invasive.
Spring is light weight framework because of its POJO (plain old Java
objects)model; when it comes to size and transparency.The basic
version of spring framework is around 2MB.
Spring Framework made J2EE application development little easier,
by introducing POJO model
Spring having this much of demand because of the following 3
3. Loose Coupling
Spring Framework Architecture
Spring is modular, allowing you to pick
and choose which modules are applicable
to you, without having to bring in the rest.
The Spring Framework provides about 20
modules which can be used based on an
Actually in spring 1.x, the framework has
divided into 7 well defined modules. But
in 2.x framework is divided into 6
◦ Spring Core Module
◦ Spring Context [ J2EE ]
◦ Spring DAO Module [ Spring JDBC ]
◦ Spring ORM module
◦ Spring AOP [ Aspect Oriented Programming ]
◦ SpringWEB-MVC Module
Spring Core Module is the base for all
modules, and very important.
Core modules are :
Aspect oriented programming(AOP)
Object relational mapping(ORM)
Data access object(DAO)
Aspect-oriented programming: enables
implementing cross-cutting concerns.
Object relational mapping:The ORM module provides
integration layers for popular object-relational mapping APIs,
including JPA, JDO, Hibernate,.
Data access object: working with relational database
management systems on the Java platform
using JDBC and object-relational mapping tools and
with NoSQL databases.
Web-MVC: The Web module provides basic web-oriented
integration features such as multipart file-upload functionality
and the initialization of the IoC(Inversion of contrl) container
using servlet listeners and a web-oriented application
The Web-Servlet module contains Spring's model-view-
controller (MVC) implementation for web applications.
Difference b/w struts & spring framework
Struts is a sophisticated framework
offering the easy 2 develop, structured
view/presentation layer of the MVC
Springs is a Lightweight Inversion of
Control and Aspect Oriented
Container Framework. It is just not a
framework to integrate / plug in at the
it provides a framework to integrate
OR mapping, JDBC etc.,
Struts can be used as the presentation
tier in Spring.
Struts is mainly a presentation layer
framework, like redirecting to a
particular page ,doing client side
validations etc which otherwise very
tedious using jsp and servlets.
Spring is a complete J2EE framework
having seven independent layers which
can be used all together or few layers
integrated with some other
framework. Spring provides declarative
transaction management and AOP.
One layer of spring is for presentation
purpose like struts but for only
presentation layer, struts is better than
Struts 2 has AJAX theme. Spring is not.
Struts is developed with a Front
Controller and dispatcher pattern.
Where in all the requests go to the
ActionServlet thereby routed to the
module specific Request Processor
which then loads the associated Form
Beans, perform validations and then
handovers the control to the
appropriate Action class with the help
of the action mapping specified in
Spring does not route the request in a
specific way like this, rather it allows
to you to design in your own way
however in allowing to exploit the
power of framework, it allows you to
use the Aspect Oriented Programming
and Inversion of Control in a great
way with great deal of declarative
programming with the XML.
Commons framework can be
integrated to leverage the validation in
spring framework too.
Struts 2 tags are style sheet-driven,
making it easier to develop consistent
Spring is not.