Web Programming. Lecture 11. University of Toronto

Similar documents
CSC309: Introduction to Web Programming. Lecture 11

CSC309: Introduction to Web Programming. Lecture 10

JSP Scripting Elements

1.264 Lecture 15. Web development environments: JavaScript Java applets, servlets Java (J2EE) Active Server Pages

COMP9321 Web Application Engineering

COMP9321 Web Application Engineering

COMP9321 Web Application Engineering

Module7: AJAX. Click, wait, and refresh user interaction. Synchronous request/response communication model. Page-driven: Workflow is based on pages

Programming for Digital Media. Lecture 7 JavaScript By: A. Mousavi and P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Fall Semester (081) Module7: AJAX

Introduction to Ajax. Sang Shin Java Technology Architect Sun Microsystems, Inc.

Financial. AngularJS. AngularJS.

Financial. AngularJS. AngularJS. Download Full Version :

Java E-Commerce Martin Cooke,

AJAX Programming Chris Seddon

Part of this connection identifies how the response can / should be provided to the client code via the use of a callback routine.

UNIT-VI. HttpServletResponse It extends the ServletResponse interface to provide HTTP-specific functionality in sending a response.

CE212 Web Application Programming Part 3

CS506 Web Design & Development Final Term Solved MCQs with Reference

JavaServer Pages (JSP)

Servlet and JSP Review

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

Table of Contents. Introduction... xxi

Introduction. Literature: Steelman & Murach, Murach s Java Servlets and JSP. Mike Murach & Associates Inc, 2003

Introduction to Web Application Development Using JEE, Frameworks, Web Services and AJAX

Web Application Security

AJAX Basics. Welcome to AJAX Basics presentation. My name is Sang Shin. I am Java technology architect and evangelist from Sun Microsystems.

Session 8. Introduction to Servlets. Semester Project

Enterprise Java Technologies (Part 1 of 3) Component Architecture. Overview of Java EE. Java Servlets

Introduction. This course Software Architecture with Java will discuss the following topics:

Session 11. Calling Servlets from Ajax. Lecture Objectives. Understand servlet response formats

Welcome To PhillyJUG. 6:30-7:00 pm - Network, eat, find a seat 7:00-7:15 pm - Brief announcements 7:15-8:30 pm - Tom Janofsky's presentation

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

IT6503 WEB PROGRAMMING. Unit-I

AIM. 10 September

The Basic Web Server CGI. CGI: Illustration. Web based Applications, Tomcat and Servlets - Lab 3 - CMPUT 391 Database Management Systems 4

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

Introduction Haim Michael. All Rights Reserved.

Fast Track to Java EE

Java SE7 Fundamentals

JavaServer Faces Technology, AJAX, and Portlets: It s Easy if You Know How!

Ch04 JavaServer Pages (JSP)

Developing Ajax Web Apps with GWT. Session I

Advanced Java Programming

Advanced Internet Technology Lab # 4 Servlets

Developing Applications with Java EE 6 on WebLogic Server 12c

Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM Advanced Internet Technology Lab.

Chapter 2 How to structure a web application with the MVC pattern

Sun Sun Certified Web Component Developer for J2EE 5 Version 4.0

AJAX in Apache MyFaces A New Approach To Web Applications

Session 9. Introduction to Servlets. Lecture Objectives

JavaScript Programming

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

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

CSCI 201L Written Exam #1 Fall % of course grade

Session 11. Ajax. Reading & Reference

Oracle EXAM - 1Z Java Enterprise Edition 5 Web Component Developer Certified Professional Exam. Buy Full Product

AJAX Programming Overview. Introduction. Overview

Watch Core Java and Advanced Java Demo Video Here:

Introduction to AJAX Bringing Interactivity & Intuitiveness Into Web Applications. By : Bhanwar Gupta SD-Team-Member Jsoft Solutions

Web 2.0 Käyttöliittymätekniikat

AJAX: Rich Internet Applications

This course is designed for web developers that want to learn HTML5, CSS3, JavaScript and jquery.

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

