SlideShare a Scribd company logo
2
Most read
3
Most read
ADVANCED JAVA
REQUEST DISPATCHER INTERFACE
Prepared by:
Taha Malampattiwala – 140050107052
Introduction to Request Dispatcher
 RequestDispatcher is an interface, implementation of which defines an object which can dispatch request to
any resources(such as HTML, Image, JSP, Servlet) on the server.
 Methods of RequestDispatcher
RequestDispatcher interface provides two important methods.
Methods Description
void forward(ServletRequest request,
ServletResponse response)
forwards a request from a servlet to
another resource (servlet, JSP file, or
HTML file) on the server
void include(ServletRequest request,
ServletResponse response)
includes the content of a resource
(servlet, JSP page, HTML file) in the
response
 How to get an Object of RequestDispatcher
 getRequestDispatcher() method of ServletRequest returns the object of RequestDispatcher.
RequestDispatcher rs = request.getRequestDispatcher("hello.html");
rs.forward(request,response);
Example of RequestDispatcher interface
In this example, 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: sorry
username or password error!. In this program, we are cheking for hardcoded information. But
you can check it to the database also that we will see in the development chapter. In this
example, we have created following files:
index.html file: for getting input from the user.
Login.java file: a servlet class for processing the response. If password is servet, it will
forward the request to the welcome servlet.
WelcomeServlet.java file: a servlet class for displaying the welcome message.
web.xml file: a deployment descriptor file that contains the information about the servlet.
Request dispacther interface ppt
index.html
<form action="servlet1" method="post">
Name:<input type="text" name="userName"/><br/>
Password:<input type="password" name="userPass"/><br/>
<input type="submit" value="login"/>
</form>
WelcomeServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class WelcomeServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("userName");
out.print("Welcome "+n);
}
}
Login.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Login extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("userName");
String p=request.getParameter("userPass");
if(p.equals("servlet"){
RequestDispatcher rd=request.getRequestDispatcher("servlet2");
rd.forward(request, response);
}
else{
out.print("Sorry UserName or Password Error!");
RequestDispatcher rd=request.getRequestDispatcher("/index.html");
rd.include(request, response);
} } }
web.xml
<web-app>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>Login</servlet-class>
</servlet>
<servlet>
<servlet-name>WelcomeServlet</servlet-name>
<servlet-class>WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/servlet1</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>WelcomeServlet</servlet-name>
<url-pattern>/servlet2</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list> </web-app>
Request dispacther interface ppt
Request dispacther interface ppt
THANK YOU

More Related Content

PPT
Request dispatching in servlet
PPTX
Memento pattern
PPTX
Gof design patterns
PPTX
Spring data jpa
PPTX
Chapter 3 servlet & jsp
PPT
Command Pattern
PDF
Understanding react hooks
PPTX
Jdbc ppt
Request dispatching in servlet
Memento pattern
Gof design patterns
Spring data jpa
Chapter 3 servlet & jsp
Command Pattern
Understanding react hooks
Jdbc ppt

What's hot (20)

PDF
Remote Method Invocation (RMI)
PPT
PDF
Spring Data JPA
PPT
Jsp ppt
PPTX
Spring jdbc
PDF
Android Networking
PPTX
Introduction to Spring Framework
PDF
RESTful Web Services
PDF
Spring Data JPA
PDF
Servlet and servlet life cycle
PDF
C# Delegates and Event Handling
PDF
Chapter6 database connectivity
PPTX
OOP in PHP.pptx
PDF
Spring Data JPA from 0-100 in 60 minutes
PDF
Api presentation
PPT
Hibernate
PPT
ADO .Net
PDF
Spring Framework - MVC
PPT
Java And Multithreading
Remote Method Invocation (RMI)
Spring Data JPA
Jsp ppt
Spring jdbc
Android Networking
Introduction to Spring Framework
RESTful Web Services
Spring Data JPA
Servlet and servlet life cycle
C# Delegates and Event Handling
Chapter6 database connectivity
OOP in PHP.pptx
Spring Data JPA from 0-100 in 60 minutes
Api presentation
Hibernate
ADO .Net
Spring Framework - MVC
Java And Multithreading
Ad

Similar to Request dispacther interface ppt (20)

PDF
Servlets intro
PPTX
Http Server Programming in JAVA - Handling http requests and responses
PPTX
Servlets
PPT
Java Servlets
PPTX
Servlet session 7
PPTX
Web Technologies - forms and actions
DOCX
Servlet
PPT
Developing RESTful WebServices using Jersey
PPT
Chap4 4 1
DOC
Servlet basics
PDF
JAVA EE DEVELOPMENT (JSP and Servlets)
PPTX
Enterprise java unit-2_chapter-1
PPTX
JAX-RS 2.0 and OData
ODP
RESTing with JAX-RS
PPTX
PPTX
Ajax
PPTX
Understanding JSP -Servlets
PPTX
PPT
Basics Of Servlet
Servlets intro
Http Server Programming in JAVA - Handling http requests and responses
Servlets
Java Servlets
Servlet session 7
Web Technologies - forms and actions
Servlet
Developing RESTful WebServices using Jersey
Chap4 4 1
Servlet basics
JAVA EE DEVELOPMENT (JSP and Servlets)
Enterprise java unit-2_chapter-1
JAX-RS 2.0 and OData
RESTing with JAX-RS
Ajax
Understanding JSP -Servlets
Basics Of Servlet
Ad

More from Taha Malampatti (17)

PPTX
Lex & yacc
PPTX
Cultural heritage tourism
PPTX
Introduction to Android ppt
PPT
Intodcution to Html
PPTX
Introduction to php
PPTX
Database Connectivity in PHP
PPTX
Cox and Kings Pvt Industrial Training
PPT
Steganography ppt
PPTX
An application of 8085 register interfacing with LCD
PPTX
An application of 8085 register interfacing with LED
PPT
Java Virtual Machine
PPTX
The sunsparc architecture
PDF
Orthogonal Projection
PPTX
Apple inc
PPT
Blood donation
PPTX
Compressors and its applications
PPTX
Laws Of Gravitation
Lex & yacc
Cultural heritage tourism
Introduction to Android ppt
Intodcution to Html
Introduction to php
Database Connectivity in PHP
Cox and Kings Pvt Industrial Training
Steganography ppt
An application of 8085 register interfacing with LCD
An application of 8085 register interfacing with LED
Java Virtual Machine
The sunsparc architecture
Orthogonal Projection
Apple inc
Blood donation
Compressors and its applications
Laws Of Gravitation

Recently uploaded (20)

PDF
Well-logging-methods_new................
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Artificial Intelligence
PPTX
Geodesy 1.pptx...............................................
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Sustainable Sites - Green Building Construction
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
737-MAX_SRG.pdf student reference guides
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Current and future trends in Computer Vision.pptx
Well-logging-methods_new................
Foundation to blockchain - A guide to Blockchain Tech
Artificial Intelligence
Geodesy 1.pptx...............................................
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Sustainable Sites - Green Building Construction
Categorization of Factors Affecting Classification Algorithms Selection
737-MAX_SRG.pdf student reference guides
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
III.4.1.2_The_Space_Environment.p pdffdf
Internet of Things (IOT) - A guide to understanding
additive manufacturing of ss316l using mig welding
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Current and future trends in Computer Vision.pptx

Request dispacther interface ppt