Outline of Lecture 5. Course Content. Objectives of Lecture 6 CGI and HTML Forms

Similar documents
Forms, CGI. Cristian Bogdan 2D2052 / 2D1335 F5 1

Forms, CGI. HTML forms. Form example. Form example...

NETB 329 Lecture 13 Python CGI Programming

Common Gateway Interface CGI

Outline. Lecture 8: CGI (Common Gateway Interface ) Common Gateway Interface (CGI) CGI Overview

PYTHON CGI PROGRAMMING

Publishing On the Web. Course Content. Objectives of Lecture 7 Dynamic Pages

COSC 2206 Internet Tools. The HTTP Protocol

USQ/CSC2406 Web Publishing

Forms, CGI. Objectives

Outline of Lecture 3 Protocols

Chapter 17 : Internet Publishing

CS105 Perl: Perl CGI. Nathan Clement 24 Feb 2014

Dynamic Documents. Kent State University Dept. of Math & Computer Science. CS 4/55231 Internet Engineering. What is a Script?

Server-Side Web Programming: Python (Part 1) Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University

Internet and Web Based Technology.

Common Gateway Interface

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

Web technologies. Web. basic components. embellishments in browser. DOM (document object model)

Everyday Activity. Course Content. Objectives of Lecture 13 Search Engine

Chapter 1 FORMS. SYS-ED/ Computer Education Techniques, Inc.

core programming HTML Forms Sending Data to Server-Side Programs Marty Hall, Larry Brown

Javascript, Java, Flash, Silverlight, HTML5 (animation, audio/video, ) Ajax (asynchronous Javascript and XML)

Web Engineering. Basic Technologies: Protocols and Web Servers. Husni

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

COMS 359: Interactive Media

Implementing a Web Server on OS/390: Part III Writing Common Gateway Interfaces and Installing Java Virtual Machine

Web Programming. Based on Notes by D. Hollinger Also Java Network Programming and Distributed Computing, Chs.. 9,10 Also Online Java Tutorial, Sun.

CGI Programming. What is "CGI"?

Creating and Building Websites

Networking and Internet

HTML Forms. By Jaroslav Mohapl

Summary 4/5. (contains info about the html)

HTML 5 Tables and Forms

Course Topics. The Three-Tier Architecture. Example 1: Airline reservations. IT360: Applied Database Systems. Introduction to PHP

1.264 Lecture 12. HTML Introduction to FrontPage

Course Content. Outline of Lecture 10. Objectives of Lecture 10 DBMS & WWW. CMPUT 499: DBMS and WWW. Dr. Osmar R. Zaïane. University of Alberta 4

CSC309: Introduction to Web Programming. Lecture 8

CGI Architecture Diagram. Web browser takes response from web server and displays either the received file or error message.

Figure 1 Forms category in the Insert panel. You set up a form by inserting it and configuring options through the Properties panel.

The Hypertext Markup Language (HTML) Part II. Hamid Zarrabi-Zadeh Web Programming Fall 2013

CHAPTER 2 MARKUP LANGUAGES: XHTML 1.0

You can also set the expiration time of the cookie in another way. It may be easier than using seconds.

HTML Tables and Forms. Outline. Review. Review. Example Demo/ Walkthrough. CS 418/518 Web Programming Spring Tables to Display Data"

Shankersinh Vaghela Bapu Institue of Technology

Spring 2014 Interim. HTML forms

Form Overview. Form Processing. The Form Element. CMPT 165: Form Basics

3. WWW and HTTP. Fig.3.1 Architecture of WWW

Web Site Design and Development Lecture 23. CS 0134 Fall 2018 Tues and Thurs 1:00 2:15PM

DAY 2. Creating Forms

Hyperlinks, Tables, Forms and Frameworks

Document Object Model. Overview

CMPE 151: Network Administration. Servers

Using SAS/IntrNet Software

Giving credit where credit is due

HTML. HTML Evolution

WWW Document Technologies

Lecture (03) from static HTML to

Creating Forms in SOCS

