SlideShare a Scribd company logo
1
What is MVC?
2
MVC – An overview
Controller
View
Model
Response
3
Advantage of MVC
 Navigation control is centralized. Now only controller contains the
logic to determine the next page.
 Easy to maintain
 Easy to extend
 Easy to test
 Better separation of concerns
 Reusability
4
MVC Architecture
web.xml
Multiply
Login
Logout
Add
Controller
Login
Logout
Add
Multiply
Client’s Request
5
Spring MVC Architecture
Front
Controller
web.xml
Multiply
Login
Logout
Add
Client’s Request
Controller
Login
Logout
Add
Multiply
6
Front Controller -
Responsibilities
 Initialize the framework to supply to the requests.
 Load the map of all the URLs and the components responsible to
handle the request.
 Prepare the map for the views.
7
What is Spring MVC Framework?
 Spring links objects together instead of the objects linking
themselves together.
 Spring object linking is defined in XML files, allowing easy changes
for different application configurations thus working as a plug in
architecture.
8
What is Spring MVC Framework?
 In an MVC architecture the controllers handle all requests.
 Spring uses a “DispatcherServlet” defined in the web.xml file to
analyze a request URL pattern and then pass control to the correct
controller by using a URL mapping defined in a “Spring bean” XML
file.
9
Spring 3 MVC- Basic Architecture
Dispatcher
Servlet
(Front
controller)
HandlerMapping
(Map of URL and controllers)
Controller
(Responsible to
handle request)
View (JSP,
XML,
Velocity)
Model
(POJO)
Request
1
5
4
3
2
10
Spring 3.0 MVC Request Flow
Dispatcher Servlet
Capture the Request
Locale
If request is
multipart- File upload
data is exposed
HandlerMapping
(Map of URL and controllers)
Handler
Chain
Interceptor -
Pre Process
Interceptor -
Pre Process
Controller
Interceptor -
Post Process
Interceptor -
Post Process
View
Resolver
Prepare
the View
Request
Response
11
Why Spring Framework?
 All frameworks integrate well with Spring.
 Consistent Configuration, open plug-in architecture.
 Integrates well with different O/R Mapping frameworks like
Hibernate.
 Easier to test applications with.
 Less complicated then other frameworks.
 Active user community.
 Spring is well organized and seems easier to learn comparatively
 Spring also supports JDBC Framework that makes it easier to
create JDBC Apps.
12
Features of Spring MVC
Framework
1. Inversion of Control (IoC) Container
2. Data Access Framework
3. Transaction Management
4. Spring Web Services
It is used to provide object
reference to class during
runtime.
It enables developers to easily write
code to access the persistant data
throughout the application.
It enables developers to model a
wide range of transaction by
providing Java Transaction API (JTA).
It provides powerful mapping for transmitting
incoming XML request to any object.
13
Advantage of Spring MVC
Framework
 Predefined Templates
 Loose Coupling
 Easy to test
 Lightweight
 Fast Development
 Declarative Support
 Hibernate and JDBC Support
 MVC Architecture and JavaBean Support
Example of web.xml file
<web-app>
<servlet>
<servlet-name>tradingapp</servlet-name>
<servlet-class>DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>tradingapp</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
*** Any URL ending with an “.html” pattern is routed to the
DispatcherServlet, the DispatcherServlet loads the tradingapp-servlet.xml
file and routes the user to the correct controller.
Without Dependency-Injection/IoC
Object A
Object B
Object C
creates
creates
An object creating its dependencies without IoC leads to tight object
coupling.
Object A
Object B
Object C
setB(IB)
setC(IC)
Object A contains setter methods that accept interfaces to objects B
and C. This could have also been achieved with constructors in
object A that accepts objects B and C.
With Dependency-Injection/IoC
 Allows objects to be created at higher levels and passed into object so they can
use the implementation directly
Overview of Spring
 Spring is a dependency injection framework to make java application loosely coupled.
 Spring framework makes the easy development of JavaEE application.
What is Spring?
 Dependency Injection (DI) is a design pattern used to implement IoC.
 It allows the creation of dependent objects outside of a class and provides
those objects to a class through different ways.
 Using DI, we move the creation and binding of the dependent objects outside
of the class that depends on them.
Dependency Injection
Overview of Spring
Client Service
Injector
Uses
Injects
 The Dependency Injection pattern involves 3 types of classes.
