Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Programming the WWW I

Similar presentations


Presentation on theme: "Introduction to Programming the WWW I"— Presentation transcript:

1 Introduction to Programming the WWW I
CMSC Winter 2003 Lecture 14

2 Introduction to Perl What is Perl? How do you run it?
From command line From Web How do you write Web pages with it?

3 Accessing HTML Files Over the Internet

4 Web Application Program
Carries out many dynamic tasks, such as the following: Input a search term, search the WWW, and return the results Calculate and display the number of times that a page has been viewed Verify the input fields on a Web form Save a Web form into a database Display a special graph, or return the results of a calculation based on data input from a form

5 The Common Gateway Interface
a standard that enables Web browsers to exchange data with computer programs located on a Web server first appeared in the NCSA HTTPD Web server software built by the National Center for Super-computing Applications (NCSA). one of the first widely used Web servers was simple and the program source code was made available for free It is simple to use and available on a variety of Web servers.

6 How Browsers and Web Applications Work with CGI

7 An Interface with Different Programming Languages
Web application programs that are developed specifically to work with the CGI standard are known as CGI programs. Lots of different programming languages can be used. For example, Perl, Visual Basic, Java, C, C++, and UNIX shell scripts.

8 The Perl Programming Language
Practical Extension and Reporting Language invented in 1987 by Larry Wall at NASA’s Jet Propulsion Laboratory developed as a utility programming language for the UNIX operating system gained popularity because of its ease of use, free availability via the Internet, and its powerful combination of features

9 Why Perl is Popular Perl is a free language with lots of free applications Perl is easier to work with than many other languages Perl provides a CGI interface module Perl applications are portable.

10 Internet Service Provider Issues
Some things to determine with your ISP Allow CGI programs to execute on its Web-server? Does it have Perl? What Version? Login and initial password on the Web server? Where do you put your Perl programs on the Web server and what permission settings? How much disk space for publishing? Support FTP and/or Telnet access? or SSH/SCP?

11 Summary Web pages written in HTML are static and cannot interact with users. CGI is an interface standard that allows computer programs to communicate with Web servers. Several programming languages can be used with CGI.

12 What You Need to Get Started
SCP/SSH Connecting to the Web server Setting up your directories. Getting the location of the Perl interpreter.

13 Navigating UNIX Directories

14 Navigating UNIX Directories - 2

15 Finding The Location Of Perl
Perl interpreter A program that translates Perl program commands into commands that are understandable to a computer. Runs your Perl programs and generates any output. Its command name is simply perl. It can be installed in any of several places on a Web server.

16 Finding Location Of Perl
SSH onto Web Server enter: which perl where is perl Perl Interpreter Location

17 Starting Your Program Development Process
Each time you develop and run a program: Create a program file and copy (or save) it into the correct directory. Change your program’s access permissions. Check your program’s syntax. Run your program.

18 Create Your Program File
Editors are computer applications that enable you to create, change, and save files Microsoft Windows, Notepad is a simple editor that works well for Perl development. On UNIX systems, the Pico, Vi, and Emacs editors are popular choices.

19 Starting Your First Program
Start Editor and enter the following: #!/usr/local/bin/perl # This program prints out a simple message print “Steady Plodding Brings Prosperity\n”;

20 Program Entered in Pico

21 Run The Program Save the program file on the web server.
Enter the full path to the program file to run. For example: /home/kirby/html/cgi-bin/simple1.cgi Home Directory Directories On Web Server Program File

22 Change the Program’s Permissions On A Unix Web Server
UNIX access permissions are used to define the access rights of your files read permissions define if the file can be read write permissions define if the file can be changed, execute permissions define if the file can be executed as a program You set access permissions for your user ID, your user ID’s group, and everyone else

23 To Check Your Program Syntax (on a UNIX Web Server)
establish an SSH session, navigate to the directory that contains the file, enter perl –c filename, where filename is the program file whose syntax you want to. For example, cd html/cgi-bin perl –c simple1.cgi If no syntax errors then you will seed: simple1.cgi syntax OK

24 Program with Syntax errors
Missing quote mark

25 Running Your Program At least two different ways to run your Perl programs: Directly on a Web server or PC without a browser Using your browser over the Internet.

26 Getting Ready to Run Your Program Over the Internet
1. To use a browser over the Internet, add the following MIME content-type line: print “Content-type: text/html\n\n”;. #!/usr/local/bin/perl print “Content-type: text/html\n\n”; # This program prints out a simple message print “Steady Plodding Brings Prosperity\n”;

27 Change Program Process
1. Edit the program 2. Change the program. 3. Save the file. 4. Check the program’s syntax. 5. Run the program.

28 Running Your Program Over the Internet
1. Connect to the Internet. 2. Start your browser. 3. Enter the URL or Web address to your file 4. Check the program’s syntax. 5. Run the program. For example, assume saved the in a file called simple2.cgi in my cgi-bin directory on the Web server. Can execute by the following:

29 Output Of Program Executed Over the Internet

30 Dealing with Problems Many Web servers redirect the errors from CGI programs into a separate error log located on the server. You may receive a generic, cryptic message when running program’s with errors. Two common messages are Internal Server Error (Figure 2.17) and 500 Server Error.

31 Some Things to Check Verify the program syntax.
Verify the access permission. Verify the file has the proper extension (.pl or .cgi). Verify the program is stored in the correct directory. Verify the correct Web address to your program. Verify the first line has the correct of the Perl interpreter. Confirm the accuracy of your MIME Content-type line.

32 An Internet Server Error

33 Generating HTML Statement from Perl Programs
#!/usr/local/bin/perl print "Content-type: text/html\n\n"; print "<HTML> <HEAD> <TITLE> Example </TITLE></HEAD>"; print "<BODY>"; print "<B><Font Size=5>This is a Test </FONT></B>"; print "A very Interesting test"; print "</BODY></HTML>";

34 Program Output

35 Another approach: #!/usr/local/bin/perl
print "Content-type: text/html\n\n"; print<<END; <HTML> <HEAD> <TITLE>Example</TITLE> </HEAD> <BODY> <B><Font Size=5>This is a Test </FONT></B> A very Interesting test </BODY></HTML> END

36 What is this? Everything between ENDs gets treated as if it were inside a double quote Use this with “require” to print out a page with a fixed header, footer, body Use require “foo.pl”; to execute the code in that file in that spot

37 Summary There are several different configurations you can use to develop CGI/Perl programs. Using FTP and Telent are common Steps to create a program: create with editor, enter program, set permissions, check syntax, and run the program. Two statements are required: First line identifies Perl interpreter location. Second line specifies the MIME Content-type.


Download ppt "Introduction to Programming the WWW I"

Similar presentations


Ads by Google