CSC309: Introduction to Web Programming. Lecture 11

Similar documents
Web Programming. Lecture 11. University of Toronto

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

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

Table of Contents. Introduction... xxi

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

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

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

IT6503 WEB PROGRAMMING. Unit-I

AIM. 10 September

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!

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

Advanced Internet Technology Lab # 4 Servlets

Ch04 JavaServer Pages (JSP)

Developing Ajax Web Apps with GWT. Session I

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

Advanced Java Programming

Developing Applications with Java EE 6 on WebLogic Server 12c

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

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

JavaScript Programming

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

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

Session 11. Ajax. Reading & Reference

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

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

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

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

One application has servlet context(s).

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

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

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

JavaScript Specialist v2.0 Exam 1D0-735

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

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

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

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

Handout 31 Web Design & Development

Module 3 Web Component

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

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

Oracle Developer Day

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

JAVA SERVLET. Server-side Programming INTRODUCTION


Ajax For Java Developers

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

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

Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains 2 components

Transcription:

CSC309: Introduction to Web Programming Lecture 11 Wael Aboulsaadat

Servlets+JSP Model 2 Architecture 2

Servlets+JSP Model 2 Architecture = MVC Design Pattern 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 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 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", "forum.newresponseaction"); actions.put("processnewresponse", "forum.processnewresponseaction"); actions.put("deleteresponse", "forum.deleteresponseaction"); } public static Action getaction(string name) { Action action = null; try { Class c = Class.forName((String)actions. get(name)); action = (Action)c.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 res) throws ServletException, IOException { processrequest(req, res); } String nextview = action.process(req, res); 7

Servlets+JSP Model 2 Architecture + Command Pattern 8

JSP 9

JSP Example <HTML> <BODY> <H2>JSP Expressions</H2> <UL> <LI>Current time: <%= new java.util.date() %> <LI>Your hostname: <%= request.getremotehost() %> <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> 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) 11

JSP elements reviewed JSP elements include: Scriptlet 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. 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 13

Example JavaBean public class PersonBean implements java.io.serializable { private String name; private boolean deceased; /** No-arg constructor (takes no arguments). */ public PersonBean() { } public String getname() { return this.name; } } public boolean isdeceased() { return this.deceased; } public void setdeceased(final boolean deceased) { this.deceased = deceased; } public void setname(final String name) { this.name = name; } 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() %>

JSP form handling via Beans (e.g.) 16

JSP form handling via Beans (e.g.) 17

JSP form handling via Beans (e.g.) 18

AJAX 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 having to wait for it explicitly, to come back. i.e. you don t have to wait for an answer.

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

What is AJAX? cont d 22

What is AJAX? cont d 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 24

Starting with HTML 25

Providing an Event Handler 26

Using the XMLHttpHandler 27

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

How about using IE? Does not work! 29

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

For IE 31

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

Dealing with differences 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 34

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

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

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

How AJAX Works? 1. A JavaScript function creates and configures an XMLHttpRequest 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 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. 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 = procrequest; * "procrequest " is the function which will process the response 40

Properties of XMLHttpRequest Property 2 : objxmlhttp. readystate 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 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. 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 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 44

Cons - contd Not meant to be used in every application Concern of accessibility XMLHttpRequest object itself 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) 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. 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 48