1) Client Class: The client class (dependent class) is a class which depends on the service
class
2) Service Class: The service class (dependency) is a class that provides service to the client
class.
3) Injector Class: The injector class injects the service class object into the client class.
19
Advantage of Spring MVC over
MVC
 Spring is a powerful Java application framework, used in a wide
range of Java applications.
 Spring provides a very clean division between controllers,
JavaBean models, and views.
 Spring’s MVC is very flexible.
 Spring MVC is entirely based on interfaces.
 Every part of the Spring MVC framework is configurable via
plugging in your own interface.
 No Action Forms, bind directly to domain objects.
 More testable code (validation has no dependency on Servlet
API).
 Spring offers better integration with view technologies other than
JSP (Velocity / XSLT / FreeMarker / XL etc.)
20
Important Intefaces
Interface Default bean name purpose
org.springframework.web.servlet.
HandlerMapping
handlerMapping Maps the Request to
Handlers(Controllers)
org.springframework.web.servlet.
HandlerAdapter
none Plugs the other frameworks
handlers
org.springframework.web.servlet.
ViewResolver
viewResolver Maps the view names to
view instances
org.springframework.web.servlet.
HandlerExceptionResolver
handlerExceptionResolv
er
Mapping of the exceptions to
handlers and views
org.springframework.web.
multipart.MultipartResolver
multipartResolver Interface to handle the file
uploads
org.springframework.web.servlet.
LocaleResolver
localeResolver Helps to resolve the locale
from the request
org.springframework.web.servlet.
ThemeResolver
themeResolver Resolves a theme for a
Request.
21
Java Bean vs Basic Java Class
 A Bean is a Java class, but a Java class does not have to be a bean.
 A Java Bean is a java class that should follow following
conventions:
1. It should have a no-arg constructor.
2. It should be Serializable.
3. It should provide methods to set and get the values of the properties,
known as getter and setter methods.
22
Why use Java Bean?
 It is a reusable software component.
 A bean encapsulates many objects into one object, so we can
access this object from multiple places.
 Moreover, it provides the easy maintenance.
23
Java Bean Architecture
Browser
JSP Pages
Java Bean
Enterprise
Information
System (EIS)
Servlet Container
1
Request
4
Response
2
3
24
Bean Life Cycle
 The life cycle of a Spring bean is easy to understand.
1. When a bean is instantiated, it may be required to perform
some initialization to get it into a usable state.
2. Similarly, when the bean is no longer required and is removed
from the container, some cleanup may be required.
Bean Life Cycle
1. public class HelloWorld {
2. private String message;
3. public void init(){
4. System.out.println("Bean is going through init.");}
5. public void setMessage(String message){
6. this.message = message; }
7. public void getMessage(){
8. System.out.println("Your Message : " + message);}
9. public void destroy(){
10. System.out.println("Bean will destroy now."); }}
26
Questions
1. Explain MVC Architecture
5. Explain MVC architecture in detail with figure.
6. Write a java bean named “student” having roll no and name having getter &
setter methods. Write a JSP page to set the roll number and name for a
student object and then print them by reading from object.
7. What is MVC architecture? Explain Spring architecture with neat
sketch.
8. What is Dependency Injection?
9. Briefly explain spring bean life cycle.
2. What are the differences between Java Bean and basic java class? Explain
Java Bean Architecture.
3. Differentiate : Java Bean and basic java class and Explain Java Bean
Architecture and Show the use of JSP inbuilt objects: request and response,
with their use in application
4. What is Spring Web MVC framework? List its key features.
Ad

More Related Content

Similar to Module 5.ppt............................. (20)

Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
ASG
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
Aneega
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts framework
s4al_com
 
Struts(mrsurwar) ppt
Struts(mrsurwar) pptStruts(mrsurwar) ppt
Struts(mrsurwar) ppt
mrsurwar
 
Struts & spring framework issues
Struts & spring framework issuesStruts & spring framework issues
Struts & spring framework issues
Prashant Seth
 
MVC
MVCMVC
MVC
akshin
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Pravin Pundge
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
Emprovise
 
Building Web Application Using Spring Framework
Building Web Application Using Spring FrameworkBuilding Web Application Using Spring Framework
Building Web Application Using Spring Framework
Edureka!
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Arjun Thakur
 
Month 2 report
Month 2 reportMonth 2 report
Month 2 report
PRIYANKA FNU
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
Tuna Tore
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
Tuna Tore
 
MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...
MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...
MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...
CrimsonpublishersPRSP
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworks
Mukesh Kumar
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
People Strategists
 
