ch5
ch5
Sem-5
5 Spring,Strut
Topics Covered
1. Introduction to spring framework
2. spring architecture
3. spring and MVC
4. Spring context definition
5. Inversion of control in spring
6. Ascept oriented programming in spring
7. Understanding Struts Framework
8. Comparision with MVC using RequestDispatcher and the EL
9. Struts Flow of Control
10. Processing Requests with Action Objects
11. Handling Request Parameters with FormBeans
12. Prepopulating and Redisplaying Input Forms
13. Using Properties Files
Page 1 of 12
J2EE 5. Spring,Strut B.C.A. Sem-5
Module
The Core Container consists of the Core, Beans, Context, and Expression Language
modules whose detail is as follows:
The Core module provides the fundamental parts of the framework, including the IoC
and Dependency Injection features.
The Bean module provides BeanFactory which is a sophisticated
implementation of the factory pattern.
The Context module builds on the solid base provided by the Core and Beans modules
and it is a medium to access any objects defined and configured. The
ApplicationContext interface is the focal point of the Context module.
The Expression Language module provides a powerful expression language for
querying and manipulating an object graph at runtime.
Data Access/Integration
The Data Access/Integration layer consists of the JDBC, ORM, OXM, JMS and
Transaction modules whose detail is as follows:
The JDBC module provides a JDBC-abstraction layer that removes the need to do
tedious JDBC related coding.
The ORM module provides integration layers for popular object-relational mapping
APIs, including JPA, JDO, Hibernate, and iBatis.
The OXM module provides an abstraction layer that supports Object/XML mapping
implementations for JAXB, Castor, XMLBeans, JiBX and XStream.
The Java Messaging Service JMS module contains features for producing and
consuming messages.
Page 2 of 12
J2EE 5. Spring,Strut B.C.A. Sem-5
Web
The Web layer consists of the Web, Web-Servlet, Web-Struts, and Web-Portlet
modules whose detail is as follows:
The Web module provides basic web-oriented integration features such as multipart
file-upload functionality and the initialization of the IoC container using servlet
listeners and a web-oriented application context.
The Web-Servlet module contains Spring's model-view-controller
(MVC)
Miscellaneous
There are few other important modules like AOP, Aspects, Instrumentation, Web and
Test modules whose detail is as follows:
The AOP module provides aspect-oriented programming implementation allowing you
to define method-interceptors and pointcuts to cleanly decouple code that implements
functionality that should be separated.
The Aspects module provides integration with AspectJ which is again a powerful and
mature aspect oriented programming (AOP) framework.
The Instrumentation module provides class instrumentation support and class loader
implementations to be used in certain application servers.
The Test module supports the testing of Spring components with JUnit or TestNG
frameworks.
It offers a meaningful exception hierarchy, which simplifies the error handling strategy.
AOP Framework
MVC Framework
It comes with MVC web application framework, built on core spring functionality.
It is highly configurable via strategy interfaces and accommodates multiple view
technologies like JSP.
Page 3 of 12
J2EE 5. Spring,Strut B.C.A. Sem-5
Spring Architecture
Spring is well organized architecture consisting of 7 modules.
1)Spring AOP:it is one of the key component of spring.AOP is used in spring.it is used to
provide declarative enterprise services.
2)Spring ORM:the ORM package is related to the database access.It provides integration
layers for popular object-relational mapping API’s.
3)Spring web:it is a part of spring’s web application development stack, which includes
spring MVC.
5)Spring context:this package build on the beans package to add support for message
sources and for the observer design pattern.
6)Spring web MVC:this is the module which provides the MVC implementation for the
web application.
7)Spring Core:It is the most important component of spring framework.It provides the
Dependancy injection features.It seprates the dependencies like initialization, creation and
access of the objects.
Page 4 of 12
J2EE 5. Spring,Strut B.C.A. Sem-5
Page 5 of 12
J2EE 5. Spring,Strut B.C.A. Sem-5
3. The DispatcherServlet will take help from ViewResolver to pickup the defined view for
the request.
4. Once view is finalized, The DispatcherServlet passes the model data to the view which
is finally rendered on the browser.
Step 3: So request transfer to the Controller, and then controller will process the request by
executing appropriate methods and returns ModeAndView object (contains Model data and
View name) back to the DispatcherServlet
Step 4: Now DispatcherServlet send the model object to the ViewResolver to get the actual
view page
Step 5: Finally DispatcherServlet will pass the Model object to the View page to display the
result
Dependency Injection
Page 6 of 12
J2EE 5. Spring,Strut B.C.A. Sem-5
The application classes in a complex java application should be independent so that the
other java classes can be reused and can be tested independently of other classes while
doing unit testing.
DI joins these classes together and at the same time keeps them independent.
DI can be well defined when it is distinguish separately in two parts.
For example, class A is dependent on class B.The second part, injection states that all
this means is that class B will get injected into class A by the IOC.
DI is implemented by passing parameters to the constructor.
AOP Terminologies
Before we start working with AOP, let us become familiar with the AOP concepts and
terminology. These terms are not specific to Spring, rather they are related to AOP.
Terms Description
Page 7 of 12
J2EE 5. Spring,Strut B.C.A. Sem-5
Page 8 of 12
J2EE 5. Spring,Strut B.C.A. Sem-5
3) Bean tags
Strut provides a set of custom JSP tags that allows you to easily output the
properties of JavaBean component.
4) HTML tags
Strut provide a set of custom JSP tag to create HTML forms that are related to
javabean components.
It allows us to get initial form-field values from java objects and redisplay
forms with some or all previously entered values intact.
5) Form field validation
It has built in capability for checking that form values are in the required
format which is known as form field validation.
If values are missing or in improper format, the form can be automatically
reappeared with error message.
The validation can be performed either on the server or both server and client.
6) Consistent approach
Strut push you for regular use of MVC throughout your application.
Disadvantages
1) Bigger learning curve
To use MVC with struts one has to be comfortable with the standard JSP and
servlet API and a large and complicated framework that is almost equal in size
to the core system.
It is specially significant with smaller projects, near-term deadlines and less
experience developers mush time can be spent learning struts for building an
actual system.
2) Worse documentation
With compared to the servlet and JSP API, strut has fewer online resources,
and many first time users find the online apache documentation confusing and
poorly organized.
3) Less transparent
Strut applications are harder to understand.
Page 9 of 12
J2EE 5. Spring,Strut B.C.A. Sem-5
data.
Once it examines the user input data in the bean, the execute method invokes
business logic and data access logic, placing the result in normal beans stored
in the request.
4) strut forward the requests to the appropriate JSP page
strut normally invokes the result page with RequestDispatcher.
Forward although request.sendRedirect is occasionally used.In most real
applications, the results page uses bean:write.
Page 10 of 12
J2EE 5. Spring,Strut B.C.A. Sem-5
You need to create an input form whose ACTION corresponds to one of the
*.do addresses listed in struts-config.xml.
At a minimum, the input form should look like this:
<Form action=”…/xyz.do”…>…</form>
6) Display result in JSP
Strut is built around the MVC architecture, these JSP pages should avoid JSP
scripting elements whenever possible.
Page 12 of 12