SlideShare a Scribd company logo
Redirection
Agenda
• Understanding Client side redirection
• Understanding ServletContext
• Understanding RequestDispatcher
• Understanding Server Side Redirection
• Difference between include and forward
What is Redirection
• Page redirection is generally used when we need to
- send the client to a new location
- Load balancing
Types of Redirection
• Two types of Redirection
- Client side
• Use request.sendRedirect
• Use response.setStatus and response.setHeader
- Server side
• Use RequestDispatcher
- include()
- forward()
Client Redirection explained
Client make original request for page1
Page1 contains redirecting response
Redirecting response comes to the client
Page1 is not displayed to the client
Without user intervention it request page2
Page2 is ultimately displayed to the client
Understanding ServletContext
• Only one ServletContext is created by container
• Servlet’s instances can see its environment through ServletContext
• It Contains method using which the servlets can communicate
• It shares all the information required by the enitre application
components(Servlets,JSP)
Understanding RequestDispatcher
• RequestDispatcher Object forwards a client request to a resource
or include resource itself in response back to the client.
• Resource can be
- Servlet
- JSP
- HTML
sendRedirect vs RequestDispatcher
Understanding RequestDispatcher
Understanding RequestDispatcher
• RequestDispatcher can be created from
- ServletContext
- ServletRequest
• Absolute URL can be specified only when RequestDispatcher invoked
from ServletRequest
Difference between include and forward
• Forward
- Control is transferred to the new page
- The output of the current page is not rendered
• Include
- Control is retained in the current page
- The output of the current page is rendered along with the new page
Status Codes
• response.setStatus(int statusCode)
- Use a constant for the code, not an explicit int.
- Constants are in HttpServletResponse
- Names derived from standard message.
- E.g., SC_OK, SC_NOT_FOUND, etc.
• response.sendError(int code,String message)
- Wraps message inside small HTML document
• response.sendRedirect(String url)
• Sets status code to 302
• Sets Location response header also
Summary
• Response.sendRedirect does client side redirection
• RequestDispatcher does Server Side redirection
• Include will retain the control in the old page
• Forward will transfer control to the new page

More Related Content

PPTX
Servlet session 8
PPTX
Node js crash course session 3
PDF
Introduction to Javascript in Magento 2 | Colorado Magento Meetup
PPTX
Mule: JSON to Object
PPTX
Intro to Web Sockets
ODP
JSON Edit, Validate, Query, Transform, and Convert
PDF
Robust web apps with React.js
PDF
React js use contexts and useContext hook
Servlet session 8
Node js crash course session 3
Introduction to Javascript in Magento 2 | Colorado Magento Meetup
Mule: JSON to Object
Intro to Web Sockets
JSON Edit, Validate, Query, Transform, and Convert
Robust web apps with React.js
React js use contexts and useContext hook

What's hot (11)

PPTX
Mule parsing with json
PPTX
Mule parsing with json part2
PPT
Rest Service In Mule
PDF
Robust UI development with ClojureScript
PPTX
Introduction to React JS for beginners
PPTX
Until successful scope in mule
PPT
Rest service in mule
PPT
2310 b 13
PPT
Single thread interface in servlet
PDF
Android rest client applications-services approach @Droidcon Bucharest 2012
PPT
2310 b 12
Mule parsing with json
Mule parsing with json part2
Rest Service In Mule
Robust UI development with ClojureScript
Introduction to React JS for beginners
Until successful scope in mule
Rest service in mule
2310 b 13
Single thread interface in servlet
Android rest client applications-services approach @Droidcon Bucharest 2012
2310 b 12
Ad

Similar to Advance java session 4 (20)

PPT
Request dispatching in servlet
PDF
Csajsp Chapter15
PDF
J2EE Difference
PDF
Java Difference
PPT
Servlet 03
PPTX
J2EE : Java servlet and its types, environment
PDF
05 status-codes
PPTX
Servlet session 7
PDF
J2EE_Course_Content
PPTX
SCWCD : Handling exceptions : CHAP : 5
PDF
Jsf2 overview
PPTX
Integrating Servlets and JSP (The MVC Architecture)
PPTX
Enterprise java unit-2_chapter-1
PPTX
Session 29 - Servlets - Part 5
DOCX
Servlet
PPT
Session 2 servlet context and session tracking - Giáo trình Bách Khoa Aptech
PPTX
Request dispacther interface ppt
PPTX
BITM3730Week12.pptx
Request dispatching in servlet
Csajsp Chapter15
J2EE Difference
Java Difference
Servlet 03
J2EE : Java servlet and its types, environment
05 status-codes
Servlet session 7
J2EE_Course_Content
SCWCD : Handling exceptions : CHAP : 5
Jsf2 overview
Integrating Servlets and JSP (The MVC Architecture)
Enterprise java unit-2_chapter-1
Session 29 - Servlets - Part 5
Servlet
Session 2 servlet context and session tracking - Giáo trình Bách Khoa Aptech
Request dispacther interface ppt
BITM3730Week12.pptx
Ad

