Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Server Programming: CGI(Perl/Python)

Similar presentations


Presentation on theme: "Web Server Programming: CGI(Perl/Python)"— Presentation transcript:

1 Web Server Programming: CGI(Perl/Python)
Slide # 07 Web Server Programming: CGI(Perl/Python) E-business (constructed by Dr. Hanh Pham)

2 E-business (constructed by Dr. Hanh Pham)
Outline Server Programming Mechanisms Servlets CGI CGI with Python CGI with Perl CGI for Shopping Cart E-business (constructed by Dr. Hanh Pham)

3 Overview of Tools for Web Programming
E-business (constructed by Dr. Hanh Pham)

4 Mechanisms for Web Server Programming
Single-tenant: CGI (with Perl, PHP, Ruby, WebDNA, ASP, ColdFusion, … ) Multiple-tenant (shared virtual machine): Servlets (Java program, more for processing data, outputs HTML) JSP (HTML-like syntax and compiled into Servlet, more for presenting data) ASP.NET E-business (constructed by Dr. Hanh Pham)

5 E-business (constructed by Dr. Hanh Pham)
Java Servlets Servlet = a Java program which implement applications at a web server. Functions/Purpose: Process and store data (submitted from an HTML form) Provide dynamic content (results of a database query) Manage state information (exp: adding items to the shopping cart of the appropriate customer) Mechanism (How ?): When a request is made (via a JSP) a servlet is generated and deployed/ran within a web/servlet container. The web container is responsible for managing the lifecycle of servlets, mapping a URL to a particular servlet and ensuring that the URL requester has the correct access rights. The servlet/object receives a request and generates a response based on that request. Servlets typically embed HTML inside Java code and generate HTML (to send to the browser). E-business (constructed by Dr. Hanh Pham)

6 Java Servlets in Details
E-business (constructed by Dr. Hanh Pham)

7 Java Servlets with JSP & JavaBeans
E-business (constructed by Dr. Hanh Pham)

8 E-business (constructed by Dr. Hanh Pham)
CGI Common Gateway Interface (CGI) is a method for generating dynamic contents of web pages. CGI programs/scripts are programs(applications) which resides and run at the server site, they: get inputs from web browser (via forms) and produces output/response (HTML code) at the server site. Then, the HTML output will be sent automatically back to the web browser, run there and display the results to users. E-business (constructed by Dr. Hanh Pham)

9 E-business (constructed by Dr. Hanh Pham)
CGI E-business (constructed by Dr. Hanh Pham)

10 E-business (constructed by Dr. Hanh Pham)
CGI So, what it takes to build and make a CGI program works ? You will need more than just one program. HTML code to display the FORM to the users (to input INFO) CGI program which will produce another HTML code (to display results) E-business (constructed by Dr. Hanh Pham)

11 E-business (constructed by Dr. Hanh Pham)
CGI Although, it is only TWO programs but since the CGI program must produce another HTML code/output, you will need to define that HTML output (which is a program) first. So, at the end it is actually THREE programs: HTML code to display the FORM to the users (to input INFO) HTML output (to display RESULTS) CGI program which processes the INFO from the FORM (via EV) and produce the HTML output above. EV are environment variables. They are GLOBAL variables which can be shared by all programs. In CGI mechanism, EVs are shared between the Web Server program and the CGI program so that the Web Server program can pass the INFO (it received from the FORM) to the CGI program. E-business (constructed by Dr. Hanh Pham)

12 E-business (constructed by Dr. Hanh Pham)
CGI EXAMPLE 1: let’s make a simple CGI program in Python which gets first name (exp: “John”) and last name ( “Smith”) from a FORM and reply with “Hello John Smith” in the browser window. E-business (constructed by Dr. Hanh Pham)

13 E-business (constructed by Dr. Hanh Pham)
CGI Mechanism E-business (constructed by Dr. Hanh Pham)

14 E-business (constructed by Dr. Hanh Pham)
CGI  CREATE a FORM and its CGI program for displaying back INFO entered in the FORM (EXAMPLE 1) SET-UP the a working folder for the FORM and CGI programs: Login to your CS account using Putty Go inside the WEB folder (cd WWW) Go inside your course folder (cd eb) Go inside your working folder (cd w) Create a folder called cgi(mkdir cgi-example1) Go inside that folder (cd cgi-example1) E-business (constructed by Dr. Hanh Pham)

15 E-business (constructed by Dr. Hanh Pham)
CGI Use a text editor program (jpico, emacs, vi, joe, …) to CREATE FILES inside cgi: a file named “p1.htm” which contains a HTML code to display the FORM to the users (to input INFO), with the contents showed below. a file named “p1x.htm” which contains HTML output (to display RESULTS), with the contents showed below. This file is only temporary use and can be deleted later. a file named “p1py.cgi” which contains a CGI program which processes the INFO from the FORM (via EV) and produce the HTML output above, with the contents showed below. E-business (constructed by Dr. Hanh Pham)

16 E-business (constructed by Dr. Hanh Pham)
CGI E-business (constructed by Dr. Hanh Pham)

17 E-business (constructed by Dr. Hanh Pham)
CGI/Python E-business (constructed by Dr. Hanh Pham)

18 E-business (constructed by Dr. Hanh Pham)
CGI After “p1py.cgi” is built based on the HTML code in “p1x.htm” you can delete the “p1x.htm” file. So, you will need just two files in the db3-1 folder: file “p1.htm” which contains a HTML code to display the FORM to the users (to input INFO) file “p1py.cgi” which contains a CGI program which processes the INFO from the FORM (via EV) and produce the HTML output above. Set the permission for both files as 755 (chmod 755 *). To TEST if they work correctly: open a web browser and type the following address: cs.newpaltz.edu/~UserName/eb/w/cgi-example1/p1.htm E-business (constructed by Dr. Hanh Pham)

19 E-business (constructed by Dr. Hanh Pham)
CGI/Perl Example See an example of CGI using Perl for the server program: E-business (constructed by Dr. Hanh Pham)

20 CGI/PERL for Shopping Cart
Example, Demo, and Download: MUST set it up and run at your account at: E-business (constructed by Dr. Hanh Pham)

21 E-business (constructed by Dr. Hanh Pham)
References Most of materials in this slide come from: searchcio.techtarget.com tutorialspoint.com Wikipedia "Developing Distributed and E-commerce Applications", Darrel Ince, 2nd Edition, Pearson Addison Wesley “Web Programming and Internet Technologies: An E-commerce Approach”, Porter Scobey, Pawan Lingras, Jones & Bartlett Publishers, 2013 “Electronic Commerce”, 11th Edition, Cengage Learning, Gary Schneider, 2015 Internet & World Wide Web How to Program, 5/e, Paul J. Deitel, Harvey M. Deitel, Abbey Deitel E-business (constructed by Dr. Hanh Pham)


Download ppt "Web Server Programming: CGI(Perl/Python)"

Similar presentations


Ads by Google