SlideShare a Scribd company logo
SPRING MVC
The spring web MVC provides model-view-controller
architecture
By Nagaraju
 The Model encapsulates the application data and in general they will consist of
POJO.
 The View is responsible for rendering the model data and in general it generates
HTML output that the client's browser can interpret.
 The Controller is responsible for processing user requests and building appropriate
model and passes it to the view for rendering.
The Spring web model-view-controller(MVC) is designed around a DispatcherServlet
that handles all the http request and responses. . The request processing workflow of the
Spring Web MVC DispatcherServlet is illustrated in the following diagram:
Following is the sequence of events corresponding to an incoming HTTP request to
DispatcherServlet.
 After receiving an HTTP request, DispatcherServlet consults the HandlerMapping to call the
appropriate Controller.
 The Controller takes the request and calls the appropriate service methods based on used GET
or POST method. The service method will set model data based on defined business logic and
returns view name to the DispatcherServlet.
 The DispatcherServlet will take help from ViewResolver to pickup the defined view for the
request.
 Once view is finalized, The DispatcherServlet passes the model data to the view which is
finally rendered on the browser.
Required Configuration:
You need to map requests that you want the DispatcherServlet to handle, by using a URL mapping
in the web.xml.
<servlet>
<servlet-name>ServletName</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping><servlet-name>ServletName</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
 Upon initialization of ServletName DispatcherServlet, the framework will try to load the
applicationcontext from a file named [servlet-name]-servlet.xml located in the application's
WebContent/WEB-INF directory.
 We can customize this file name and location by adding the servletlistenerContextLoaderListener in
your web.xml file as follows.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/HelloWeb-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
 Required configuration for [servletname]-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package=“packagename" />
<bean ><property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
Following are the important points about HelloWeb-servlet.xmlfile:
 The [servlet-name]-servlet.xml file will be used to create the beans defined, overriding the definitions of any beans
defined with the same name in the global scope.
 The <context:component-scan...> tag will be use to activate Spring MVC annotationscanning capability which allows to
make use of annotations like @Controller and @RequestMapping etc.
Defining a controller:
@Controller annotation indicates that a particular class serves the role of a controller.
@RequestMapping annotation is used to map a URL to either an entire class or a particular handler method.
Ex:
@Controller
@RequestMapping("/hello")
public class HelloController{
@RequestMapping(method = RequestMethod.GET)
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello";
}
}
SPRING SECURITY
 We can do authentication and authorization for the some specific urls by using spring security.
Only selected people can use the urls.
 We will mention the url in the spirng-security.xml to which authentication is to be done and the
username and password.
 Create the Spring-Security.xml file and mention the url to which authentication is to be done in
the intercept-url tag like this as shown in below
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-
security-3.2.xsd">
<http auto-config="true">
<intercept-url pattern="/Url" access="ROLE_USER" /> </http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name=“userName" password=“Password" authorities="ROLE_USER" />
</user-service> </authentication-provider> </authentication-manager>
</beans:beans>
 Integrate Spring Security
To integrate Spring security with a Spring MVC web application, just
declares DelegatingFilterProxy as a servlet filter to intercept any Incoming request.
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
We have to include the these tag in the Web.xml
We can redirect the page based on the authentication status.
We can include our custom login page.
<form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/login?error"
username-parameter="username" 3
password-parameter="password" />
<logout logout-success-url="/login?logout" />
Based on the authentication we can redirect to specific page.
Ad

More Related Content

What's hot (20)

springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
Tuna Tore
 
Spring MVC Basics
Spring MVC BasicsSpring MVC Basics
Spring MVC Basics
Bozhidar Bozhanov
 
Jsf intro
Jsf introJsf intro
Jsf intro
vantinhkhuc
 
Jsf2.0 -4
Jsf2.0 -4Jsf2.0 -4
Jsf2.0 -4
Vinay Kumar
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Guo Albert
 
Java server faces
Java server facesJava server faces
Java server faces
Fábio Santos
 
