© 2001-2003 Marty Hall, Larry Brown Web core programming 1 Using Applets as Front Ends to Server-Side Programs.

Slides:



Advertisements
Similar presentations
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Advertisements

DT228/3 Web Development WWW and Client server model.
Muhammad Taimoor Khan
Prepared By E. Musa Alyaman1 URLs, InetAddresses, and URLConnections Chapter 9.
Servlets and a little bit of Web Services Russell Beale.
1 Creating a network app Write programs that  run on different end systems and  communicate over a network.  e.g., Web: Web server software communicates.
Programming Applets How do Applets work ? This is an HTML page This is the applet’s code It has a link to an applet.
Slide 1 EE557: Server-Side Development Lecturer: David Molloy Room: XG19 Mondays 10am-1pm Notes:
1 Networking with Java 2: The Server Side. 2 Some Terms Mentioned Last Week TCP -Relatively slow but enables reliable byte-stream transmission UDP -Fast.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
CIS – Spring Instructors: Geoffrey Fox, Bryan Carpenter Computational Science and.
1 Web Search Interfaces. 2 Web Search Interface Web search engines of course need a web-based interface. Search page must accept a query string and submit.
1 CS6320 – Why Servlets? L. Grewe 2 What is a Servlet? Servlets are Java programs that can be run dynamically from a Web Server Servlets are Java programs.
28-Jun-15 Basic Protocols. 2 Sockets Sockets, or ports, are a very low level software construct that allows computers to talk to one another When you.
15-Jul-15 Basic Protocols. 2 Sockets Sockets, or ports, are a very low level software construct that allows computers to talk to one another When you.
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
1 Lecture 9 George Koutsogiannakis/ Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
HTTP; The World Wide Web Protocol
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Chapter 4: Core Web Technologies
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Application Protocols: HTTP CSNB534 Semester 2, 2007/2008 Asma Shakil.
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
4-Oct-15 Basic Protocols. 2 Sockets Sockets, or ports, are a very low level software construct that allows computers to talk to one another When you send.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
CS4273: Distributed System Technologies and Programming I Lecture 7: Java Networking.
Cli/Serv.: Chat/121 Client/Server Distributed Systems v Objectives –discuss a client/server based chat system –mention two other ways of chatting.
CS4273: Distributed System Technologies and Programming Lecture 13: Review.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: HTTP and CGI Fundamentals of Web Programming.
Chapter 18 Networking F Client/Server Communications F Simple Client/Server Applications F Serve Multiple Clients F Create Applet Clients F Send and Retrieve.
10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0.
Slides © Marty Hall, book © Sun Microsystems Press 1 Generating the HTTP Response Core Servlets & JSP book:
1 Streams Files are a computer’s long term memory Need ability for programs to –get information from files –copy information from program variables to.
Servlet Communication Other Servlets, HTML pages, objects shared among servlets on same server Servlets on another server with HTTP request of the other.
CS 11 java track: lecture 6 This week: networking basics Sockets Vectors parsing strings.
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
Lab 2 Primer Assignment 3 Structure File I/O More parsing and HTTP Formatting.
Chapter 16: Networking F Client/Server Communications F Serving Multiple Clients F Applet Clients F Viewing HTML Pages F Retrieving Files from Web Servers.
Servlets Part 3. Topics Session Tracking ServletToServletCommunication-Servlet Chaining ServerSideIncludes AppletToServlet.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
Jan 2001C.Watters1 World Wide Web and E-Commerce Client Side Processing.
2: Application Layer 1 Chapter 2: Application layer r 2.1 Principles of network applications  app architectures  app requirements r 2.2 Web and HTTP.
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 21 Java Servlets Wed. 11/22/00 based on material.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 7 Omar Meqdadi Department of Computer Science and Software Engineering University of.
Networking with JavaN-1 Outline Client-Server Example Steps required on the server side Steps required on the client side.
Network Programming: Servers. Agenda l Steps for creating a server Create a ServerSocket object Create a Socket object from ServerSocket Create an input.
Using Applets as Front Ends to Server-Side Programs.
Server-side http General form of http response/request GET request method POST request method Responses Servlet support.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Working with URLs CSIE, National University of Tainan.
Introduction to Servlets
Web Concepts Lesson 2 ITBS2203 E-Commerce for IT.
Chapter 18 Networking Client/Server Communications
Chapter 26 Servlets.
Generating the Server Response: HTTP Status Codes
Basic Protocols 24-Nov-18.
Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.
Basic Protocols 19-Feb-19.
Client-Server Model: Requesting a Web Page
Presentation transcript:

© Marty Hall, Larry Brown Web core programming 1 Using Applets as Front Ends to Server-Side Programs

Applet Front Ends2 Agenda Sending GET data and having the browser display the results Sending GET data and processing the results within the applet (HTTP tunneling) Using object serialization to exchange high- level data structures between applets and servlets Sending POST data and processing the results within the applet (HTTP tunneling) Bypassing the HTTP server altogether

Applet Front Ends3 Sending GET Request and Displaying Resultant Page Applet requests that browser display page – showDocument try { URL programURL = new URL(baseURL + "?" + someData); getAppletContext().showDocument(programURL); } catch(MalformedURLException mue) {... }; URL-encode the form data String someData = name1 + "=" + URLEncoder.encode(val1) + "&" + name2 + "=" + URLEncoder.encode(val2) + "&" +... nameN + "=" + URLEncoder.encode(valN);

