SlideShare a Scribd company logo
1 of 24
copyright © I-Admin
Spring Framework 3.0 MVC
Prepared By:
Ravi Kant Soni
Sr. Software Engineer | ADS-Bangalore
session - 1
copyright © I-Admin
Objectives
 Introduce Spring MVC Module
 Learn about Spring MVC Components
(Dispatcher, Handler mapping, Controller,
View Resolver, View)
copyright © I-Admin
What Is Spring?
copyright © I-Admin
What is Spring?
 Spring is light weight, open source framework begins
developed by Spring Source Company
 Spring 1.0 was released in 2004
 Spring is available on www.springframework.org
 It provides support for JPA, Hibernate, Web services,
Schedulers, Ajax, Struts, JSF and many other
frameworks
copyright © I-Admin
Why use Spring?
 Spring was created to reduce the complexity
observed in Java enterprise application development
 Spring is organised into many modules that offer
various types of assistance to the developer in a host
of application areas
• Spring enables developers to develop enterprise-
class applications using POJOs
• Testing an application written with Spring is simple
because environment-dependent code is moved into
this framework
copyright © I-Admin
By the way, just what is MVC?
 Model-View-Controller or MVC is an architectural
pattern used in development of applications.
– Model encapsulates the raw data
– Controller responds to events, and instruct the model and view to
perform actions based on events
– View render information supplied by model in a form suitable for
user interaction.
copyright © I-Admin
MVC Architecture
copyright © I-Admin
Spring MVC Architecture
 Based on existing Servlet/JSP technology
copyright © I-Admin
Spring MVC Components
 DispatcherServlet responsible for intercepting the
request and dispatching for specific urls.
 Controller responsible for processing user requests
and building appropriate model and passes it to the
view for rendering
 View interface represents presentation logic and is
responsible for rendering content
 ModelAndView class objects encapsulates view and
model linking
 Model encapsulates the application data, will consist
of POJO
copyright © I-Admin
DispatcherServlet
 Used to handle all incoming requests and route them
through Spring
 Also responsible to initialize the frameworks
components which are used to process the request
at various stages
 Uses customizable logic to determine which
controllers should handle which requests
 Forwards all responses to through view handlers to
determine the correct views to route responses to
 DispatcherServlet Architecture uses the Front
Controller Design Pattern
copyright © I-Admin
DispatcherServlet Architecture
copyright © I-Admin
DispatcherServlet Mapping
 Request that are to be handled by DispatcherServlet
are to be mapped using a URL mapping in web.xml
config file.
 Each DispatcherServlet has its own
WebApplicationContext
copyright © I-Admin
DispatcherServlet in web.xml
 Dispatcher Servlet named "spring" that will intercept all urls to this web
application
 <servlet-mapping> tag indicates what URLs will be handled by the which
DispatcherServlet
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
copyright © I-Admin
Spring Configuration
 By default Spring looks for a servletname -servlet.xml file in /WEB-INF
 For the previous example we would need to create a file in /WEB-INF named
spring-servlet.xml
<beans xmlns …….>
<mvc:annotation-driven/>
<context:component-scan base-package="com.iadmin.spring" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
copyright © I-Admin
Spring Configuration cont..
 <mvc:annotation-driven /> tells Spring to support
annotations like @Controller, @RequestMapping
and others that simplify the writing and configuration
of controllers
 InternalResourceViewResolver resolve the view
names, looks for JSPs that match a given view
name in the director /WEB-INF/jsp
 <context:component-scan...> tell Spring where to
automatically detect controllers
copyright © I-Admin
The ‘C’ in MVC
 DispatcherServlet delegates the request to the
controllers to execute the functionality specific to it
 The @Controller annotation indicates that a
particular class serves the role of a controller
 Controller interpret user input and transform this
input into specific model which will be represented to
the user by the view
copyright © I-Admin
The ‘M’ in MVC
 Model is generally defined as a MAP that can
contain objects that are to be displayed in view
 ModelAndView object encapsulates the relations
between view and model and is returned by
corresponding Controller methods
 ModelAndView class use ModelMap that is custom
MAP implementation where values are added in key-
value fashion
copyright © I-Admin
The ‘V’ in MVC
 View Page can be explicitly returned as part of
ModelAndView object by the controller
 In case of mapping logical name of view can be
resolved to particular view page in case
ModelAndView doesn’t contain the view reference
 The view name can be independent of view
technology (without using .jsp in controller) and
resolved to specific technology by using
ViewResolver and render by View
copyright © I-Admin
Defining a Controller
 @Controller annotation defines the class as a
