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.

More Related Content

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

PPT
Hybernat and structs, spring classes in mumbai
Vibrant Technologies & Computers
 
PDF
Toms introtospring mvc
Guo Albert
 
PPTX
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Arjun Thakur
 
PDF
Spring mvc
Guo Albert
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Spring Framework-II
People Strategists
 
PPTX
Spring framework-tutorial
vinayiqbusiness
 
PPTX
Spring (1)
Aneega
 
ODP
Spring Mvc,Java, Spring
ifnu bima
 
PPT
MVC
akshin
 
PDF
Spring Framework Tutorial | VirtualNuggets
Virtual Nuggets
 
PDF
Building Web Application Using Spring Framework
Edureka!
 
PDF
Spring mvc
Hamid Ghorbani
 
PPTX
Spring tutorials
TIB Academy
 
PDF
Spring Mvc
ifnu bima
 
PDF
quickguide-einnovator-7-spring-mvc
jorgesimao71
 
PPT
Learn spring at amc square learning
ASIT Education
 
PPT
Spring Framework
nomykk
 
PPTX
Skillwise-Spring framework 1
Skillwise Group
 
PPTX
Spring framework Introduction
Anuj Singh Rajput
 
Hybernat and structs, spring classes in mumbai
Vibrant Technologies & Computers
 
Toms introtospring mvc
Guo Albert
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Arjun Thakur
 
Spring mvc
Guo Albert
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Spring Framework-II
People Strategists
 
Spring framework-tutorial
vinayiqbusiness
 
Spring (1)
Aneega
 
Spring Mvc,Java, Spring
ifnu bima
 
MVC
akshin
 
Spring Framework Tutorial | VirtualNuggets
Virtual Nuggets
 
Building Web Application Using Spring Framework
Edureka!
 
Spring mvc
Hamid Ghorbani
 
Spring tutorials
TIB Academy
 
Spring Mvc
ifnu bima
 
quickguide-einnovator-7-spring-mvc
jorgesimao71
 
Learn spring at amc square learning
ASIT Education
 
Spring Framework
nomykk
 
Skillwise-Spring framework 1
Skillwise Group
 
Spring framework Introduction
Anuj Singh Rajput
 

Recently uploaded (20)

PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PPTX
Mathematics 5 - Time Measurement: Time Zone
menchreo
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
Mathematics 5 - Time Measurement: Time Zone
menchreo
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
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