Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.

Slides:



Advertisements
Similar presentations
1 Copyright © 2002 Pearson Education, Inc.. 2 Chapter 1 Introduction to Perl and CGI.
Advertisements

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?
Social Web Design 1 Darby Chang Social Web Design.
Molecular Biomedical Informatics Web Programming 1.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Adding Dynamic Content to your Web Site
1 CGICGI Common Gateway Interface Server-side Programming Lecture.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Web Programming 網際網路程式設計 1 Darby Chang 張天豪 Web Programming 網際網路程式設計.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Server-Side vs. Client-Side Scripting Languages
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic Server Side Web Technologies: Part 2.
生物資訊程式語言應用 Part 2 HTML. 2 Principle of Programming Interface with PC English Japanese Chinese Machine Code Compiler / Interpreter C++ Perl Assembler Machine.
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.
Guide To UNIX Using Linux Third Edition
Molecular Biomedical Informatics 分子生醫資訊實驗室 Social Web Design & Research 社群網站設計 & 研究 Social Web Design & Research 1.
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.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Chapter 6: Hostile Code Guide to Computer Network Security.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Social Web Design 社群網站設計 1 Darby Chang 張天豪 Social Web Design 社群網站設計.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Social Web Design & Research 社群網站設計 & 研究 Social Web Design & Research 1.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
UFCEKG-20-2 Data, Schemas & Applications Lecture 4 Server Side Scripting & PHP.
JAVASCRIPT HOW TO PROGRAM -2 DR. JOHN P. ABRAHAM UTPA.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 24 – Web Servers (PWS, IIS, Apache, Jigsaw) Outline 24.1Introduction 24.2Microsoft Personal.
NETWORK CENTRIC COMPUTING (With included EMBEDDED SYSTEMS)
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.
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
Introduction to Programming the WWW I CMSC Summer 2004 Lecture 6.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
CSU - DCE Advanced Perl CGI Operation - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) on the.
20-753: Fundamentals of Web Programming 1 Lecture 1: Introduction Fundamentals of Web Programming Lecture 1: Introduction.
Introduction to Applets CS 3505 Client Side Scripting with applets.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: HTTP and CGI Fundamentals of Web Programming.
10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0.
Website Development with PHP and MySQL Saving Data.
Chapter 9: Perl and CGI Programming CGI Programming Acknowledgement: Some materials are taken from Teach Yourself CGI Programming with PERL 5 in a Week.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) Instructor: Joseph DiVerdi,
Intermediate CGI & CGI.pm Webmaster II - Fort Collins, CO Copyright © XTR Systems, LLC CGI Programming & The CGI.pm Perl Module Instructor: Joseph DiVerdi,
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Scripting Languages Client Side and Server Side. Examples of client side/server side Examples of client-side side include: JavaScript Jquery (uses a JavaScript.
Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
CS 330 Class 8 Homework A pattern that contains a word with an optional period A pattern that contains Fred with a space (not Freddy) See regexp.txt guest4.htm.
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.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
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)
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
CS 330 Class 7 Comments on Exam Programming plan for today:
Programming Basics Web Programming.
What is Perl? PERL--Practical Extraction and Report Language
Web Application Development Using PHP
Presentation transcript:

Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1

CGI 2 Web Programming 網際網路程式設計

Common Gateway Interface (CGI) Common – 通用 Gateway – 閘道 Interface – 介面 Web Programming 網際網路程式設計 3

4

It’s an interface It allows browsers (and thus users) to communicate with web servers –In brief, an interface is a bulk of rules. If you program follows these rules, you can communicate with browsers. A program that fits these rules is called a CGI program. –CGI is over HTTP A CGI program is just a program where the only thing need to know is how its IO related to browsers’ IO Web Programming 網際網路程式設計 5 Browser CGI Program Web Server HTML FormEnvironment Standard OutputHTML

HTML form Passing data to the server side Boy Girl Submit HTML Forms and Input You know HTML, and thus you know the browsers’ IO Web Programming 網際網路程式設計 6

CGI program CGI is not a language. If you follow the rules, you can use any programming language to implement a CGI program. But please don’t try any… –Perl is a widely used language in CGI programming. In addition to Perl, shell script, Python, Ruby, PHP, Tcl, C/C++ and Visual Basic can be used for CGI programming  by 通用網關 介面 - 維基百科,自由的百科全書 通用網關 介面 - 維基百科,自由的百科全書 Web Programming 網際網路程式設計 7

8 Job trends

c, java, javascript, c++, perl perl, php, jquery, python, ruby, objective-c Web Programming 網際網路程式設計 9

CGI IO in Perl # input use CGI; # just like include in C my $cgi = new CGI; # create a CGI object my $nick = $cgi->param('nick'); my $color = $cgi->param('color'); # output print "Content-type: text/html\n\n"; # HTTP header print "Hello World! \n"; # any valid HTML print "$nick likes $color!\n"; # any valid HTML Easy? Let’s see other languages Web Programming 網際網路程式設計 10 Boy Girl

11 Before that, what is Content-type: text/html\n\n Web Programming 網際網路程式設計