Struts. P. O. Box Austin, TX Fax: +1 (801) (877) 866-JAVA

One application has servlet context(s).

Ajax and Web 2.0 Related Frameworks and Toolkits. Dennis Chen Director of Product Engineering / Potix Corporation

Java Server Page (JSP)

sessionx Desarrollo de Aplicaciones en Red A few more words about CGI CGI Servlet & JSP José Rafael Rojano Cáceres

Web based Applications, Tomcat and Servlets - Lab 3 -

Etanova Enterprise Solutions

JAVA COURSES. Empowering Innovation. DN InfoTech Pvt. Ltd. H-151, Sector 63, Noida, UP

AJAX and PHP AJAX. Christian Wenz,

Lesson 12: JavaScript and AJAX


Web Presentation Patterns (controller) SWEN-343 From Fowler, Patterns of Enterprise Application Architecture

JAVA. Duration: 2 Months

THE NEW ERA OF WEB DEVELOPMENT. qooxdoo. Andreas Ecker, Derrell Lipman

ICOM 5016 Database Systems. Database Users. User Interfaces and Tools. Chapter 8: Application Design and Development.

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

JavaScript Specialist v2.0 Exam 1D0-735

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

JavaServer Pages. Juan Cruz Kevin Hessels Ian Moon

Servlets and JSP (Java Server Pages)

Evaluation Copy. Ajax For Java Developers. If you are being taught out of this workbook, or have been sold this workbook, please call

Module 3 Web Component

Handout 31 Web Design & Development

Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains an Individual and Group component

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

Java Applets, etc. Instructor: Dmitri A. Gusev. Fall Lecture 25, December 5, CS 502: Computers and Communications Technology

Database Systems Lab. 11. JSP I 충남대학교컴퓨터공학과 데이타베이스시스템연구실

AJAX Workshop. Karen A. Coombs University of Houston Libraries Jason A. Clark Montana State University Libraries

2/6/2012. Rich Internet Applications. What is Ajax? Defining AJAX. Asynchronous JavaScript and XML Term coined in 2005 by Jesse James Garrett

Oracle Developer Day

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

Outline. AJAX for Libraries. Jason A. Clark Head of Digital Access and Web Services Montana State University Libraries


Ajax For Java Developers

JAVA SERVLET. Server-side Programming INTRODUCTION

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

Transcription:

CSC309: Introduction to Web Programming Lecture 11 Wael Aboulsaadat University of Toronto

Servlets+JSP Model 2 Architecture University of Toronto 2

Servlets+JSP Model 2 Architecture = MVC Design Pattern University of Toronto 3

Servlets+JSP Model 2 Architecture Controller Servlet Act as a single point of entry for requests Process the requests, accessing and modifying the underlying model Delegate the task of presenting information to a specific view component University of Toronto 4

Servlets+JSP Model 2 Architecture + Command Pattern Controller Servlet Act as a single point of entry for requests Process the requests by dispatching it to a specific command (command access and modify the underlying object model) Delegate the task of presenting information to a specific view component University of Toronto 5

Servlets+JSP Model 2 Architecture + Command Pattern import java.util.hashmap; public class ActionHelper { private static HashMap actions = new HashMap(); static { actions.put("viewtopic", "forum.viewtopicaction"); actions.put("login", "forum.loginaction"); actions.put("logout", "forum.logoutaction"); actions.put("newresponse", p "forum.newresponseaction"); actions.put("processnewresponse", "forum.processnewresponseaction"); actions.put("deleteresponse", "forum.deleteresponseaction"); } University of Toronto public static Action getaction(string name) { Action action = null; try { Class c = Class.forName((String)actions. get(name)); action = (Action)c.newInstance() newinstance() } catch (Exception e) { e.printstacktrace(); } return action; } } 6

