SlideShare a Scribd company logo
1 of 11
SESSION – 7
By→ Anuj Kumar Singh
RequestDispatcher in Servlet
The RequestDispatcher interface provides the facility of dispatching the request
to another resource it may be html, servlet or jsp. This interface can also be
used to include the content of another resource also. It is one of the way of
servlet collaboration.
Methods of RequestDispatcher interface
1. public void forward(ServletRequest request,ServletResponse
response)throws ServletException,IOException:Forwards a request from a
servlet to another resource (servlet, JSP file, or HTML file) on the server.
2. public void include(ServletRequest request,ServletResponse
response)throws ServletException,java.io.IOException:Includes the content
of a resource (servlet, JSP page, or HTML file) in the response.
How to get the object of RequestDispatcher
The getRequestDispatcher() method of ServletRequest interface
returns the object of RequestDispatcher.
Syntax of getRequestDispatcher method
public RequestDispatcher getRequestDispatcher(String resource);
Example of using getRequestDispatcher method
RequestDispatcher rd=request.getRequestDispatcher("servlet2");
//servlet2 is the url-pattern of the second servlet
rd.forward(request, response);//method may be include or forward
Example of RequestDispatcher interface
1. We are validating the password entered by the user. If password is
servlet, it will forward the request to the WelcomeServlet, otherwise
will show an error message.
2. In this example, we have created following files:
a. index.html file: for getting input from the user.
b. Login.java file: a servlet class for processing the response. If
password is servlet, it will forward the request to the welcome servlet.
c. WelcomeServlet.java file: a servlet class for displaying the welcome
message.
d. web.xml file: a deployment descriptor file that contains the
information about the servlet.
index.html
NewServlet.java (for validation)
NewServlet1.java (If password matched then Welcome)
Output 1
Output 2
Servlet   session 7

More Related Content

What's hot

Servlet api & servlet http package
Servlet api & servlet http packageServlet api & servlet http package
Servlet api & servlet http packagerenukarenuka9
 
Jakarta EE : The First Parts
Jakarta EE : The First PartsJakarta EE : The First Parts
Jakarta EE : The First PartsKenji HASUNUMA
 
SCWCD 1. get post - url (cap1 - cap2 )
SCWCD 1. get   post - url (cap1 - cap2 )SCWCD 1. get   post - url (cap1 - cap2 )
SCWCD 1. get post - url (cap1 - cap2 )Francesco Ierna
 
Why you shouldn’t edit silver stripe core files (and how to do it anyway)
Why you shouldn’t edit silver stripe core files (and how to do it anyway)Why you shouldn’t edit silver stripe core files (and how to do it anyway)
Why you shouldn’t edit silver stripe core files (and how to do it anyway)Loz Calver
 
Box connector Mule ESB Integration
Box connector Mule ESB IntegrationBox connector Mule ESB Integration
Box connector Mule ESB IntegrationAnilKumar Etagowni
 
Android networking in Hindi
Android networking in Hindi Android networking in Hindi
Android networking in Hindi Vipin sharma
 
Mule security - spring security manager
Mule  security - spring security managerMule  security - spring security manager
Mule security - spring security managerD.Rajesh Kumar
 

What's hot (9)

Servlet api & servlet http package
Servlet api & servlet http packageServlet api & servlet http package
Servlet api & servlet http package
 
Jakarta EE : The First Parts
Jakarta EE : The First PartsJakarta EE : The First Parts
Jakarta EE : The First Parts
 
Servlets
ServletsServlets
Servlets
 
SCWCD 1. get post - url (cap1 - cap2 )
SCWCD 1. get   post - url (cap1 - cap2 )SCWCD 1. get   post - url (cap1 - cap2 )
SCWCD 1. get post - url (cap1 - cap2 )
 
Sse
SseSse
Sse
 
Why you shouldn’t edit silver stripe core files (and how to do it anyway)
Why you shouldn’t edit silver stripe core files (and how to do it anyway)Why you shouldn’t edit silver stripe core files (and how to do it anyway)
Why you shouldn’t edit silver stripe core files (and how to do it anyway)
 
Box connector Mule ESB Integration
Box connector Mule ESB IntegrationBox connector Mule ESB Integration
Box connector Mule ESB Integration
 
Android networking in Hindi
Android networking in Hindi Android networking in Hindi
Android networking in Hindi
 
Mule security - spring security manager
Mule  security - spring security managerMule  security - spring security manager
Mule security - spring security manager
 

Similar to Servlet session 7

Similar to Servlet session 7 (20)