HTTP header Not HTML header HTTP is the protocol. HTML is just a format transferring over it. You can use HTTP to transfer other formats, such as plain text file. –just like you can transfer.doc,.pdf,.avi… files over FTP –but HTML is actually plain text, so the problem is how browsers interpret the same file content Chapter 10. HTTP Headers HTTP 流程 與 HTTP Header 入門 HTTP 流程 與 HTTP Header 入門 Web Programming 網際網路程式設計 12

Content-type: text/html\n\n Content-type: text/plain\n\n Web Programming 網際網路程式設計 13

HTTP header fields List of HTTP header fields You can use them to –change the way that browsers parse your response –return binary files (for download) –specify the filename –…–… Except Content-Type, try Content-Disposition Web Programming 網際網路程式設計 14

CGI IO in PHP Hello World! Web Programming 網際網路程式設計 15

CGI IO in Ruby # input require 'cgi' cgi = CGI.new nick = cgi['nick'] color = cgi['color'] # output puts "Content-type: text/html"; puts # HTTP header puts "Hello World! "; # any valid HTML puts "#{nick} likes #{color}!"; # any valid HTML Web Programming 網際網路程式設計 16

CGI IO in JSP Hello World! Web Programming 網際網路程式設計 17

CGI IO in C #include #include int main(void) { // input char * query; char nick[256], color[256]; // dangerous data = getenv('QUERY_STRING'); sscanf(query, "nick=%s&color=%s", &nick, &color); // output printf("Content-type: text/html\n\n"); // HTTP header printf("Hello World! "); // any valid HTML printf("%s likes %s!", nick, color); # any valid HTML return 0; } 永遠的 UNIX > CGI 之 C 語言篇 永遠的 UNIX > CGI 之 C 語言篇 So just don’t use it Web Programming 網際網路程式設計 18

CGI is just an interface Web Programming 網際網路程式設計 19 It’s fundamental but old

Advanced interfaces FastCGI –not execute the CGI programs from scratch every time –FastCGI 中文介紹FastCGI 中文介紹 PSGI –inspired by Python’s WSGI and Ruby’s RackWSGIRack –Perl many interfaces to web servers such as CGI, mod_perl and FastCGI –allows web developers to only write PSGI and choose an appropriate adapter –stop writing code to support many web server environments Web Programming 網際網路程式設計 20

CGI vs. PSGI Servers are the actual web servers written in any languages but mostly in C Servers are Perl processes that are usually embedded in the web server (like mod_perl) or a Perl daemon process called by a web server (like FastCGI), or an entirely Perl-based web server Script can be written in any language such as C, Perl, Shell scripts, Ruby or Python PSGI application is a Perl code reference Use environment variables and STDIN for input Use the $env hash references and the psgi.input stream for input Print for outputReturn an array ref for output Web Programming 網際網路程式設計 21

Test (debug) CGI programs Pass input data via the URL &color=blue Actually, browsers do the same thing while submitting a HTML form Web Programming 網際網路程式設計 22

23

Perl Script language The most advantages are string manipulation and hash The first line must be –#!/usr/bin/perl -w use strict; –be sure to include this line –Perl is an untyped ( 無型態 ) language where variables can be used without declaration, but the harm is larger (bugs) than the convenience Web Programming 網際網路程式設計 24

File IO in Perl open FH, 'res/member' or die; # fopen while ( ) { # each line chomp; # truncate the last "\n" my ( $_name, $_nick ) = split "\t"; $_nick eq $nick and $name = $_name and last; # just like English } close FH; # close the file Web Programming 網際網路程式設計 25

Some tips Set CGI programs to executable –$ chmod 755 do A module that helps debugging –use CGI::Carp "fatalsToBrowser"; Writable file –$ chmod 666 filename # writable to web server –open FH, ">filename" or die; –open FH, ">>filename" or die; Web Programming 網際網路程式設計 26

Script/interpreted languages Interpreted Languages: PHP, Perl, Python, Ruby (Sheet One) Interpreted Languages: PHP, Perl, Python, Ruby (Sheet One) Interpreted Languages: PHP, Perl, Python, Ruby (Sheet Two) Interpreted Languages: PHP, Perl, Python, Ruby (Sheet Two) Web Programming 網際網路程式設計 27

Any Questions? Web Programming 網際網路程式設計 28 about CGI (or Perl)

Today’s assignment 今天的任務 Web Programming 網際網路程式設計 29

Make your web site memorable Implement at least one cross-computer (namely you cannot implement with only JavaScript) interaction with CGI Reference –Perl 學習手札Perl 學習手札 –Perl - 維基百科,自由的百科全書Perl - 維基百科,自由的百科全書 Your web site ( will be checked not before 23:59 10/22 (Tue). You may send a report (such as some important modifications) to me in case I did not notice your features. me Web Programming 網際網路程式設計 30

Appendix 附錄 31 Web Programming 網際網路程式設計

If we have time… I’m sure that we won’t have spare time today :p We won’t have enough time to finish Perl in the whole semester so that I can only teach specific functions But I’m not sure what functions you need, so please think about it and feel free to discuss with me via any media Web Programming 網際網路程式設計 32

The concept of template/ 模板 # use Linux command (written in C) $_ = `/bin/cat _hello.html`; s/{name}/$name/g; # regular expression print "Content-type: text/html\n\n$_"; Call outer programs/commands The magic $_ variable –using it well will largely reduce the code (but less readable for rookies) Web Programming 網際網路程式設計 33 Hello World! {name} likes {color}!