SlideShare a Scribd company logo
Java/J2EE Programming Training
Request Dispatcher
Page 2Classification: Restricted
Agenda
• Understand Request Dispatcher
• JSP
Page 3Classification: Restricted
Page 4Classification: Restricted
num1
num2
Num1= 10
Num2= 20
sum = 30
response
Public void doGet(HttpServletRequest req,
HttpServletResponse res)
{
String num= req.getParameter(“num1”);
String num2 = req.getParameter(“num2”);
int n1 = Integer.parseInt(“num1”);
int n2= Integer.parseInt(“num2”);
Integer sum= n1 +n2;
req.setAttribute(“sum”,sum);
}
Page 6Classification: Restricted
FactorialServlet
num1
num2
Rd.forward(req, resp)
Num1= 10
Num2= 20
Sum = 30
respons
e
Public void doGet(HttpServletRequest
req, HttpServletResponse res)
{
request.setAttribute(“sum”, sum);
RequestDispatcher rd;
rd =
req.getRequestDispatcher(“fact”);
rd.forward(req, res)
}
Page 8Classification: Restricted
FactorialServlet
num1
num2
Rd.forward
(req, resp)
Public void
doGet(HttpServletRequest req,
HttpServletResponse res)
{ request.setAttribute(“sum”,
sum);
RequestDispatcher rd;
Rd =
req.getRequestDispatcher(“fa
ct”);
rd.forward(req, res)
}
Num1= 10
Num2= 20
Sum = 30
Response
“sum = “ +
sum
Public void
doGet(HttpServletRequest req,
HttpServletResponse res)
{
String sum =
req.getAttribute(“sum”).toString();
out.println( “sum = “ + sum )
}
Page 9Classification: Restricted
FactorialServlet
num1
num2
Rd.forward
(req, resp)
Public void
doGet(HttpServletRequest req,
HttpServletResponse res)
{ request.setAttribute(“sum”,
sum);
RequestDispatcher rd;
Rd =
req.getRequestDispatcher(“fact”
);
rd.forward(req, res)
}
Num1= 10
Num2= 20
Sum = 30
Response
“sum = “ +
sum
Public void
doGet(HttpServletRequest req,
HttpServletResponse res)
{
String sum =
req.getAttribute(“sum”).toString();
out.println( “sum = “ + sum )
}
Page 10Classification: Restricted
username
password
valid
Home.jsp Login.jsp
Page 11Classification: Restricted
public void doGet(HttpServletRequest req,
HttpServletResponse res)
{
if( valid)
{
RequestDispatcher rd =
req.getRequestDispatcher(“Home.jsp”)
rd.forward(req, res);
}
else
{
req.setAttribute(“error”, “username or
password is invalid”);
RequestDispatcher rd
=req.getRequestDispatcher(“Login.jsp”);
rd.forward(req, res);
}
}
login
Page 12Classification: Restricted
public void doGet(HttpServletRequest req,
HttpServletResponse res)
{
if( valid)
{
RequestDispatcher rd =
req.getRequestDispatcher(“Home.jsp”)
rd.forward(req, res);
}
else
{
req.setAttribute(“error”, “username or password
is invalid”);
RequestDispatcher rd
=req.getRequestDispatcher(“Login.jsp”);
rd.forward(req, res);
}
}
Home About
username/pwd
invalid
login
Page 13Classification: Restricted
public void doGet(HttpServletRequest req,
HttpServletResponse res)
{
if( valid)
{
RequestDispatcher rd =
req.getRequestDispatcher(“Home.jsp”)
rd.forward(req, res);
}
else
{
req.setAttribute(“error”, “username or password is
invalid”);
RequestDispatcher rd
=req.getRequestDispatcher(“Login.jsp”);
rd.forward(req, res);
}
}
Home About
L
Login.jsp
username/pwd
invalid
${requestScope.e
rror}
login
error=“username/pwd is
invalid
Page 14Classification: Restricted
JSP
• Java Server Pages
• used for developing server side response
• to add dynamic functionality to web page
• java code is written inside html
• gets the container support
• Life Cycle methods
• jspInit()
• _jspService
• jspDestroy
Page 15Classification: Restricted
Compilation & Execution
• Execution of jsp is done in two phases
• translation
• Web container translates Hello.jsp to _Hello.java
• Converts jsp to servlet
• compilation
• generates Hello.class file
• load the class file
• creates the instance of Hello
• calls init method
• call service method
• calls destroy method.
Page 16Classification: Restricted
Hello.jsp->_Hello.java
compiles _Hello.java to
_Hello.class
Page 17Classification: Restricted
_jspInit()
_jspServic
e()
_jspServic
e()
_jspServic
e()
Page 18Classification: Restricted
_jspInit()
_jspServic
e()
_jspServic
e()
_jspServic
e()
jspDestroy()
Page 19Classification: Restricted
Thank You