More from Smita B Kumar (20)

PPTX
Advance java session 20
PPTX
Advance java session 19
PPTX
Advance java session 18
PPTX
Advance java session 17
PPTX
Advance java session 16
PPTX
Advance java session 15
PPTX
Advance java session 14
PPTX
Advance java session 13
PPTX
Advance java session 12
PPTX
Advance java session 11
PPTX
Advance java session 10
PPTX
Advance java session 9
PPTX
Advance java session 8
PPTX
Advance java session 7
PPTX
Advance java session 6
PPTX
Advance java session 5
PPTX
Advance java session 3
PPTX
Advance java session 2
PPTX
JEE session 1
PPTX
01 introduction to struts2
Advance java session 20
Advance java session 19
Advance java session 18
Advance java session 17
Advance java session 16
Advance java session 15
Advance java session 14
Advance java session 13
Advance java session 12
Advance java session 11
Advance java session 10
Advance java session 9
Advance java session 8
Advance java session 7
Advance java session 6
Advance java session 5
Advance java session 3
Advance java session 2
JEE session 1
01 introduction to struts2

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
KodekX | Application Modernization Development
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Electronic commerce courselecture one. Pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectral efficient network and resource selection model in 5G networks
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MYSQL Presentation for SQL database connectivity
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
“AI and Expert System Decision Support & Business Intelligence Systems”
KodekX | Application Modernization Development
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Electronic commerce courselecture one. Pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Big Data Technologies - Introduction.pptx
Understanding_Digital_Forensics_Presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Programs and apps: productivity, graphics, security and other tools
NewMind AI Weekly Chronicles - August'25 Week I
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Building Integrated photovoltaic BIPV_UPV.pdf
sap open course for s4hana steps from ECC to s4
Per capita expenditure prediction using model stacking based on satellite ima...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

Advance java session 4

  • 2. Agenda • Understanding Client side redirection • Understanding ServletContext • Understanding RequestDispatcher • Understanding Server Side Redirection • Difference between include and forward
  • 3. What is Redirection • Page redirection is generally used when we need to - send the client to a new location - Load balancing
  • 4. Types of Redirection • Two types of Redirection - Client side • Use request.sendRedirect • Use response.setStatus and response.setHeader - Server side • Use RequestDispatcher - include() - forward()
  • 5. Client Redirection explained Client make original request for page1 Page1 contains redirecting response Redirecting response comes to the client Page1 is not displayed to the client Without user intervention it request page2 Page2 is ultimately displayed to the client
  • 6. Understanding ServletContext • Only one ServletContext is created by container • Servlet’s instances can see its environment through ServletContext • It Contains method using which the servlets can communicate • It shares all the information required by the enitre application components(Servlets,JSP)
  • 7. Understanding RequestDispatcher • RequestDispatcher Object forwards a client request to a resource or include resource itself in response back to the client. • Resource can be - Servlet - JSP - HTML
  • 10. Understanding RequestDispatcher • RequestDispatcher can be created from - ServletContext - ServletRequest • Absolute URL can be specified only when RequestDispatcher invoked from ServletRequest
  • 11. Difference between include and forward • Forward - Control is transferred to the new page - The output of the current page is not rendered • Include - Control is retained in the current page - The output of the current page is rendered along with the new page
  • 12. Status Codes • response.setStatus(int statusCode) - Use a constant for the code, not an explicit int. - Constants are in HttpServletResponse - Names derived from standard message. - E.g., SC_OK, SC_NOT_FOUND, etc. • response.sendError(int code,String message) - Wraps message inside small HTML document • response.sendRedirect(String url) • Sets status code to 302 • Sets Location response header also
  • 13. Summary • Response.sendRedirect does client side redirection • RequestDispatcher does Server Side redirection • Include will retain the control in the old page • Forward will transfer control to the new page