Servlets+JSP Model 2 Architecture + Command Pattern import java.io.ioexception; import javax.servlet.*; import javax.servlet.http.*; public class FrontController extends HttpServlet { protected void processrequest( HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String actionname = req.getpathinfo().substring(1); Action action = ActionHelper.getAction(actionName); RequestDispatcher dispatcher = getservletcontext(). getrequestdispatcher(nextview); dispatcher.forward(req, res); } protected void doget(httpservletrequest req, HttpServletResponse tr res) throws ServletException, IOException { processrequest(req, res); } String nextview = action.process(req, res); University of Toronto 7

Servlets+JSP Model 2 Architecture + Command Pattern University of Toronto 8

JSP University of Toronto 9

JSP Example <HTML> <BODY> <H2>JSP Expressions</H2> <UL> <LI>Current time: <%= new java.util.date() %> <LI>Your hostname: <%= request.getremotehost() tr t t() %> <LI>The URI Requested: <%= request.getrequesturi() %> <LI>The Protocol Used: <%= request.getprotocol() %> <LI>Your session ID: <%= session.getid() %> <LI>The <CODE>testParam</CODE> form parameter: <%= request.getparameter("testparam") %> </UL> </BODY> </HTML> Server side Client side JSP Engine/Container <HTML> <BODY> <H2>JSP Expressions</H2> <UL> <LI>Current time: <LI>Your hostname: <LI>The URI Requested: <LI>The Protocol Used: <LI>Your session ID: <LI>The <CODE>testParam</CODE> form parameter: </UL> </BODY> </HTML> University of Toronto 10

The JSP Framework Idea: Use regular HTML for most of page Mark servlet code with special tags Entire JSP page gets translated into a servlet (once), and servlet is what actually gets invoked (for each request) University of Toronto 11

JSP elements reviewed JSP elements include: Scriptlet t enclosed in <% and %> markers: a small script in Java to perform arbitrary functions. Executed in the underlying servlet context. Expression: anything between <%= and %> markers is evaluated by the JSP engine as a Java expression in the servlet context. JSP directive enclosed in <%@ and %> markers passes information to the JSP engine (guides compilation ). JSP actions or tags are a set of customizable XML-style tags for particular actions, e.g. predefine jsp:usebean instantiates a JavaBean class on the server. University of Toronto 12

JSP makes extensive use of Java Beans JavaBeans API provides a standard format for Java classes Supported by Visual manipulation tools Auto-discovery of class information Basic criteria for Beans Zero argument constructor No public variables Access methods in the format of getxxx setxxx isxxx University of Toronto 13

Example JavaBean public class PersonBean implements java.io.serializable { public boolean isdeceased() { return this.deceased; d private String name; } private boolean deceased; public void setdeceased(final /** No-arg constructor (takes no arguments). */ boolean deceased) public PersonBean() { { } this.deceased = deceased; public String getname() { } return this.name; } } public void setname(final String name) { this.name = name; } University of Toronto 14

How to use a Bean in JSP? E.g. <jsp:usebean id= book1 class= Book /> Creates an instance of Book and bind to book1 It may be thought as equivalent to <% Book book1= new coreservlets.book() %> University of Toronto

JSP form handling via Beans (e.g.) University of Toronto 16

JSP form handling via Beans (e.g.) University of Toronto 17

JSP form handling via Beans (e.g.) University of Toronto 18

AJAX University of Toronto 19

What is AJAX? Ajax: Asynchronous JavaScript and XML The word "Asynchronous" in AJAX means that the request to the server will be made. The response will be made available by the server after it has finished processing the request, without t having to wait for it explicitly, itl to come back. i.e. you don t have to wait for an answer. University of Toronto

What is AJAX? cont d Delayed response due to processing by server Immediate response University of Toronto

What is AJAX? cont d University of Toronto 22

What is AJAX? cont d University of Toronto 23

Let s Create a Contrived Example Would be nice to see Ajax at work without worrying about server side code So, here is a contrived example We will have static pages on server Based on user selection, we will pull appropriate data from these pages and display University of Toronto 24

Starting ti with HTML University of Toronto 25

Providing an Event Handler University of Toronto 26

Using the XMLHttpHandler H University of Toronto 27

Using it in FireFox Firebug showing the async request and response University of Toronto 28

How about using IE? Does not work! University of Toronto 29

Microsoft started it! Microsoft started it with the ActiveX object Other browsers have followed, but No standard Making it work with IE University of Toronto 30

For IE University of Toronto 31

But, then FireFox does not work any more! What about other browser variations? Need to deal with these differences University of Toronto 32

Dealing with differences University of Toronto 33

Rich Internet Applications (RIA) using Ajax Examples: http://www.icefaces.org/main/demos/ http://demo.backbase.com/explorer/# examples/welco me.xml And DHTMLX University of Toronto 34

Other (RIA) Technologies Applet (Swing) Macromedia Flash Java WebStart DHTML DHTML with Hidden IFrame University of Toronto 35

What is AJAX? cont d Ajax isn t a new technology or programming language. g It is a technique used to develop interactive web applications that are able to process a user request immediately. University of Toronto 36

Ajax Component technologies Dynamic HTML XML Cascading stylesheets (.css) Document object model (DOM) JavaScript XMLHttpRequest University of Toronto 37

How AJAX Works? 1. A JavaScript function creates and configures an XMLHttpRequest t object on the client, and specifies a JavaScript callback function. 2. The XMLHttpRequest object makes an asynchronous call to the web server. 3. The web server processes the request and returns an XML document that contains the result. 4. The XMLHttpRequest object calls the callback function and exposes the response from the web server so that the request can be processed. 5. The client updates the HTML DOM representing the page University of Toronto 38

XMLHttpRequest? XMLHttpRequest object is the key to Ajax programming. It s main purpose is to put an asynchronous http request to the web server. Because of this asynchronous call to the web server, you are allowed to continue using the page without the interruption of a browser refresh and the loading of a new or revised page. This object has few properties. University of Toronto 39

Properties of XMLHttpRequest Property 1: objxmlhttp.onreadystatechange This property holds the reference of function which is going to process the response from the server. objxmlhttp.onreadystatechange o a = procrequest; * "procrequest " is the function which will process the response University of Toronto 40

Properties of XMLHttpRequest Property 2 : objxmlhttp. readystate t This property holds the status of server response. objxmlhttp.readystate = [state]; State Description 0 The request is not initialized 1 The request has been set up 2 The request has been sent 3 The request is in process 4 The request is complete University of Toronto 41

Pros Ajax applications are more responsive to user actions and the programs don t experience pagereloading-related interruptions. Ajax applications are usually fast because the approach minimizes traffic to the server by sending and requesting just the minimum amount of data needed. University of Toronto 42

Cons When pages with Ajax are indexed, the data displayed by Ajax calls is not present in the page workarounds are required to get dynamic Ajax content indexed it s simply not there in the page! Content rendered via AJAX is done via javascript Search engine spiders cannot invoke javascript events to retrieve AJAX content University of Toronto 43

Cons - contd Increased development time and costs Available frameworks and components still need to completely mature Not all concerns regarding security and user privacy have been answered Conflicts in modern browsers - navigate and create bookmarks University of Toronto 44

Cons - contd Not meant to be used in every application Concern of accessibility XMLHttpRequest object itself University of Toronto 45

Workarounds - Go on an AJAX diet Use hidden divs rather than Ajax Search engines will index the content Need AJAX content to be indexed Provide hidden links that can be spidered Limit the complexity of the logic Javascript-free Ajax AJAX should be limited to providing a better user experience through RIAs (Rich Internet Applications) University of Toronto 46

Conclusion Keeping the advantages and disadvantages in mind one has to choose whether or not to have AJAX to retrieve the content/data in their application. University of Toronto 47

Third-party libraries and frameworks Cross-browser libraries X library Sarissa Prototype Widgets and widget suites Scriptaculous Rico Application frameworks DWR, JSON, JPSpan (down), and SAJAX Backbase Echo2 Ruby on Rails Ajax.Net University of Toronto 48