Introduction to jsf 2
Introduction to jsf 2Introduction to jsf 2
Introduction to jsf 2
yousry ibrahim
 
Spring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsSpring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topics
Guy Nir
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2
Jim Driscoll
 
MVC
MVCMVC
MVC
akshin
 
JSF basics
JSF basicsJSF basics
JSF basics
airbo
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
Surbhi Panhalkar
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
BG Java EE Course
 
Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Course
guest764934
 
Spring MVC 3.0 Framework (sesson_2)
Spring MVC 3.0 Framework (sesson_2)Spring MVC 3.0 Framework (sesson_2)
Spring MVC 3.0 Framework (sesson_2)
Ravi Kant Soni ([email protected])
 
Struts course material
Struts course materialStruts course material
Struts course material
Vibrant Technologies & Computers
 
JSF Component Behaviors
JSF Component BehaviorsJSF Component Behaviors
JSF Component Behaviors
Andy Schwartz
 
Jsp with mvc
Jsp with mvcJsp with mvc
Jsp with mvc
vamsitricks
 
Java server faces
Java server facesJava server faces
Java server faces
owli93
 

Viewers also liked (13)

Reactive Streams and RxJava2
Reactive Streams and RxJava2Reactive Streams and RxJava2
Reactive Streams and RxJava2
Yakov Fain
 
Live chym kysubrse vs toidicodedao
Live chym kysubrse vs toidicodedaoLive chym kysubrse vs toidicodedao
Live chym kysubrse vs toidicodedao
Huy Hoàng Phạm
 
Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2
Fabio Collini
 
Từ Gà Đến Pro Git và GitHub trong 60 phút
Từ Gà Đến Pro Git và GitHub trong 60 phútTừ Gà Đến Pro Git và GitHub trong 60 phút
Từ Gà Đến Pro Git và GitHub trong 60 phút
Huy Hoàng Phạm
 
Lap trinh java hieu qua
Lap trinh java hieu quaLap trinh java hieu qua
Lap trinh java hieu qua
Lê Anh
 
Sinh viên IT học và làm gì để không thất nghiệp
Sinh viên IT học và làm gì để không thất nghiệpSinh viên IT học và làm gì để không thất nghiệp
Sinh viên IT học và làm gì để không thất nghiệp
Huy Hoàng Phạm
 
Luận văn tìm hiểu Spring
Luận văn tìm hiểu SpringLuận văn tìm hiểu Spring
Luận văn tìm hiểu Spring
An Nguyen
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Ba Big
 
Hành trình trở thành web đì ve lốp pơ
Hành trình trở thành web đì ve lốp pơHành trình trở thành web đì ve lốp pơ
Hành trình trở thành web đì ve lốp pơ
Huy Hoàng Phạm
 
Từ Sinh Viên IT tới Lập Trình Viên
Từ Sinh Viên IT tới Lập Trình ViênTừ Sinh Viên IT tới Lập Trình Viên
Từ Sinh Viên IT tới Lập Trình Viên
Huy Hoàng Phạm
 
Effective java
Effective javaEffective java
Effective java
Haeil Yi
 
Effective Java
Effective JavaEffective Java
Effective Java
Brice Argenson
 
Effective java
Effective javaEffective java
Effective java
Emprovise
 
Reactive Streams and RxJava2
Reactive Streams and RxJava2Reactive Streams and RxJava2
Reactive Streams and RxJava2
Yakov Fain
 
Live chym kysubrse vs toidicodedao
Live chym kysubrse vs toidicodedaoLive chym kysubrse vs toidicodedao
Live chym kysubrse vs toidicodedao
Huy Hoàng Phạm
 
Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2
Fabio Collini
 
Từ Gà Đến Pro Git và GitHub trong 60 phút
Từ Gà Đến Pro Git và GitHub trong 60 phútTừ Gà Đến Pro Git và GitHub trong 60 phút
Từ Gà Đến Pro Git và GitHub trong 60 phút
Huy Hoàng Phạm
 