Spring MVC controller
 @RequestMapping annotation is used to map a
URL to either an entire class or a particular handler
method
 DispatcherServlet delegates the request to the
controllers to execute the functionality specific to it
copyright © I-Admin
Defining a Controller cont…
@Controllerpublic
class HelloController{
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC !");
return "hello";
}
}
 The value attribute indicates the URL to which the handler
method is mapped
 The method attribute defines the service method to handle
HTTP GET request
copyright © I-Admin
Creating JSP Views
 Spring MVC supports many types of views for different presentation
technologies. These include - JSPs, HTML, PDF, Excel worksheets, XML,
Velocity templates, XSLT, JSON, Atom and RSS feeds, JasperReports etc
 /WEB-INF/hello/hello.jsp:
<html>
<head>
<title>Hello Spring MVC</title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>
 Here, ${message} is the attribute which we have setup inside the Controller
copyright © I-Admin
Spring vs. Struts
 Struts Framework
– Based on MVC architecture
– View – JSPs, ActionForms
– Controller – ActionServlet, Actions
 Spring Framework
– DispatcherServlet - Spring’s Front Controller implementation
– View- JSP’s
– ViewResolver - Maps logical View names to actual View
implementations
– HandlerMapping-Strategy interface used by DispatcherServlet for
mapping incoming requests to individual Controllers
copyright © I-Admin
DEMO
copyright © I-Admin
Questions
Thank You
ravikant.soni@i-admin.com

More Related Content

What's hot

Spring Framework - MVC
Spring Framework - MVCSpring Framework - MVC
Spring Framework - MVCDzmitry Naskou
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot IntroductionJeevesh Pandey
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API07.pallav
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features OverviewSergii Stets
 
RxJS & Angular Reactive Forms @ Codemotion 2019
RxJS & Angular Reactive Forms @ Codemotion 2019RxJS & Angular Reactive Forms @ Codemotion 2019
RxJS & Angular Reactive Forms @ Codemotion 2019Fabio Biondi
 
Angular and The Case for RxJS
Angular and The Case for RxJSAngular and The Case for RxJS
Angular and The Case for RxJSSandi Barr
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!Jakub Kubrynski
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8Knoldus Inc.
 
Introduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionIntroduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionRichard Paul
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsNewCircle Training
 

What's hot (20)

Java Spring
Java SpringJava Spring
Java Spring
 
Spring Framework - MVC
Spring Framework - MVCSpring Framework - MVC
Spring Framework - MVC
 
Spring jdbc
Spring jdbcSpring jdbc
Spring jdbc
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features Overview
 
RxJS & Angular Reactive Forms @ Codemotion 2019
RxJS & Angular Reactive Forms @ Codemotion 2019RxJS & Angular Reactive Forms @ Codemotion 2019
RxJS & Angular Reactive Forms @ Codemotion 2019
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Angular and The Case for RxJS
Angular and The Case for RxJSAngular and The Case for RxJS
Angular and The Case for RxJS
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8
 
Java persistence api 2.1
Java persistence api 2.1Java persistence api 2.1
Java persistence api 2.1
 
Introduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionIntroduction to Spring's Dependency Injection
Introduction to Spring's Dependency Injection
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 

Viewers also liked

Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC frameworkMohit Gupta
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVCRichard Paul
 
Presentation Spring, Spring MVC
Presentation Spring, Spring MVCPresentation Spring, Spring MVC
Presentation Spring, Spring MVCNathaniel Richand
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkDineesha Suraweera
 
Spring MVC Architecture Tutorial
Spring MVC Architecture TutorialSpring MVC Architecture Tutorial
Spring MVC Architecture TutorialJava Success Point
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCAnton Krasnoshchok
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVCGuy Nir
 
Spring MVC - The Basics
Spring MVC -  The BasicsSpring MVC -  The Basics
Spring MVC - The BasicsIlio Catallo
 
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 HTML5Tuna Tore
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 
Zed ria presentation
Zed ria presentationZed ria presentation
Zed ria presentationsujiswetha65
 
Диплом Пакалина Ю.
Диплом Пакалина Ю.Диплом Пакалина Ю.
Диплом Пакалина Ю.Socreklamanalytics
 
портфоліо на мк 2013 [автосохраненный] готовий
портфоліо  на мк 2013 [автосохраненный] готовийпортфоліо  на мк 2013 [автосохраненный] готовий
портфоліо на мк 2013 [автосохраненный] готовийles1812
 
Pragati a4 brouchre - wide
Pragati   a4 brouchre - widePragati   a4 brouchre - wide
Pragati a4 brouchre - widesujiswetha65
 