More Related Content

PDF
Hidden in Plain Sight: DUAL_EC_DRBG 'n stuff
PPTX
Using Change Streams to Keep Up with Your Data
PDF
Rajeev oops 2nd march
PDF
Qt Rest Server
PPTX
How Not to Code
PDF
생산적인 개발을 위한 지속적인 테스트
PDF
Declaring friend function with inline code
PDF
PVS-Studio in 2021 - Error Examples
Hidden in Plain Sight: DUAL_EC_DRBG 'n stuff
Using Change Streams to Keep Up with Your Data
Rajeev oops 2nd march
Qt Rest Server
How Not to Code
생산적인 개발을 위한 지속적인 테스트
Declaring friend function with inline code
PVS-Studio in 2021 - Error Examples

What's hot (12)

PDF
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
PDF
MongoDB Performance Debugging
PPTX
How Data Flow analysis works in a static code analyzer
PDF
Clang tidy
PPTX
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
PPTX
Building High-Performance Language Implementations With Low Effort
PDF
Mongodb debugging-performance-problems
PDF
20110514 mongo dbチューニング
PDF
Nko workshop - node js crud & deploy
PPTX
C programming
PDF
JavaScript Proxy (ES6)
PPTX
It's 10pm: Do You Know Where Your Writes Are?
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
MongoDB Performance Debugging
How Data Flow analysis works in a static code analyzer
Clang tidy
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Building High-Performance Language Implementations With Low Effort
Mongodb debugging-performance-problems
20110514 mongo dbチューニング
Nko workshop - node js crud & deploy
C programming
JavaScript Proxy (ES6)
It's 10pm: Do You Know Where Your Writes Are?
Ad

Similar to Java Request Dispatcher (8)

PPTX
Spring Web MVC
PPTX
Java MVC
PPTX
Enterprise java unit-2_chapter-1
PPTX
Session 29 - Servlets - Part 5
PPT
Request dispatching in servlet
PPTX
Session 28 - Servlets - Part 4
PPTX
SCWCD : The servlet model CHAP : 2
PPTX
SCWCD : The servlet model : CHAP : 2
Spring Web MVC
Java MVC
Enterprise java unit-2_chapter-1
Session 29 - Servlets - Part 5
Request dispatching in servlet
Session 28 - Servlets - Part 4
SCWCD : The servlet model CHAP : 2
SCWCD : The servlet model : CHAP : 2
Ad

More from AathikaJava (15)

PPTX
Java While Loop
PPTX
Java Webservices
PPTX
Java Type Casting
PPTX
Java Session
PPTX
Java Servlet Lifecycle
PPTX
Java Rest
PPTX
Java Polymorphism Part 2
PPTX
Java Polymorphism
PPTX
Java Spring
PPTX
Mapping Classes with Relational Databases
PPTX
Introduction to Java
PPTX
Java Encapsulation and Inheritance
PPT
Hibernate basics
PPTX
Java Filters
PPTX
Encapsulation
Java While Loop
Java Webservices
Java Type Casting
Java Session
Java Servlet Lifecycle
Java Rest
Java Polymorphism Part 2
Java Polymorphism
Java Spring
Mapping Classes with Relational Databases
Introduction to Java
Java Encapsulation and Inheritance
Hibernate basics
Java Filters
Encapsulation

Recently uploaded (20)

PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Cloud computing and distributed systems.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Approach and Philosophy of On baking technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Machine Learning_overview_presentation.pptx
Chapter 3 Spatial Domain Image Processing.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
MIND Revenue Release Quarter 2 2025 Press Release
Cloud computing and distributed systems.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
NewMind AI Weekly Chronicles - August'25-Week II
“AI and Expert System Decision Support & Business Intelligence Systems”
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
Approach and Philosophy of On baking technology
Review of recent advances in non-invasive hemoglobin estimation
A comparative analysis of optical character recognition models for extracting...
Advanced methodologies resolving dimensionality complications for autism neur...
sap open course for s4hana steps from ECC to s4
20250228 LYD VKU AI Blended-Learning.pptx
Machine Learning_overview_presentation.pptx

Java Request Dispatcher