Session 22. Intra Server Control. Lecture Objectives

Similar documents
Integrating Servlets and JavaServer Pages Lecture 13

Model View Controller (MVC)

20/08/56. Java Technology, Faculty of Computer Engineering, KMITL 1

More JSP. Advanced Topics in Java. Khalid Azim Mughal Version date: ATIJ More JSP 1/42

About the Authors. Who Should Read This Book. How This Book Is Organized

Université du Québec à Montréal

Advance Java. Configuring and Getting Servlet Init Parameters per servlet

1Z Java EE 6 Web Component Developer Certified Expert Exam Summary Syllabus Questions

Module 3 Web Component

PES INSTITUTE OF TECHNOLOGY, SOUTH CAMPUS DEPARTMENT OF MCA INTERNAL TEST (SCHEME AND SOLUTION) II

Java 2 Platform, Enterprise Edition: Platform and Component Specifications

UNIT 6:CH:14 INTEGRATING SERVLETS AND JSPTHE MVC ARCHITECTURE

Servlets. An extension of a web server runs inside a servlet container

Session 25. Spring Controller. Reading & Reference

Session 12. JSP Tag Library (JSTL) Reading & Reference

Writing Servlets and JSPs p. 1 Writing a Servlet p. 1 Writing a JSP p. 7 Compiling a Servlet p. 10 Packaging Servlets and JSPs p.

Integrating Servlets and JSP: The MVC Architecture

HttpServlet ( Class ) -- we will extend this class to handle GET / PUT HTTP requests

Session 21. Expression Languages. Reading. Java EE 7 Chapter 9 in the Tutorial. Session 21 Expression Languages 11/7/ Robert Kelly,

a. Jdbc:ids://localhost:12/conn?dsn=dbsysdsn 21. What is the Type IV Driver URL? a. 22.

Session 11. Expression Language (EL) Reading

Java EE Application Assembly & Deployment Packaging Applications, Java EE modules. Model View Controller (MVC)2 Architecture & Packaging EJB Module

COMP9321 Web Application Engineering

Introduction to Java Server Pages. Enabling Technologies - Plug-ins Scripted Pages

Advanced Java Programming SRM UNIVERSITY FACULTY OF SCIENCE AND HUMANITIES DEPARTMENT OF COMPUTER SCIENCE

Fast Track to Java EE 5 with Servlets, JSP & JDBC

COMP9321 Web Application Engineering

Introduction to JSP and Servlets Training 5-days

This course is intended for Java programmers who wish to write programs using many of the advanced Java features.

JavaServer Pages (JSP)

Java Server Pages. JSP Part II

Questions and Answers

Unit 5 JSP (Java Server Pages)

JSP - ACTIONS. There is only one syntax for the Action element, as it conforms to the XML standard:

Server-side Web Programming

Ch04 JavaServer Pages (JSP)

********************************************************************

Unit 4 Java Server Pages

Session 8. Reading and Reference. en.wikipedia.org/wiki/list_of_http_headers. en.wikipedia.org/wiki/http_status_codes

PSD1B Advance Java Programming Unit : I-V. PSD1B- Advance Java Programming

COMP9321 Web Application Engineering

Table of Contents. Introduction... xxi

directive attribute1= value1 attribute2= value2... attributen= valuen %>

JavaServer Pages. What is JavaServer Pages?

CS506 Web Design & Development Final Term Solved MCQs with Reference

CSc31800: Internet Programming, CS-CCNY, Spring 2004 Jinzhong Niu May 9, JSPs 1

JAVA 2 ENTERPRISE EDITION (J2EE)

Web applications and JSP. Carl Nettelblad

Fast Track to Java EE

ive JAVA EE C u r r i c u l u m

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

One application has servlet context(s).

Developing Applications with Java EE 6 on WebLogic Server 12c

Java Server Page (JSP)

GUJARAT TECHNOLOGICAL UNIVERSITY

COMP9321 Web Application Engineering

CSC309: Introduction to Web Programming. Lecture 11

JSP MOCK TEST JSP MOCK TEST III

The Servlet Life Cycle

Web Programming. Lecture 11. University of Toronto

5.1 Registration and Configuration

JSP. Basic Elements. For a Tutorial, see:

<Insert Picture Here> Hudson Web Architecture. Winston Prakash. Click to edit Master subtitle style

CS193i Final Exam SITN students -- hopefully you are getting this soon enough to take it on

Type of Classes Nested Classes Inner Classes Local and Anonymous Inner Classes

SSC - Web development Model-View-Controller for Java Servlet

Oracle 10g: Build J2EE Applications

CE212 Web Application Programming Part 3

Session 9. Deployment Descriptor Http. Reading and Reference. en.wikipedia.org/wiki/http. en.wikipedia.org/wiki/list_of_http_headers

ADVANCED JAVA COURSE CURRICULUM

IT6503 WEB PROGRAMMING. Unit-I

Combining Doclets with JDBC and JSP Technologies to Deliver the Next-Generation Documentation System for the Java Platform

SESM Components and Techniques

