CS4273: Distributed System Technologies and Programming I Lecture 7: Java Networking.

Slides:



Advertisements
Similar presentations
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Advertisements

CGI & HTML forms CGI Common Gateway Interface  A web server is only a pipe between user-agents  and content – it does not generate content.
TCP/IP Protocol Suite 1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 22 World Wide Web and HTTP.
DT228/3 Web Development WWW and Client server model.
PART 6 Application Layer
Kyung Hee University 1 1 Application Layer. 2 Kyung Hee University Position of Application Layer.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
JavaScript Forms Form Validation Cookies CGI Programs.
Servlets and a little bit of Web Services Russell Beale.
The Internet Useful Definitions and Concepts About the Internet.
INTERNET DATABASE Chapter 9. u Basics of Internet, Web, HTTP, HTML, URLs. u Advantages and disadvantages of Web as a database platform. u Approaches for.
Introduction to Web Database Processing
INTERNET DATABASE. Internet and E-commerce Internet – a worldwide collection of interconnected computer network Internet – a worldwide collection of interconnected.
Introduction to Web Interface Technology (CSE2030)
And so on CGI programming Web Services Java Programs for the Web.
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.
Introduction to Web Interface Technology (CSE2030)
WWW and Internet The Internet Creation of the Web Languages for document description Active web pages.
Using Entities & Creating Forms Jill R. Sommer Institute for Applied Linguistics Kent State University.
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.
Hypertext Transport Protocol CS Dick Steflik.
 What is it ? What is it ?  URI,URN,URL URI,URN,URL  HTTP – methods HTTP – methods  HTTP Request Packets HTTP Request Packets  HTTP Request Headers.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Servlets Compiled by Dr. Billy B. L. Lim. Servlets Servlets are Java programs which are invoked to service client requests on a Web server. Servlets extend.
Chapter 6: Hostile Code Guide to Computer Network Security.
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
INTRODUCTION TO WEB DATABASE PROGRAMMING
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
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.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Chapter 16 The World Wide Web Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Describe several.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
FTP (File Transfer Protocol) & Telnet
Chapter 6 The World Wide Web. Web Pages Each page is an interactive multimedia publication It can include: text, graphics, music and videos Pages are.
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.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
CS4273: Distributed System Technologies and Programming Lecture 13: Review.
Java CGI Lecture notes by Theodoros Anagnostopoulos.
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.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
Website Development with PHP and MySQL Saving Data.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
WWW: an Internet application Bill Chu. © Bei-Tseng Chu Aug 2000 WWW Web and HTTP WWW web is an interconnected information servers each server maintains.
Netprog 2002 CGI Programming1 CGI Programming CLIENT HTTP SERVER CGI Program http request http response setenv(), dup(), fork(), exec(),...
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
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.
World Wide Web Components Browsers and Servers CGI Processing Model (Common Gateway Interface) © Norman White, 2001.
How CGI and Java Servlets are Run By David Stein 14 November 2006.
Introduction to CGI PROG. CGI stands for Common Gateway Interface. CGI is a standard programming interface to Web servers that gives us a way to make.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
Lesson 11. CGI CGI is the interface between a Web page or browser and a Web server that is running a certain program/script. The CGI (Common Gateway Interface)
The Common Gateway Interface (CGI) Pat Morin COMP2405.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
Development of Web Applications - Introduction
WWW and HTTP King Fahd University of Petroleum & Minerals
PHP / MySQL Introduction
Client side & Server side scripting
Basic Protocols 24-Nov-18.
Basic Protocols 19-Feb-19.
Presentation transcript:

CS4273: Distributed System Technologies and Programming I Lecture 7: Java Networking

2 Web Networking in Java Applets Send Data back to Web Servers In many situations applets need to send data back to the server for processing. Generally there are two ways for applets to send data back to their home sites (note: applets can only communicate to their home sites): 1.Launch the application server on web site. Applets communicate with it via sockets. But you’re usually not allowed to launch your server on web site. 2.Use CGI (common gateway interface). It is well defined in HTTP protocol and most commonly used. App server

3 A simple ASP example An ASP Example <% ss = Request.Form("TextBox1") %> " />

4 CGI Program working with HTML forms Order Form Order Form <form action = " formcgi.cgi" method=POST> Name Street Address Credit Card No. Expire Date M/C Visa Ship by express

