SlideShare a Scribd company logo
1 of 50
Download to read offline
Spring MVC
Nov.2015
AirconChen
Why Spring MVC
• Spring MVC
• structs
• Spring
• Rest (Spring 3.x )
MVC
• Design Pattern
• Architecture Pattern
•
•
Model 1
• JSP JavaBean
JSP JSP HTML Java
Java
• EL JSTL
Scriptlet JSP
Java
Model1
JSP
• :
1. : JSP
2. : JSP
• :
3. :
4. : JSP
Model1
JSP+JavaBean
•
1. : JavaBean
2. : JavaBean
• :
1. : Model 1 MVC
Controller JSP
,
....
Model1
• Model 1
•
Model 2
Model :
View : ( JSP HTML)
Controller : ( Servlet )
Model 2
• :
1. :
2. : Controller JSP
3. :
Model JSP
• :
1. : MVC
2. : MVC
Model2
• Model 2
• SpringMVC Model 2
DispatcherServlet
HTTP
Response
1
2
3
4
56
7
Handler
ModalAndView
SpringMVC
Web.xml
DispatcherServlet
1. DispatcherServlet HTTP request
Spring MVC framework
2. Web layer Spring
Container(WebApplicationContext), BO
layer Spring Container(ApplicationContext)
Web layer bean BO layer bean ?
3. initial Spring MVC Component,
DispatcherServlet ?
1. DispatcherServlet HTTP request
Spring MVC framework
/WEB-INF/servlet-name-servlet.xml
Web layer Spring Container
Web layer Spring Container(WebApplicationContext),
BO layer Spring Container(ApplicationContext)
Web layer bean BO layer bean ?
Web Layer Spring Container
BO Layer Spring ContainerBO Layer Spring ContainerBO Layer Spring ContainerBO Layer Spring ContainerBO Layer Spring Container
Children Container
Parent Container
BO Layer can not call Web Layer
Web Layer can call BO Layer
DispatcherServlet
• namespace: ftc, Spring
WEB-INF/ftc.xml
• contextConfigLocation: Spring
”classpath:ftc1.xml, classpath:ftc2.xml“ initial
WebApplicationContext
• publishContext: boolean DispatcherServlet
WebApplicationContext ServletContext
ServletContext WebApplicationContext Instance
• publishEvents:boolean DispatcherServlet request
Container ServletRequestHandlerEvent, true,
DispatcherServlet
Annotation driven controller
• @RequestMapping
• @Controller
• @PathVariable
• @RequestParam
• @CookieValue
• @RequestHeader
User Request
@RequestMapping
• POJO @Controller
• <context:component-scan/> package
POJO HTTP request controller
• controller controller
method request
• request controller
@RequestMapping
• Controller
class @RequestMapping
@RequestMapping URL
DEMO
HTTP Request Method
HTTP
@RequestMapping
• value: request URL
• method: request Method
• params: request parameter
• headers: set request header conditions
request
• Request
• Cookie Request header
•
• HTTP Request
Request
Request
Cookie Request Header
HTTP Request
@RequestParam
• value:
• required:
• defaultValue:
required false
Servlet API
1.
2. HttpServletResponse void
Spring MVC
• ModalAndView: return ModelAndView( View
)
• @ModelAttribute: Annotation
• Map Model: return Map
• @SessionAttributes:
HttpSession
ModelAndView
@ModelAttribute
• Data model
Method @ModelAttribute
DEMO
Spring MVC Annotation,
@ModelAttribute @requestParam,
@CookieValue
Spring MVC
Map Model
DEMO
@SessionAttributes
• Spring MVC
HttpSession
• Spring MVC Model
• @ModelAttribute return add Model
• Session @SessionAttributes(“xxx”) xxx
xxx Model
• @ModelAttribute(“xxx”)
1. Model xxx
2. xxx session Class @SessionAttributes(“xxx”)
HttpSesionRequiredException
3. Model xxx session request
@SessionAttributes
@SessionAttributes
org.springframework.validation
LocalValidtorFactoryBean
• Spring Validator interface
• JSR 303 Validator interface
• Spring JSR 303 implement, import
Hibernate Validator jar
• <mvc:annotation-driven/>
LocalValidtorFactoryBean @Valid
JSR303
@Valid
Valid
Result
• BindingResult Spring
MVC Data model.
HTTP
Request
HTTP
Response
Spring MVC
DataModel
1 2
34
5
6
7
8
DEMO
• WebApplicationContext property
• message.properties
•
• message_zh_TW.properties
• message_zh_CN.properties
SpringMVC vs Struts
SpringMVC Struts
servlet filter
Method Class
Class
:java web framework competition
Web Framework
2012

More Related Content

What's hot

Ch. 13 filters and wrappers
Ch. 13 filters and wrappersCh. 13 filters and wrappers
Ch. 13 filters and wrappers
Manolis Vavalis
 