Session 13. RESTful Services Part 2. Lecture Objectives

Java Enterprise Edition. Java EE Oct Dec 2016 EFREI/M1 Jacques André Augustin Page 1

4.1 The Life Cycle of a Servlet 4.2 The Java Servlet Development Kit 4.3 The Simple Servlet: Creating and compile servlet source code, start a web

Sun Sun Certified Web Component Developer for J2EE 5 Version 4.0

CSC309: Introduction to Web Programming. Lecture 10

Specialized - Mastering JEE 7 Web Application Development

ADVANCED JAVA TRAINING IN BANGALORE

MARATHWADA INSTITUTE OF TECHNOLOGY, AURANGABAD DEPARTMENT OF MASTER OF COMPUTER APPLICATIONS ADVANCE JAVA QUESTION BANK

FINALTERM EXAMINATION Spring 2009 CS506- Web Design and Development Solved by Tahseen Anwar

Babu Madhav Institute of Information Technology 2016

Session 8. JavaBeans. Reading & Reference. Reading. Reference. Session 8 Java Beans. 2/27/2013 Robert Kelly, Head First Chapter 3 (MVC)

Experiment No: Group B_2

Oracle - Developing Applications for the Java EE 7 Platform Ed 1 (Training On Demand)

J2EE Development. Course Detail: Audience. Duration. Course Abstract. Course Objectives. Course Topics. Class Format.

Session 24. Introduction to Java Server Faces (JSF) Robert Kelly, Reading.

Session 9. Introduction to Servlets. Lecture Objectives

COURSE 9 DESIGN PATTERNS

Web Application Services Practice Session #2

Database. Request Class. jdbc. Servlet. Result Bean. Response JSP. JSP and Servlets. A Comprehensive Study. Mahesh P. Matha

4. The transport layer

PRIMIX SOLUTIONS. Core Labs. Tapestry : Java Web Components Whitepaper

JAVA Training Overview (For Demo Classes Call Us )

Java E-Commerce Martin Cooke,

A Gentle Introduction to Java Server Pages

112. Introduction to JSP

Copyright Descriptor Systems, Course materials may not be reproduced in whole or in part without prior written consent of Joel Barnum

JSP. Common patterns

Transcription:

Session 22 Intra Server Control 1 Lecture Objectives Understand the differences between a server side forward and a redirect Understand the differences between an include and a forward and when each should be used 2 11/14/2018 1

We can pass control from a servlet to a JSP with a redirect or a forward. Servlets and JSP User agent Web Server A redirect is an HTTP status code that causes the browser to load a different page Tag Handler Bean JSP servlet JSP response.sendredirect("results-page.jsp"); 3 RequestDispatcher Interface An object that receives a request (and response) and sends these objects to a named resource (e.g., servlet, JSP file) on the server Operates entirely within the server String url = /presentations/presentation1.jsp ; RequestDispatcher dispatcher = request.getrequestdispatcher(url); dispatcher.forward(request, response); You can also get a handle from the ServletContext the forward method transfers control / indicates the path is relative to the root of the Web application. Otherwise relative to the original request 4 11/14/2018 2

Code a servlet that Are We on Track? Adds an attribute to the request object Forwards to a JSP that displays (using EL) the value of the request attribute (in a paragraph tag) RequestDispatcher is in the javax.servlet package 5 Were We on Track? Servlet... request.setattribute("a", "CSE336"); RequestDispatcher r = request.getrequestdispatcher("jsps/tracks/trackforward.jsp"); r.forward(request,response); JSP <h1>forward Example</h1> <p>the value of request attribute a is {requestscope.a</p> Or <p>the value of request attribute a is ${a</p> 6 11/14/2018 3

Forward / Include RequestDispatcher provides 2 methods forward Forwards a request to another resource on the server The destination resource generates the response Called before response buffer is flushed include Includes the response of the target in the response generated by the servlet using the dispatcher You will not likely use the include method in your project it is mainly for library tags 7 Forward / Include Issues Use the include method of RequestDispatcher to have the servlet provide response body Included page: Must be dynamic Cannot set the status code Cannot set headers Must use the flush attribute ( and set it to true) JSP provides support for includes and forwards <jsp:include page= pathname flush= true /> occurs at request time c:import is more powerful, so you may not need to use jsp:include 8 11/14/2018 4

servlet Example... InfoBean b = new InfoBean(); b.setvalue(request.getparameter( value )); request.setattribute( mybean, b); RequestDispatcher r = request.getrequestdispatcher( Next.jsp ); r.forward(request, response); Next.jsp The servlet forwards to next.jsp A request attribute is not the same as a request parameter... <p>the value that was forwarded is ${mybean.value</p> 9 Bean used in the example: package lectures; public class InfoBean { private String value; Example public void setvalue(string s) { value = s; public String getvalue() { return value; 10 11/14/2018 5

Have You Satisfied the Lecture Objectives? Understand the differences between a server side forward and a redirect Understand the differences between an include and a forward and in which cases each would be used 11 11/14/2018 6