5 A simple example of a CGI program main(argc, argv) int argc; char *argv[]; {char *data; FILE *fp; // header: required by http protocol printf("Content-type: text/plain\n"); printf("\n"); scanf("%s", data); // read from browser // write data to a file fp = fopen("form.dat", "w+"); fprintf(fp, "%s\n", data); // send reply back to browser printf(“Your order is processed. Thanks!\n); } HTTP server CGI HTML form browser Web Server

6 Data format of HTML forms Data collected from the form is sent back to the web server as a single line of string, where fields are separated by “&”, space are replaced by “+” and other symbols by %ASCII code: customer=Xiaohua+Jia&address=CS+dept%2C+City+U+of+ HK&cardno= &expire=01%2F97&cc=visacard&ex press=on

7 CGI Program for HTML forms cgi programs can be developed in any language. After being compiled, name the executable file with the extension “.cgi”. put the cgi program in the same directory as the webpage (it can be in other dir, but you need specify correctly in the form). This program will be started by the HTTP server when a client clicks “submit” button of the form. The cgi program reads the form data from the stdin and its stdout has been redirected to the client browser. It processes the form data and sends replies back to the web browser (the replies is usually in HTML format, so that the browser can display the response nicely).

8 Applets Communicate with CGI Programs applets can take inputs from the user, send request to and recv replies from a cgi program via the web server using HTTP protocol. applets open a socket connecting back to the originating HTTP server. Then they use “POST” method to send data to the cgi program: out.println("POST "+ "/~jia /cgi/appletcgi.cgi HTTP/1.0"); out.println("Content-type: plain/text"); out.println("Content-length: " + data.length()); out.println("");// header ends with “\r” out.println(data); // data must be packed into one line http server strips the header from the packet received from applets and passes only the data to cgi program. cgi program (in the same format as that for HTML forms) receives data from applets through stdin and sends replies back through stdout. cgi program is started by HTTP server each time when an applet POSTs data.

9 Example of Applet Interacts With CGI Program public class appletCGI extends Applet implements ActionListener { public void init() { …………….. add("North", textin = new JtextField("“, 50)); textin.addActionListener(this); sourceArea = new TextArea(30, 80); } public void public void actionPerformed (ActionEvent e) { String sdata = textin.getText(); // no space in data!!! if (e.getSource() == textin) { s = new Socket("personal.cs.cityu.edu.hk",80); in = new BufferedReader(new InputStreamReader(s.getInputStream())); out = new PrintWriter(s.getOutputStream(), true); // one run of this protocol sends one line str out.println("POST /~jia/cgi/appletcgi.cgi HTTP/1.0"); out.println("Content-type: plain/text"); out.println("Content-length: " + sdata.length()); out.println(""); out.println(sdata ); while ((line = in.readLine()) != null) sourceArea.append(line+"\n"); out.close(); in.close();} ……… } ………

10 An “Echo” CGI program with Applet main(argc, argv) int argc; char *argv[]; { char sdata[256], rdata[256]; FILE *fp; printf("Content-type: text/plain\n"); printf("\n"); fp = fopen("form.dat", "a"); // append mode scanf("%s\r", rdata); fprintf(fp, "%s\n", rdata); // save to file printf(“Echoed from CGI: %s\n", rdata); fclose (fp); }

11 What A CGI Program Can Do After a CGI program is started by the http server, it receives data from applets (or HTML forms). It processes users inputs by: –connect to database servers to retrieve client requested data (convert client query into database query commands), –save the processed data to a local file, or –connect to mail servers to send s to users for data processing. Note: CGI is an ordinary application server. It can communicate with any servers running anywhere. CGI is a gateway to bridge applets to the outside of the world!

12 Implementation of Order CGI program can request a mail server to send the data received from an applet (or HTML form) to an -account as an . CGI program interacts with the mail server via SMTP (simple mail transfer protocol) to send an . Applet can’t access mail server directly due to security reason. SMTP is an ASCII text protocol. You can find the format of SMTP commands by using “telnet” to connect to an server. Important: telnet is a great debugging tool for Internet programming!!!

13 Implementation of Order (Cont.) class mailOrder { public static void main(String[] args ) { boolean more = true; String str = null; s = new Socket("mars.cs.cityu.edu.hk",25); in = new BufferedReader( new InputStreamReader(s.getInputStream())); out = new PrintWriter(s.getOutputStream(), true); str = in.readLine(); // read reply from svr System.out.println(str); // for debug // followings are SMTP commands out.println("HELO ss4e.cs.ust.hk\r" ); str = in.readLine(); // read reply from svr System.out.println(str); out.println("MAIL FROM: jcao\r" ); ……// read reply from mail svr out.println("RCPT TO: ); ……// read reply from mail svr out.println( "DATA\r" ); // start of data …… out.println( "this is 2nd test!\r" ); // body …… out.println( ".\r" ); // end of body …… out.println( "QUIT\r" ); // quit SMTP …… } ……. }

14 CGI program in Java Since the above cgi program (mailOrder) is written in Java and a Java program needs the Java interpreter to execute it, a cgi shell script is needed to execute the Java code: #!/bin/sh echo Content-type: text/plain echo /usr/local/jdk/bin/java mailOrder echo $QUERY_STRING