ASP .NET MVC
ASP .NET MVC ASP .NET MVC
ASP .NET MVC
eldorina
 

What's hot (20)

Exploring AngularJS - Liju Pillai
Exploring AngularJS - Liju PillaiExploring AngularJS - Liju Pillai
Exploring AngularJS - Liju Pillai
 
Web sockets in Angular
Web sockets in AngularWeb sockets in Angular
Web sockets in Angular
 
Spring MVC Architecture Tutorial
Spring MVC Architecture TutorialSpring MVC Architecture Tutorial
Spring MVC Architecture Tutorial
 
Rails concepts
Rails conceptsRails concepts
Rails concepts
 
Reacting to the Isomorphic Buzz
Reacting to the Isomorphic BuzzReacting to the Isomorphic Buzz
Reacting to the Isomorphic Buzz
 
Integration and Acceptance Testing
Integration and Acceptance TestingIntegration and Acceptance Testing
Integration and Acceptance Testing
 
Whats New In Spring 3.0 ?
Whats New In Spring 3.0 ?Whats New In Spring 3.0 ?
Whats New In Spring 3.0 ?
 
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.comWhen to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
 
4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
 
Ch. 13 filters and wrappers
Ch. 13 filters and wrappersCh. 13 filters and wrappers
Ch. 13 filters and wrappers
 
SpringMVC
SpringMVCSpringMVC
SpringMVC
 
深入淺出RoR
深入淺出RoR深入淺出RoR
深入淺出RoR
 
SPA using Rails & Backbone
SPA using Rails & BackboneSPA using Rails & Backbone
SPA using Rails & Backbone
 
Angular js
Angular jsAngular js
Angular js
 
ASP .NET MVC
ASP .NET MVC ASP .NET MVC
ASP .NET MVC
 
Introduction to Srping Web Flow
Introduction to Srping Web Flow Introduction to Srping Web Flow
Introduction to Srping Web Flow
 
Rest with grails 3
Rest with grails 3Rest with grails 3
Rest with grails 3
 
Puppet Camp London 2014: MCollective as an Integration Layer
Puppet Camp London 2014: MCollective as an Integration LayerPuppet Camp London 2014: MCollective as an Integration Layer
Puppet Camp London 2014: MCollective as an Integration Layer
 
ASP.Net 5 and C# 6
ASP.Net 5 and C# 6ASP.Net 5 and C# 6
ASP.Net 5 and C# 6
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...
 

Similar to SpringMVC

SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...
Liam Cleary [MVP]
 
Building dynamic applications with the share point client object model
Building dynamic applications with the share point client object modelBuilding dynamic applications with the share point client object model
Building dynamic applications with the share point client object model
Eric Shupps
 
ASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web developmentASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web development
Volodymyr Voytyshyn
 

Similar to SpringMVC (20)

SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...
 
Building dynamic applications with the share point client object model
Building dynamic applications with the share point client object modelBuilding dynamic applications with the share point client object model
Building dynamic applications with the share point client object model
 
Angular beans
Angular beansAngular beans
Angular beans
 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: Servlets
 
Java EE 8 Update
Java EE 8 UpdateJava EE 8 Update
Java EE 8 Update
 
Java EE 8 Web Frameworks: A Look at JSF vs MVC
Java EE 8 Web Frameworks: A Look at JSF vs MVCJava EE 8 Web Frameworks: A Look at JSF vs MVC
Java EE 8 Web Frameworks: A Look at JSF vs MVC
 
Testing Spring MVC and REST Web Applications
Testing Spring MVC and REST Web ApplicationsTesting Spring MVC and REST Web Applications
Testing Spring MVC and REST Web Applications
 
My04_MVC.pdf
My04_MVC.pdfMy04_MVC.pdf
My04_MVC.pdf
 
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
 
ASP.NET MVC overview
ASP.NET MVC overviewASP.NET MVC overview
ASP.NET MVC overview
 
IP UNIT III PPT.pptx
 IP UNIT III PPT.pptx IP UNIT III PPT.pptx
IP UNIT III PPT.pptx
 
Java Servlets.pdf
Java Servlets.pdfJava Servlets.pdf
Java Servlets.pdf
 
ASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web developmentASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web development
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Aspnet mvc
Aspnet mvcAspnet mvc
Aspnet mvc
 
Next stop: Spring 4
Next stop: Spring 4Next stop: Spring 4
Next stop: Spring 4
 
Servlets
ServletsServlets
Servlets
 
Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2
 
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
 

More from Aircon Chen (6)

App開發執行力release
App開發執行力releaseApp開發執行力release
App開發執行力release
 
Ionic
IonicIonic
Ionic
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
Rest
RestRest
Rest
 
Log
LogLog
Log
 
Spring framework
Spring frameworkSpring framework
Spring framework
 

Recently uploaded

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 

SpringMVC