Applet Front Ends4 GET Request Example: Applet public class SearchApplet extends Applet implements ActionListener {... public void actionPerformed(ActionEvent event) { String query = URLEncoder.encode(queryField.getText()); SearchSpec[] commonSpecs = SearchSpec.getCommonSpecs(); for(int i=0; i<commonSpecs.length-1; i++) { try { SearchSpec spec = commonSpecs[i]; URL searchURL = new URL(spec.makeURL(query, "10")); String frameName = "results" + i; getAppletContext().showDocument(searchURL, frameName); } catch(MalformedURLException mue) {} }

Applet Front Ends5 GET Request Example: Utility Class public class SearchSpec { private String name, baseURL, numResultsSuffix; private static SearchSpec[] commonSpecs = { new SearchSpec("google", " "&num="),... }; public String makeURL(String searchString, String numResults) { return(baseURL + searchString + numResultsSuffix + numResults); }... }

Applet Front Ends6 Get Request Example: HTML File Parallel Search Engine Results

Applet Front Ends7 Get Request: Initial Result

Applet Front Ends8 GET Request: Submission Result

Applet Front Ends9 HTTP Tunneling Idea –Open a socket connection to port 80 on the server and communicate through HTTP Advantages –Communicate through firewalls –Server-side programs only needs to return the data, not a complete HTML document Disadvantages –Can only tunnel to server from which the applet was loaded –Applet, not browser, receives the response Cannot easily display HTML

Applet Front Ends10 HTTP Tunneling and GET Requests Create URL object referring to applet’s host URL dataURL = new URL(…); Create a URLConnection object URLConnection connection = dataURL.openConnection(); Instruct browser not to cache URL data connection.setUseCaches(false); Set any desired HTTP headers Create an input stream –Call connection.getInputStream ; wrap in higher-level stream Read data sent from server –E.g., call readLine on BufferedReader Close the input stream

Applet Front Ends11 HTTP Tunneling Template: Client Side URL currentPage = getCodeBase(); String protocol = currentPage.getProtocol(); String host = currentPage.getHost(); int port = currentPage.getPort(); String urlSuffix = "/servlet/SomeServlet"; URL dataURL = new URL(protocol, host, port, urlSuffix); URLConnection connection = dataURL.getConnection(); connection.setUseCaches(false); connection.setRequestProperty("header", "value"); BufferedReader in = new BufferedReader( new InputStreamReader(connection.getInputStream())); String line; while ((line = in.readLine()) != null) { doSomethingWith(line); } in.close();

Applet Front Ends12 Using Object Serialization with HTTP Tunneling Idea –Server-side program (servlet) sends complete Java object –Client-side program (applet) reads it Client-side program (applet) template: ObjectInputStream in = new ObjectInputStream( connection.getInputStream()); SomeClass object = (SomeClass)in.readObject(); doSomethingWith(object);

Applet Front Ends13 Using Object Serialization with HTTP Tunneling (Continued) Server-side program (servlet) template: String contentType = "application/x-java-serialized-object"; response.setContentType(contentType); ObjectOutputStream out = new ObjectOutputStream( response.getOutputStream()); SomeClass object = new SomeClass(...); out.writeObject(value); out.flush();

Applet Front Ends14 Example: Live Scrolling Data

Applet Front Ends15 Sending POST Data to Server Applet sends POST request to server Processes the response directly Url currentPage = getCodeBase(); String protocol = currentPage.getProtocol(); String host = currentPage.getHost(); int port = currentPage.getPort(); String urlSuffix = "/servlet/SomeServlet"; URL dataURL = new URL(protocol, host, port, urlSuffix); URLConnection connection = dataURL.openConnection(); connection.setUseCaches(false); connection.setDoOutput(true);

Applet Front Ends16 Sending POST Data to Server (Continued) Character or Binary Data ByteArrayOutputStream byteStream = new ByteArrayOutputStream(512); PrintWriter out = new PrintWriter(byteStream, true); out.print(data); out.flush(); connection.setRequestProperty( "Content-Length", String.valueOf(byteStream.size())); connection.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded"); byteStream.writeTo(connection.getOutputStream());

Applet Front Ends17 Sending POST Data to Server Serialized Data ByteArrayOutputStream byteStream = new ByteArrayOutputStream(512); ObjectOutputStream out = new ObjectOutputStream(byteStream); out.writeObject(data); out.flush(); connection.setRequestProperty( "Content-Length", String.valueOf(byteStream.size())); connection.setRequestProperty( "Content-Type", "application/x-java-serialized-object"); byteStream.writeTo(connection.getOutputStream());

Applet Front Ends18 Sending POST Data: Example Sends data to a servlet that returns an HTML page showing form data it receives –Displays result in an AWT TextArea

Applet Front Ends19 Bypassing the HTTP Server If you are using applets, you don't have to communicate via HTTP –JDBC –RMI –SOAP (perhaps via JAX-RPC) –Raw sockets Advantages –Simpler –More efficient Disadvantages –Can only talk to server from which applet was loaded –Subject to firewall restrictions –You have to have a second server running

Applet Front Ends20 Summary Send data via GET and showDocument –Can access any URL –Only browser sees result Send data via GET and URLConnection –Can only access URLs on applet's home host –Applet sees results –Applet can send simple data –Server can send complex data (including Java objects) Send data via POST and URLConnection –Can only access URLs on applet's home host –Applet sees results –Applet can send complex data (including Java objects) –Server can send complex data (including Java objects) Bypass Web Server

© Marty Hall, Larry Brown Web core programming 21 Questions?