Viewers also liked (20)

Spring MVC Basics
Spring MVC BasicsSpring MVC Basics
Spring MVC Basics
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVC
 
Presentation Spring, Spring MVC
Presentation Spring, Spring MVCPresentation Spring, Spring MVC
Presentation Spring, Spring MVC
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Support de cours Spring M.youssfi
Support de cours Spring  M.youssfiSupport de cours Spring  M.youssfi
Support de cours Spring M.youssfi
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring MVC Architecture Tutorial
Spring MVC Architecture TutorialSpring MVC Architecture Tutorial
Spring MVC Architecture Tutorial
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVC
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVC
 
Spring MVC - The Basics
Spring MVC -  The BasicsSpring MVC -  The Basics
Spring MVC - The Basics
 
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
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Presentation Spring
Presentation SpringPresentation Spring
Presentation Spring
 
Диплом Ярош А.
Диплом Ярош А.Диплом Ярош А.
Диплом Ярош А.
 
Matilla Portfolio
Matilla PortfolioMatilla Portfolio
Matilla Portfolio
 
Zed ria presentation
Zed ria presentationZed ria presentation
Zed ria presentation
 
Диплом Пакалина Ю.
Диплом Пакалина Ю.Диплом Пакалина Ю.
Диплом Пакалина Ю.
 
портфоліо на мк 2013 [автосохраненный] готовий
портфоліо  на мк 2013 [автосохраненный] готовийпортфоліо  на мк 2013 [автосохраненный] готовий
портфоліо на мк 2013 [автосохраненный] готовий
 
Pragati a4 brouchre - wide
Pragati   a4 brouchre - widePragati   a4 brouchre - wide
Pragati a4 brouchre - wide
 

Similar to Spring MVC 3.0 Framework

Similar to Spring MVC 3.0 Framework (20)

quickguide-einnovator-7-spring-mvc
quickguide-einnovator-7-spring-mvcquickguide-einnovator-7-spring-mvc
quickguide-einnovator-7-spring-mvc
 
Spring MVC framework features and concepts
Spring MVC framework features and conceptsSpring MVC framework features and concepts
Spring MVC framework features and concepts
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Jinal desai .net
Jinal desai .netJinal desai .net
Jinal desai .net
 
Dispatcher
DispatcherDispatcher
Dispatcher
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
Spring MVC introduction HVA
Spring MVC introduction HVASpring MVC introduction HVA
Spring MVC introduction HVA
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVC
 
Spring mvc 2.0
Spring mvc 2.0Spring mvc 2.0
Spring mvc 2.0
 
MVC
MVCMVC
MVC
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
 
MVC 4
MVC 4MVC 4
MVC 4
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Struts(mrsurwar) ppt
Struts(mrsurwar) pptStruts(mrsurwar) ppt
Struts(mrsurwar) ppt
 
AngularJS = Browser applications on steroids
AngularJS = Browser applications on steroidsAngularJS = Browser applications on steroids
AngularJS = Browser applications on steroids
 
Month 2 report
Month 2 reportMonth 2 report
Month 2 report
 

Recently uploaded

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 