P20CSP105-AdvJavaProg.pptx
P20CSP105-AdvJavaProg.pptxP20CSP105-AdvJavaProg.pptx
P20CSP105-AdvJavaProg.pptx
DrTCVijayaraghavan
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
Hùng Nguyễn Huy
 
Spring mvc 2.0
Spring mvc 2.0Spring mvc 2.0
Spring mvc 2.0
Rudra Garnaik, PMI-ACP®
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
Surbhi Panhalkar
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
ASG
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
Aneega
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts framework
s4al_com
 
Struts(mrsurwar) ppt
Struts(mrsurwar) pptStruts(mrsurwar) ppt
Struts(mrsurwar) ppt
mrsurwar
 
Struts & spring framework issues
Struts & spring framework issuesStruts & spring framework issues
Struts & spring framework issues
Prashant Seth
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
Emprovise
 
Building Web Application Using Spring Framework
Building Web Application Using Spring FrameworkBuilding Web Application Using Spring Framework
Building Web Application Using Spring Framework
Edureka!
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Arjun Thakur
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
Tuna Tore
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
Tuna Tore
 
MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...
MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...
MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...
CrimsonpublishersPRSP
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworks
Mukesh Kumar
 

Recently uploaded (20)

YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
Ad

Module 5.ppt.............................

  • 2. 2 MVC – An overview Controller View Model Response
  • 3. 3 Advantage of MVC  Navigation control is centralized. Now only controller contains the logic to determine the next page.  Easy to maintain  Easy to extend  Easy to test  Better separation of concerns  Reusability
  • 6. 6 Front Controller - Responsibilities  Initialize the framework to supply to the requests.  Load the map of all the URLs and the components responsible to handle the request.  Prepare the map for the views.
  • 7. 7 What is Spring MVC Framework?  Spring links objects together instead of the objects linking themselves together.  Spring object linking is defined in XML files, allowing easy changes for different application configurations thus working as a plug in architecture.
  • 8. 8 What is Spring MVC Framework?  In an MVC architecture the controllers handle all requests.  Spring uses a “DispatcherServlet” defined in the web.xml file to analyze a request URL pattern and then pass control to the correct controller by using a URL mapping defined in a “Spring bean” XML file.
  • 9. 9 Spring 3 MVC- Basic Architecture Dispatcher Servlet (Front controller) HandlerMapping (Map of URL and controllers) Controller (Responsible to handle request) View (JSP, XML, Velocity) Model (POJO) Request 1 5 4 3 2
  • 10. 10 Spring 3.0 MVC Request Flow Dispatcher Servlet Capture the Request Locale If request is multipart- File upload data is exposed HandlerMapping (Map of URL and controllers) Handler Chain Interceptor - Pre Process Interceptor - Pre Process Controller Interceptor - Post Process Interceptor - Post Process View Resolver Prepare the View Request Response
  • 11. 11 Why Spring Framework?  All frameworks integrate well with Spring.  Consistent Configuration, open plug-in architecture.  Integrates well with different O/R Mapping frameworks like Hibernate.  Easier to test applications with.  Less complicated then other frameworks.  Active user community.  Spring is well organized and seems easier to learn comparatively  Spring also supports JDBC Framework that makes it easier to create JDBC Apps.
  • 12. 12 Features of Spring MVC Framework 1. Inversion of Control (IoC) Container 2. Data Access Framework 3. Transaction Management 4. Spring Web Services It is used to provide object reference to class during runtime. It enables developers to easily write code to access the persistant data throughout the application. It enables developers to model a wide range of transaction by providing Java Transaction API (JTA). It provides powerful mapping for transmitting incoming XML request to any object.
  • 13. 13 Advantage of Spring MVC Framework  Predefined Templates  Loose Coupling  Easy to test  Lightweight  Fast Development  Declarative Support  Hibernate and JDBC Support  MVC Architecture and JavaBean Support
  • 14. Example of web.xml file <web-app> <servlet> <servlet-name>tradingapp</servlet-name> <servlet-class>DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>tradingapp</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> </web-app> *** Any URL ending with an “.html” pattern is routed to the DispatcherServlet, the DispatcherServlet loads the tradingapp-servlet.xml file and routes the user to the correct controller.
  • 15. Without Dependency-Injection/IoC Object A Object B Object C creates creates An object creating its dependencies without IoC leads to tight object coupling.
  • 16. Object A Object B Object C setB(IB) setC(IC) Object A contains setter methods that accept interfaces to objects B and C. This could have also been achieved with constructors in object A that accepts objects B and C. With Dependency-Injection/IoC  Allows objects to be created at higher levels and passed into object so they can use the implementation directly
  • 17. Overview of Spring  Spring is a dependency injection framework to make java application loosely coupled.  Spring framework makes the easy development of JavaEE application. What is Spring?  Dependency Injection (DI) is a design pattern used to implement IoC.  It allows the creation of dependent objects outside of a class and provides those objects to a class through different ways.  Using DI, we move the creation and binding of the dependent objects outside of the class that depends on them. Dependency Injection
  • 18. Overview of Spring Client Service Injector Uses Injects  The Dependency Injection pattern involves 3 types of classes. 1) Client Class: The client class (dependent class) is a class which depends on the service class 2) Service Class: The service class (dependency) is a class that provides service to the client class. 3) Injector Class: The injector class injects the service class object into the client class.
  • 19. 19 Advantage of Spring MVC over MVC  Spring is a powerful Java application framework, used in a wide range of Java applications.  Spring provides a very clean division between controllers, JavaBean models, and views.  Spring’s MVC is very flexible.  Spring MVC is entirely based on interfaces.  Every part of the Spring MVC framework is configurable via plugging in your own interface.  No Action Forms, bind directly to domain objects.  More testable code (validation has no dependency on Servlet API).  Spring offers better integration with view technologies other than JSP (Velocity / XSLT / FreeMarker / XL etc.)
  • 20. 20 Important Intefaces Interface Default bean name purpose org.springframework.web.servlet. HandlerMapping handlerMapping Maps the Request to Handlers(Controllers) org.springframework.web.servlet. HandlerAdapter none Plugs the other frameworks handlers org.springframework.web.servlet. ViewResolver viewResolver Maps the view names to view instances org.springframework.web.servlet. HandlerExceptionResolver handlerExceptionResolv er Mapping of the exceptions to handlers and views org.springframework.web. multipart.MultipartResolver multipartResolver Interface to handle the file uploads org.springframework.web.servlet. LocaleResolver localeResolver Helps to resolve the locale from the request org.springframework.web.servlet. ThemeResolver themeResolver Resolves a theme for a Request.
  • 21. 21 Java Bean vs Basic Java Class  A Bean is a Java class, but a Java class does not have to be a bean.  A Java Bean is a java class that should follow following conventions: 1. It should have a no-arg constructor. 2. It should be Serializable. 3. It should provide methods to set and get the values of the properties, known as getter and setter methods.
  • 22. 22 Why use Java Bean?  It is a reusable software component.  A bean encapsulates many objects into one object, so we can access this object from multiple places.  Moreover, it provides the easy maintenance.
  • 23. 23 Java Bean Architecture Browser JSP Pages Java Bean Enterprise Information System (EIS) Servlet Container 1 Request 4 Response 2 3
  • 24. 24 Bean Life Cycle  The life cycle of a Spring bean is easy to understand. 1. When a bean is instantiated, it may be required to perform some initialization to get it into a usable state. 2. Similarly, when the bean is no longer required and is removed from the container, some cleanup may be required.
  • 25. Bean Life Cycle 1. public class HelloWorld { 2. private String message; 3. public void init(){ 4. System.out.println("Bean is going through init.");} 5. public void setMessage(String message){ 6. this.message = message; } 7. public void getMessage(){ 8. System.out.println("Your Message : " + message);} 9. public void destroy(){ 10. System.out.println("Bean will destroy now."); }}
  • 26. 26 Questions 1. Explain MVC Architecture 5. Explain MVC architecture in detail with figure. 6. Write a java bean named “student” having roll no and name having getter & setter methods. Write a JSP page to set the roll number and name for a student object and then print them by reading from object. 7. What is MVC architecture? Explain Spring architecture with neat sketch. 8. What is Dependency Injection? 9. Briefly explain spring bean life cycle. 2. What are the differences between Java Bean and basic java class? Explain Java Bean Architecture. 3. Differentiate : Java Bean and basic java class and Explain Java Bean Architecture and Show the use of JSP inbuilt objects: request and response, with their use in application 4. What is Spring Web MVC framework? List its key features.

Editor's Notes

  • #9: https://www.youtube.com/watch?v=EKobsnv9dsA
  • #15: https://www.youtube.com/watch?v=vFzP2SaMyA0
  • #16: https://www.youtube.com/watch?v=vLMaFRgZjM0