Enterprise java unit-2_chapter-1
Enterprise  java unit-2_chapter-1Enterprise  java unit-2_chapter-1
Enterprise java unit-2_chapter-1
 
Servlet 03
Servlet 03Servlet 03
Servlet 03
 
Servlet session 8
Servlet   session 8Servlet   session 8
Servlet session 8
 
Servlet
Servlet Servlet
Servlet
 
Servlet basics
Servlet basicsServlet basics
Servlet basics
 
J2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environmentJ2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environment
 
Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responses
 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet Basic
 
Chap4 4 1
Chap4 4 1Chap4 4 1
Chap4 4 1
 
WEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES ServletWEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES Servlet
 
J2ee servlet
J2ee servletJ2ee servlet
J2ee servlet
 
RESTing with JAX-RS
RESTing with JAX-RSRESTing with JAX-RS
RESTing with JAX-RS
 
Servlets intro
Servlets introServlets intro
Servlets intro
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
 
Servlet
ServletServlet
Servlet
 
Servlets
ServletsServlets
Servlets
 
SCWCD : The servlet container : CHAP : 4
SCWCD : The servlet container : CHAP : 4SCWCD : The servlet container : CHAP : 4
SCWCD : The servlet container : CHAP : 4
 
Java servlets
Java servletsJava servlets
Java servlets
 

More from Anuj Singh Rajput (20)

Web technology
Web technologyWeb technology
Web technology
 
Java script
Java scriptJava script
Java script
 
Html (hypertext markup language)
Html (hypertext markup language)Html (hypertext markup language)
Html (hypertext markup language)
 
Css
CssCss
Css
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
Jsp session 13
Jsp   session 13Jsp   session 13
Jsp session 13
 
Jsp session 12
Jsp   session 12Jsp   session 12
Jsp session 12
 
Jsp session 11
Jsp   session 11Jsp   session 11
Jsp session 11
 
Jsp session 10
Jsp   session 10Jsp   session 10
Jsp session 10
 
Jsp session 9
Jsp   session 9Jsp   session 9
Jsp session 9
 
Jsp session 8
Jsp   session 8Jsp   session 8
Jsp session 8
 
Jsp session 7
Jsp   session 7Jsp   session 7
Jsp session 7
 
Jsp session 6
Jsp   session 6Jsp   session 6
Jsp session 6
 
Jsp session 5
Jsp   session 5Jsp   session 5
Jsp session 5
 
Jsp session 4
Jsp   session 4Jsp   session 4
Jsp session 4
 
Jsp session 3
Jsp   session 3Jsp   session 3
Jsp session 3
 
Jsp session 2
Jsp   session 2Jsp   session 2
Jsp session 2
 
Jsp session 1
Jsp   session 1Jsp   session 1
Jsp session 1
 
Servlet session 14
Servlet   session 14Servlet   session 14
Servlet session 14
 
Servlet session 13
Servlet   session 13Servlet   session 13
Servlet session 13
 

Recently uploaded

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

Servlet session 7

  • 1. SESSION – 7 By→ Anuj Kumar Singh
  • 2. RequestDispatcher in Servlet The RequestDispatcher interface provides the facility of dispatching the request to another resource it may be html, servlet or jsp. This interface can also be used to include the content of another resource also. It is one of the way of servlet collaboration. Methods of RequestDispatcher interface 1. public void forward(ServletRequest request,ServletResponse response)throws ServletException,IOException:Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server. 2. public void include(ServletRequest request,ServletResponse response)throws ServletException,java.io.IOException:Includes the content of a resource (servlet, JSP page, or HTML file) in the response.
  • 3.
  • 4.
  • 5. How to get the object of RequestDispatcher The getRequestDispatcher() method of ServletRequest interface returns the object of RequestDispatcher. Syntax of getRequestDispatcher method public RequestDispatcher getRequestDispatcher(String resource); Example of using getRequestDispatcher method RequestDispatcher rd=request.getRequestDispatcher("servlet2"); //servlet2 is the url-pattern of the second servlet rd.forward(request, response);//method may be include or forward
  • 6. Example of RequestDispatcher interface 1. We are validating the password entered by the user. If password is servlet, it will forward the request to the WelcomeServlet, otherwise will show an error message. 2. In this example, we have created following files: a. index.html file: for getting input from the user. b. Login.java file: a servlet class for processing the response. If password is servlet, it will forward the request to the welcome servlet. c. WelcomeServlet.java file: a servlet class for displaying the welcome message. d. web.xml file: a deployment descriptor file that contains the information about the servlet.
  • 7.
  • 10. NewServlet1.java (If password matched then Welcome) Output 1 Output 2