Web forms and CGI scripts

1 Form Basics CSC309

Chapter 27 WWW and HTTP Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Time Server. TCP/IP Intro. Time Client. Well-known TCP/IP ports

Building Web Based Application using HTML

LAB MANUAL SUBJECT: WEB TECHNOLOGY CLASS : T.E (COMPUTER) SEMESTER: VI

Web History. Systemprogrammering 2006 Föreläsning 9 Web Services. Internet Hosts. Web History (cont) 1945: 1989: Topics 1990:

Writing Perl Programs using Control Structures Worked Examples

Part I. Web Technologies for Interactive Multimedia

Dynamic HTML becomes HTML5. HTML Forms and Server Processing. Form Submission to Web Server. DHTML - Mouse Events. CMST385: Slide Set 8: Forms

Form Processing in PHP

Lecture : 3. Practical : 2. Course Credit. Tutorial : 0. Total : 5. Course Learning Outcomes

Chapter 4 Sending Data to Your Application

Web Recommendations for Mobile Web Browsing

CSE 154 LECTURE 8: FORMS

CSI 3140 WWW Structures, Techniques and Standards. Markup Languages: XHTML 1.0

ITEC447 Web Projects CHAPTER 9 FORMS 1

Remote Procedure Calling

COMP519 Practical 14 Python (5)

introduction to XHTML

Week 8: HyperText Transfer Protocol - Clients - HTML. Johan Bollen Old Dominion University Department of Computer Science

OpenQM. Building a CGI Web Server. Martin Phillips Ladybridge Systems Ltd

HTML HTML. Chris Seddon CRS Enterprises Ltd 1

FORM VALIDATION. June 2016 IJIRT Volume 3 Issue 1 ISSN: Himanshu Kapoor Dronacharya College Of Engineering, Khentawas, Gurgaon

HTML crashcourse. general structure tables forms textfield textarea selectbox listbox hidden field checkbox radiobuttons submit button

Web Design and Development ACS Chapter 13. Using Forms 11/27/2018 1

UR what? ! URI: Uniform Resource Identifier. " Uniquely identifies a data entity " Obeys a specific syntax " schemename:specificstuff

HTML: Fragments, Frames, and Forms. Overview

HTML and JavaScript: Forms and Validation

Course title: WEB DESIGN AND PROGRAMMING

COMP519 Web Programming Autumn CGI Programming

Outline. Introducing Form. Introducing Forms 2/21/2013 INTRODUCTION TO WEB DEVELOPMENT AND HTML

1. Begin by selecting [Content] > [Add Content] > [Webform] in the administrative toolbar. A new Webform page should appear.

COMP519 Web Programming Autumn CGI Programming

CROSS SITE PRINTING. Printer Spamming

5. JavaScript Basics

Databases HTML and PHP I. (GF Royle, N Spadaccini ) HTML/PHP I 1 / 28

Advanced HTML Scripting WebGUI Users Conference

Course Topics. IT360: Applied Database Systems. Introduction to PHP

Computer Science E-75 Building Dynamic Websites

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

Transcription:

Web-Based Information Systems Fall 2004 CMPUT 410: CGI and HTML Forms Dr. Osmar R. Zaïane University of Alberta Outline of Lecture 5 Introduction Poor Man s Animation Animation with Java Animation with JavaScript Sound Animation with DHTML Objectives Learn about old and new techniques that allow animation in web pages. See some more concepts related to web technologies, server-side and client-side. University of Alberta 1 University of Alberta 2 Course Content Introduction Internet and WWW Protocols HTML and beyond Animation & WWW CGI & HTML Forms Javascript Databases & WWW Dynamic Pages Perl & Cookies SGML / XML CORBA & SOAP Web Services Search Engines Recommender Syst. Web Mining Security Issues Selected Topics Objectives of Lecture 6 CGI and HTML Forms Learn about another aspect of HTML: building forms to input data. Introduce the concept of CGI. Web-based Applications University of Alberta 3 University of Alberta 4