Lap trinh java hieu qua
Lap trinh java hieu quaLap trinh java hieu qua
Lap trinh java hieu qua
Lê Anh
 
Sinh viên IT học và làm gì để không thất nghiệp
Sinh viên IT học và làm gì để không thất nghiệpSinh viên IT học và làm gì để không thất nghiệp
Sinh viên IT học và làm gì để không thất nghiệp
Huy Hoàng Phạm
 
Luận văn tìm hiểu Spring
Luận văn tìm hiểu SpringLuận văn tìm hiểu Spring
Luận văn tìm hiểu Spring
An Nguyen
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Ba Big
 
Hành trình trở thành web đì ve lốp pơ
Hành trình trở thành web đì ve lốp pơHành trình trở thành web đì ve lốp pơ
Hành trình trở thành web đì ve lốp pơ
Huy Hoàng Phạm
 
Từ Sinh Viên IT tới Lập Trình Viên
Từ Sinh Viên IT tới Lập Trình ViênTừ Sinh Viên IT tới Lập Trình Viên
Từ Sinh Viên IT tới Lập Trình Viên
Huy Hoàng Phạm
 
Effective java
Effective javaEffective java
Effective java
Haeil Yi
 
Effective java
Effective javaEffective java
Effective java
Emprovise
 
Ad

Similar to Spring mvc (20)

Spring MVC
Spring MVCSpring MVC
Spring MVC
Emprovise
 
quickguide-einnovator-7-spring-mvc
quickguide-einnovator-7-spring-mvcquickguide-einnovator-7-spring-mvc
quickguide-einnovator-7-spring-mvc
jorgesimao71
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Harshit Choudhary
 
Spring MVC 3.0 Framework
Spring MVC 3.0 FrameworkSpring MVC 3.0 Framework
Spring MVC 3.0 Framework
Ravi Kant Soni ([email protected])
 
Jinal desai .net
Jinal desai .netJinal desai .net
Jinal desai .net
rohitkumar1987in
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
Hùng Nguyễn Huy
 
Simple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnanSimple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnan
Gigin Krishnan
 
Spring tutorial
Spring tutorialSpring tutorial
Spring tutorial
Sanjoy Kumer Deb
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
Tomi Juhola
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
Volkan Uzun
 
Mvc interview questions – deep dive jinal desai
Mvc interview questions – deep dive   jinal desaiMvc interview questions – deep dive   jinal desai
Mvc interview questions – deep dive jinal desai
jinaldesailive
 
Oip presentation
Oip presentationOip presentation
Oip presentation
Harsha Halgaswatta
 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3
Ilio Catallo
 
Spring mvc 2.0
Spring mvc 2.0Spring mvc 2.0
Spring mvc 2.0
Rudra Garnaik, PMI-ACP®
 
springwebmvc-1234567891236547894463621.pdf
springwebmvc-1234567891236547894463621.pdfspringwebmvc-1234567891236547894463621.pdf
springwebmvc-1234567891236547894463621.pdf
Patiento Del Mar
 
Unit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptxUnit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptx
AbhijayKulshrestha1
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
erdemergin
 
Dispatcher
DispatcherDispatcher
Dispatcher
RAHUL VUTUKURI
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
zeeshanhanif
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
People Strategists
 
Ad

More from nagarajupatangay (8)

Exception handling in mule
Exception handling in muleException handling in mule
Exception handling in mule
nagarajupatangay
 
Mule
MuleMule
Mule
nagarajupatangay
 
Java script object notation(json)
Java script object notation(json)Java script object notation(json)
Java script object notation(json)
nagarajupatangay
 
Rest
RestRest
Rest
nagarajupatangay
 
Soap
SoapSoap
Soap
nagarajupatangay
 
Web service
Web serviceWeb service
Web service
nagarajupatangay
 
Oss
OssOss
Oss
nagarajupatangay
 