Recently uploaded (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 

Spring MVC 3.0 Framework

  • 1. copyright © I-Admin Spring Framework 3.0 MVC Prepared By: Ravi Kant Soni Sr. Software Engineer | ADS-Bangalore session - 1
  • 2. copyright © I-Admin Objectives  Introduce Spring MVC Module  Learn about Spring MVC Components (Dispatcher, Handler mapping, Controller, View Resolver, View)
  • 4. copyright © I-Admin What is Spring?  Spring is light weight, open source framework begins developed by Spring Source Company  Spring 1.0 was released in 2004  Spring is available on www.springframework.org  It provides support for JPA, Hibernate, Web services, Schedulers, Ajax, Struts, JSF and many other frameworks
  • 5. copyright © I-Admin Why use Spring?  Spring was created to reduce the complexity observed in Java enterprise application development  Spring is organised into many modules that offer various types of assistance to the developer in a host of application areas • Spring enables developers to develop enterprise- class applications using POJOs • Testing an application written with Spring is simple because environment-dependent code is moved into this framework
  • 6. copyright © I-Admin By the way, just what is MVC?  Model-View-Controller or MVC is an architectural pattern used in development of applications. – Model encapsulates the raw data – Controller responds to events, and instruct the model and view to perform actions based on events – View render information supplied by model in a form suitable for user interaction.
  • 8. copyright © I-Admin Spring MVC Architecture  Based on existing Servlet/JSP technology
  • 9. copyright © I-Admin Spring MVC Components  DispatcherServlet responsible for intercepting the request and dispatching for specific urls.  Controller responsible for processing user requests and building appropriate model and passes it to the view for rendering  View interface represents presentation logic and is responsible for rendering content  ModelAndView class objects encapsulates view and model linking  Model encapsulates the application data, will consist of POJO
  • 10. copyright © I-Admin DispatcherServlet  Used to handle all incoming requests and route them through Spring  Also responsible to initialize the frameworks components which are used to process the request at various stages  Uses customizable logic to determine which controllers should handle which requests  Forwards all responses to through view handlers to determine the correct views to route responses to  DispatcherServlet Architecture uses the Front Controller Design Pattern
  • 12. copyright © I-Admin DispatcherServlet Mapping  Request that are to be handled by DispatcherServlet are to be mapped using a URL mapping in web.xml config file.  Each DispatcherServlet has its own WebApplicationContext
  • 13. copyright © I-Admin DispatcherServlet in web.xml  Dispatcher Servlet named "spring" that will intercept all urls to this web application  <servlet-mapping> tag indicates what URLs will be handled by the which DispatcherServlet <servlet> <servlet-name>spring</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
  • 14. copyright © I-Admin Spring Configuration  By default Spring looks for a servletname -servlet.xml file in /WEB-INF  For the previous example we would need to create a file in /WEB-INF named spring-servlet.xml <beans xmlns …….> <mvc:annotation-driven/> <context:component-scan base-package="com.iadmin.spring" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> </beans>
  • 15. copyright © I-Admin Spring Configuration cont..  <mvc:annotation-driven /> tells Spring to support annotations like @Controller, @RequestMapping and others that simplify the writing and configuration of controllers  InternalResourceViewResolver resolve the view names, looks for JSPs that match a given view name in the director /WEB-INF/jsp  <context:component-scan...> tell Spring where to automatically detect controllers
  • 16. copyright © I-Admin The ‘C’ in MVC  DispatcherServlet delegates the request to the controllers to execute the functionality specific to it  The @Controller annotation indicates that a particular class serves the role of a controller  Controller interpret user input and transform this input into specific model which will be represented to the user by the view
  • 17. copyright © I-Admin The ‘M’ in MVC  Model is generally defined as a MAP that can contain objects that are to be displayed in view  ModelAndView object encapsulates the relations between view and model and is returned by corresponding Controller methods  ModelAndView class use ModelMap that is custom MAP implementation where values are added in key- value fashion
  • 18. copyright © I-Admin The ‘V’ in MVC  View Page can be explicitly returned as part of ModelAndView object by the controller  In case of mapping logical name of view can be resolved to particular view page in case ModelAndView doesn’t contain the view reference  The view name can be independent of view technology (without using .jsp in controller) and resolved to specific technology by using ViewResolver and render by View
  • 19. copyright © I-Admin Defining a Controller  @Controller annotation defines the class as a Spring MVC controller  @RequestMapping annotation is used to map a URL to either an entire class or a particular handler method  DispatcherServlet delegates the request to the controllers to execute the functionality specific to it
  • 20. copyright © I-Admin Defining a Controller cont… @Controllerpublic class HelloController{ @RequestMapping(value = "/hello", method = RequestMethod.GET) public String printHello(ModelMap model) { model.addAttribute("message", "Hello Spring MVC !"); return "hello"; } }  The value attribute indicates the URL to which the handler method is mapped  The method attribute defines the service method to handle HTTP GET request
  • 21. copyright © I-Admin Creating JSP Views  Spring MVC supports many types of views for different presentation technologies. These include - JSPs, HTML, PDF, Excel worksheets, XML, Velocity templates, XSLT, JSON, Atom and RSS feeds, JasperReports etc  /WEB-INF/hello/hello.jsp: <html> <head> <title>Hello Spring MVC</title> </head> <body> <h2>${message}</h2> </body> </html>  Here, ${message} is the attribute which we have setup inside the Controller
  • 22. copyright © I-Admin Spring vs. Struts  Struts Framework – Based on MVC architecture – View – JSPs, ActionForms – Controller – ActionServlet, Actions  Spring Framework – DispatcherServlet - Spring’s Front Controller implementation – View- JSP’s – ViewResolver - Maps logical View names to actual View implementations – HandlerMapping-Strategy interface used by DispatcherServlet for mapping incoming requests to individual Controllers
  • 24. copyright © I-Admin Questions Thank You ravikant.soni@i-admin.com