Outline of Lecture 6 HTML Forms CGI programming Using HTML Forms A Web HTML page can gather input and send it to a program on the server for processing. The program that receives the input for processing is called a CGI (or Common Gateway Interface). A CGI program has a URL like any Web accessible file. A Form has a link to the corresponding CGI. Form in browser Server CGI University of Alberta 5 University of Alberta 6 HTML Forms Structure <FORM ACTION= URL_CGI METHOD= > </FORM> ACTION specifies the URL of a CGI program or e-mail address (mailto:e-mail@address.there) METHOD specifies how the data is transmitted to the server GET : the data is sent appended to the URL POST : the data is sent after the HTTP header ENCTYPE specifies the way in which the data is encoded You cannot have nested forms. (No forms in forms allowed) University of Alberta 7 Form Input Elements Textfields <INPUT TYPE= TEXT NAME= var1 VALUE= Hello SIZE= 20 > MAXLENGTH would specify the maximum input length Text areas <TEXTAREA NAME= var2 COLS= 20 ROWS= 3 > This is a text zone </TEXTAREA> WRAP can either be OFF, HARD or SOFT and specifies how the word wrap is done at the end of line Password fields <INPUT TYPE= PASSWORD NAME= var3 > SIZE VALUE MAXLENGTH University of Alberta 8 Hello This is a text zone *****

Form Input Elements Radio buttons (shared names) <INPUT TYPE= RADIO NAME= var4 VALUE= yes CHECKED> <INPUT TYPE= RADIO NAME= var4 VALUE= no > Checkboxes <INPUT TYPE= CHECKLIST name= var5 CHECKED> <INPUT TYPE= CHECKLIST name= var6 > Hidden variables <INPUT TYPE= HIDDEN NAME= var7 VALUE=23> Image maps (server-side) <INPUT TYPE= IMAGE NAME= var8 SRC= image.gif ALIGN= RIGHT > Clicking on the image would submit the form along with two variables: name.x and name.y (in this case var8.x and var8.y) Form Input Elements Combo boxes and List boxes <SELECT NAME= var9 > <OPTION VALUE= A > option 1</OPTION> <OPTION VALUE= B > option 2</OPTION> </SELECT> <SELECT NAME= var10 SIZE= 3 MULTIPLE> <OPTION>Element 1</OPTION> <OPTION SELECTED>Element 2</OPTION> <OPTION>Element 3</OPTION> <OPTION>Element 4</OPTION> </SELECT> option1 Element 1 Element 2 Element 3 University of Alberta 9 University of Alberta 10 Form Input Elements Attached file <INPUT TYPE= FILE NAME= var11 VALUE= myfile.txt > SIZE, MAXLENGTH used as for textfields ACCEPT restricts the files to certain MIME types JavaScript button <INPUT TYPE= BUTTON NAME= var12 VALUE= Your Cart > no submission but can be attached to a JavaScript Submit button <INPUT TYPE= SUBMIT VALUE= Send > submits the form (pairs of variable-value) Reset button <INPUT TYPE= RESET VALUE= Clear all values > Resets all variables in the form to their original values myfile.txt Your Cart Clear all values University of Alberta 11 Send Browse Example of a Form <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>Example of a form</title></head> <BODY BGCOLOR="#00FF00"> <H1> Satisfaction Report</H1> <FORM ACTION ="mailto:me@university.ca" METHOD=POST> Name: <INPUT TYPE=text name="name"><br> <DL><DT>Are you <DD><INPUT TYPE=radio name="satisf" Value="1"> Very Satisfied <DD><INPUT TYPE=radio name="satisf" Value="2"> Satisfied <DD><INPUT TYPE=radio name="satisf" Value="3"> Not Satisfied </DL> <INPUT TYPE=submit> </FORM> </BODY> </HTML> University of Alberta 12