Billing and Revenue Management
Billing and Revenue ManagementBilling and Revenue Management
Billing and Revenue Management
nagarajupatangay
 

Recently uploaded (20)

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
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
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.
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
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
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
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
 
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
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
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 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
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
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
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
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
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
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
 
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
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
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 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
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 

Spring mvc

  • 1. SPRING MVC The spring web MVC provides model-view-controller architecture By Nagaraju
  • 2.  The Model encapsulates the application data and in general they will consist of POJO.  The View is responsible for rendering the model data and in general it generates HTML output that the client's browser can interpret.  The Controller is responsible for processing user requests and building appropriate model and passes it to the view for rendering. The Spring web model-view-controller(MVC) is designed around a DispatcherServlet that handles all the http request and responses. . The request processing workflow of the Spring Web MVC DispatcherServlet is illustrated in the following diagram:
  • 3. Following is the sequence of events corresponding to an incoming HTTP request to DispatcherServlet.  After receiving an HTTP request, DispatcherServlet consults the HandlerMapping to call the appropriate Controller.  The Controller takes the request and calls the appropriate service methods based on used GET or POST method. The service method will set model data based on defined business logic and returns view name to the DispatcherServlet.  The DispatcherServlet will take help from ViewResolver to pickup the defined view for the request.  Once view is finalized, The DispatcherServlet passes the model data to the view which is finally rendered on the browser. Required Configuration: You need to map requests that you want the DispatcherServlet to handle, by using a URL mapping in the web.xml. <servlet> <servlet-name>ServletName</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping><servlet-name>ServletName</servlet-name> <url-pattern>*.jsp</url-pattern> </servlet-mapping>
  • 4.  Upon initialization of ServletName DispatcherServlet, the framework will try to load the applicationcontext from a file named [servlet-name]-servlet.xml located in the application's WebContent/WEB-INF directory.  We can customize this file name and location by adding the servletlistenerContextLoaderListener in your web.xml file as follows. <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/HelloWeb-servlet.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>  Required configuration for [servletname]-servlet.xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package=“packagename" />
  • 5. <bean ><property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> </beans> Following are the important points about HelloWeb-servlet.xmlfile:  The [servlet-name]-servlet.xml file will be used to create the beans defined, overriding the definitions of any beans defined with the same name in the global scope.  The <context:component-scan...> tag will be use to activate Spring MVC annotationscanning capability which allows to make use of annotations like @Controller and @RequestMapping etc. Defining a controller: @Controller annotation indicates that a particular class serves the role of a controller. @RequestMapping annotation is used to map a URL to either an entire class or a particular handler method. Ex: @Controller @RequestMapping("/hello") public class HelloController{ @RequestMapping(method = RequestMethod.GET) public String printHello(ModelMap model) { model.addAttribute("message", "Hello Spring MVC Framework!"); return "hello"; } }
  • 6. SPRING SECURITY  We can do authentication and authorization for the some specific urls by using spring security. Only selected people can use the urls.  We will mention the url in the spirng-security.xml to which authentication is to be done and the username and password.  Create the Spring-Security.xml file and mention the url to which authentication is to be done in the intercept-url tag like this as shown in below <beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring- security-3.2.xsd"> <http auto-config="true"> <intercept-url pattern="/Url" access="ROLE_USER" /> </http> <authentication-manager> <authentication-provider> <user-service> <user name=“userName" password=“Password" authorities="ROLE_USER" /> </user-service> </authentication-provider> </authentication-manager> </beans:beans>
  • 7.  Integrate Spring Security To integrate Spring security with a Spring MVC web application, just declares DelegatingFilterProxy as a servlet filter to intercept any Incoming request. <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> We have to include the these tag in the Web.xml We can redirect the page based on the authentication status. We can include our custom login page. <form-login login-page="/login" default-target-url="/welcome" authentication-failure-url="/login?error" username-parameter="username" 3 password-parameter="password" /> <logout logout-success-url="/login?logout" /> Based on the authentication we can redirect to specific page.