Outline of Lecture 6 Common Gateway Interface HTML Forms CGI programming Form in browser data Server data CGI HTML 1- User enters data in form 2- User presses submit button 3- data sent to web server with URL of CGI 4- Server starts a CGI and passes data 5- CGI processes data and generates HTML page University of Alberta 13 University of Alberta 14 CGI Programming Any programming language that allows reading Standard Input and writing to the Standard Output can be used for CGI programming. Perl is commonly used for CGI, but also C/C ++, Python, Unix shell script, AppleScript, Visual Basic, Java, etc. The CGI Interaction Process There are 4 basic steps in a CGI program: 1. Read the data (input parameters) 2. Process the data 3. Output an HTTP response header 4. Generate a document The CGI should send a blank line to separate the HTTP header from the generated document. Reading the data is different depending upon the method used to send the data (GET, POST) University of Alberta 15 University of Alberta 16

Reading the GET Data With the GET method, data is sent with the CGI URL: myprogram.cgi?var1=abc&var2=123 Data is appended to the URL with? Variable-value pairs are separated by & A Variable and a Value are separated by = When a web server receives a GET with a CGI URL it puts the data in an environment variable QUERY_STRING before calling the CGI program. Java and QUERY_STRING QUERY_STRING= var1=abc&var2=123 Java has no method to directly read environment variables (the concept doesn t exist with all OS). We need to use an intermediary script to pass the variable along to Java Example with Unix shell script #!/bin/sh /usr/local/jdk/bin/java myjavacgi $QUERY_STRING University of Alberta 17 University of Alberta 18 Reading the POST Data No data is attached to the CGI URL The data is sent like a document after an HTTP request header (in a single line). The header would contain information about the data such as Content-Length, etc The data is available to the program as standard input. Pros and Cons of Get and Post Since data is appended to the URL with GET, the size of data is limited by the browser s URL maximum size (truncated). There is no size limit for data sent with POST. We can activate a CGI without using an HTML form if we use GET: http://server/path/cgiprogram.cgi?parameters POST can be used to send private information. University of Alberta 19 University of Alberta 20

CGI Environment Variables In Addition to QUERY_STRING, there are many standard environment variables available to CGI programs: CONTENT_LENGTH SCRIPT_NAME CONTENT_TYPE SERVER_NAME HTTP_COOKIE SERVER_PORT HTTP_REFERER SERVER_PROTOCOL HTTP_USER_AGENT etc. REMOTE_ADDR and REMOTE_HOST REMOTE_USER REQUEST_METHOD University of Alberta 21 #------------------------------------------------------------------------- ####### Getting the input from STDIN or command line #------------------------------------------------------------------------ $my_input = ($ENV{REQUEST_METHOD} eq "POST")? <STDIN> : $ENV{QUERY_STRING}; #------------------------------------------------------------------------ ####### Splitting input by parameter and value #------------------------------------------------------------------------- @my_query_list = split( /&/, $my_input); # Splitting all pairs foreach $item (@my_query_list) { ($my_param, $my_value) = split( /=/, $item); # Splitting variables and values Example of parsing CGI input with Perl $my_value =~ s/\+/ /g; # Change +'s to spaces $my_value =~ s/\s*$//; # eliminate spaces at the end $my_value =~ s/\%0d\%0a/\n/g; $my_value =~ s/%(..)/pack('c',hex($1))/ge; if ($my_in{$my_param}) { $my_in{$my_param}.= ' '; $my_in{$my_param}.= $my_value; } else { $my_in{$my_param} = $my_value; } } $firstname=$my_in{"fname"}; $lastname=$my_in{"lname"}; # accessing parameters University of Alberta 22 Another example accessing parameters in a CGI with Perl #------------------------------------------------------------------------- ####### Accessing parameters using the CGI module # and importing standard functions. #------------------------------------------------------------------------ use CGI qw( :standard ); $dtd = " -//W3C//DTD HTML 4.01 Transitional//EN "; print( header()); Returns: Content-type: text/html\n\n print( start_html({dtd=>$dtd, title => " My page title "})); $firstname=param(" fname"); Deals with tags in the header $lastname=param(" lname "); <HTML><HEAD><TITLE> up to <BODY> No need to build the data structure and do all the parsing University of Alberta 23