Skip to content

8. Appendices

8.1. Web Development Tools

Here we indicate where to find and how to install the tools necessary for web development. Some tools have seen their versions evolve, and it is possible that the explanations provided here no longer apply to the most recent versions. The reader will then need to adapt... In the web programming course, we will primarily use the following tools, all available for free:

  • a recent browser capable of displaying XML. The course examples have been tested with Internet Explorer 6.
  • a recent JDK (Java Development Kit). The examples in this course have been tested with JDK 1.4. This JDK includes the Java 1.4 Plug-in for browsers, which allows them to display Java applets using the Java 1.4 platform.
  • a Java development environment for writing Java servlets. Here it is JBuilder 7.
  • Web servers: Apache, PWS (Personal Web Server), Tomcat.
    • Apache will be used for developing web applications in PERL (Practical Extracting and Reporting Language) or PHP (Personal Home Page)
    • PWS will be used for web application development in ASP (Active Server Pages) or PHP
    • Tomcat will be used for developing web applications using Java servlets or JSP (Java Server Pages)
  • a database management application: MySQL
  • EasyPHP: a tool that brings together the Apache web server, the PHP language, and SGBD MySQL

8.1.1. Web Servers, Browsers, Scripting Languages

  • Major Web Servers
    • Apache (Linux, Windows)
    • Internet Information Server IIS (NT), Personal Web Server PWS (Windows 9x)
  • Major Browsers
    • Internet Explorer (Windows)
    • Netscape (Linux, Windows)
  • Server-side scripting languages
    • VBScript (IIS, PWS)
    • JavaScript (IIS, PWS)
    • Perl (Apache, IIS, PWS)
    • PHP (Apache, IIS, PWS)
    • Java (Apache, Tomcat)
    • Languages .NET
  • Browser-side scripting languages
    • VBScript (IE)
    • Javascript (IE, Netscape)
    • PerlScript (IE)
    • Java (IE, Netscape)

8.1.2. Where to find the tools

Netscape
http://www.netscape.com/ (downloads link)
Internet Explorer
http://www.microsoft.com/windows/ie/default.asp
PHP
http://www.php.net
http://www.php.net/downloads.php (Windows Binaries)
PERL
http://www.activestate.com http://www.activestate.com/Products/
http://www.activestate.com/Products/ActivePerl/
VBScript, JavaScript
http://msdn.microsoft.com/scripting (follow the Windows Script link)
JAVA
http://java.sun.com/
http://java.sun.com/downloads.html (JSE)
http://java.sun.com/j2se/1.4/download.html
Apache
http://www.apache.org/
http://www.apache.org/dist/httpd/binaries/win32/
PWS
included in NT 4.0 Option pack for Windows 95
included in the Windows 98 CD
http://www.microsoft.com/ntserver/nts/downloads/recommended/NT4OptPk/win95.asp
IIS 
(windows NT/2000)
http://www.microsoft.com
Tomcat
http://jakarta.apache.org/tomcat/
JBuilder
http://www.borland.com/jbuilder/
http://www.borland.com/products/downloads/download_jbuilder.html
EasyPHP
http://www.easyphp.org/
http://www.easyphp.org/telechargements.php3

8.1.3. EasyPHP

This application is very convenient because it combines the following in a single package:

  • the Apache Web server (1.3.x)
  • the PHP language (4.x)
  • the SGBD MySQL (3.23.x)
  • a MySQL administration tool: PhpMyAdmin

The installation application looks like this:

Image

Installing EasyPHP is straightforward, and a directory structure is created in the file system:

Image

easyphp.exe
the application executable
apache
the Apache server directory structure
mysql
the SGBD directory structure mysql
phpmyadmin
the directory structure of the phpmyadmin application
php
the directory structure of php
www
root of the directory tree for web pages served by the Apache server for EasyPHP
cgi-bin
directory where CGI scripts for the Apache server can be placed

The main advantage of EasyPHP is that the application comes preconfigured. Thus, Apache, PHP, and MySQL are already configured to work together. When you launch EasyPhp via its shortcut in the Programs menu, an icon appears in the bottom-right corner of the screen.

This is the letter E with a red dot, which should flash if the Apache web server and the MySQL database are operational. When you right-click on it, you access the menu options:

Image

The option Administration allows you to configure settings and perform functionality tests:

Image

8.1.3.1. PHP Administration

The php Info button allows you to verify that the Apache-PHP combination is functioning properly: a PHP information page should appear:

Image

The Extensions button displays a list of extensions installed for php. These are actually function libraries.

Image

The screen above shows, for example, that the functions required to use the MySQL database are present.

The Settings button displays the login and password for the administrator of the MySQL database.

Image

Using the MySQL database is beyond the scope of this quick overview, but it is clear here that a password should be set for the database administrator.

8.1.3.2. Apache Administration

Still on the EasyPHP administration page, the "Your Aliases" link allows you to define aliases associated with a directory. This allows you to place web pages outside the www directory in the easyPhp directory tree.

Image

If you enter the following information on the page above:

Image

and click the "Validate" button, the following lines are added to the file <easyphp>\apache\conf\httpd.conf:

    Alias /st/ "e:/data/serge/web/"

    <Directory "e:/data/serge/web">
        Options FollowSymLinks Indexes
        AllowOverride None
        Order deny,allow
        allow from 127.0.0.1
        deny from all
    </Directory>

<easyphp> refers to the installation directory of EasyPHP. httpd.conf is the Apache server configuration file. You can therefore achieve the same result by editing this file directly. Changes to the httpd.conf file are normally applied immediately by Apache. If this is not the case, you will need to stop and restart it, using the easyphp icon:

Image

To finish our example, we can now place web pages in the directory tree e:\data\serge\web:

C:\winnt\system32>dir e:\data\serge\web\html\balises.htm

14/07/2002  17:02                3 767 balises.htm

and request this page using the alias st:

Image

In this example, the Apache server has been configured to run on port 81. Its default port is 80. This is controlled by the following line in the httpd.conf file we encountered earlier:

Port 81

8.1.3.3. The Apache configuration file htpd.conf

When you want to fine-tune Apache, you have to manually edit its configuration file httpd.conf, located here in the <easyphp>\apache\conf folder:

Image

Here are a few key points to note in this configuration file:

ligne(s)
role
ServerRoot "D:/Program Files/Apache Group/Apache"
specifies the folder containing the Apache directory structure
Port 80
specifies which port the web server will use. Typically, this is 80. By changing this line, you can have the web server run on a different port
ServerAdmin root@istia.univ-angers.fr
the email address of the Apache server administrator
ServerName stahe.istia.uang
the name of the machine on which the Apache server is running
ServerRoot "E:/Program Files/EasyPHP/apache"
the installation directory of the Apache server. When relative file names appear in the configuration file, they are relative to this directory.
DocumentRoot "E:/Program Files/EasyPHP/www"
the root directory of the tree of web pages served by the server. Here, url http://machine/rep1/fic1.html will correspond to the file E:\Program Files\EasyPHP\www\rep1\fic1.html
<Directory "E:/Program Files/EasyPHP/www">
sets the properties of the previous folder
ErrorLog logs/error.log
logs folder, so actually <ServerRoot>\logs\error.log: E:\Program Files\EasyPHP\apache\logs\error.log. This is the file to check if you find that the Apache server is not working.
    ScriptAlias /cgi-bin/ "E:/Program Files/EasyPHP/cgi-bin/"
E:\Program Files\EasyPHP\cgi-bin will be the root of the directory tree where you can place CGI scripts. Thus, the URL http://machine/cgi-bin/rep1/script1.pl will be the url for the script CGI E:\Program Files\EasyPHP\cgi-bin \rep1\script1.pl.
<Directory "E:/Program Files/EasyPHP/cgi-bin/">
sets the properties of the above folder
LoadModule php4_module "E:/Program Files/EasyPHP/php/php4apache.dll"
AddModule mod_php4.c
module loading lines allowing Apache to work with PHP4.
    AddType application/x-httpd-php .phtml .pwml .php3 .php4 .php .php2 .inc
Sets the file extensions to be treated as files to be processed by PHP

8.1.3.4. Administering MySQL with PhpMyAdmin

On the EasyPhp administration page, click the PhpMyAdmin button:

Image

The drop-down list under Home allows you to view the current databases.
The number in parentheses is the number of tables. If you select a database, its tables are displayed:

The web page offers a number of operations on the database:

Image

If you click the View user link:

Image

There is only one user here: root, who is the administrator of MySQL. By following the Edit link, you could change their password, which is currently blank—a practice not recommended for an administrator.

We won’t say any more about PhpMyAdmin, which is a feature-rich software that would merit a discussion spanning several pages.

8.1.4. PHP

We've seen how to obtain PHP using the EasyPhp application. To obtain PHP directly, go to the website http://www.php.net.

PHP is not limited to web use. It can be used as a scripting language in Windows. Create the following script and save it as date.php:

<?
   // script php displaying the time
  $maintenant=date("j/m/y, H:i:s",time());
  echo "Nous sommes le $maintenant";
?>

In a DOS window, navigate to the date.php directory and run it:

E:\data\serge\php\essais>"e:\program files\easyphp\php\php.exe" date.php
X-Powered-By: PHP/4.2.0
Content-type: text/html

Nous sommes le 18/07/02, 09:31:01

8.1.5. PERL

It is best if Internet Explorer is already installed. If it is present, Active Perl will configure it to accept PERL scripts in HTML pages, scripts that will be executed by IE itself on the client side. The Active Perl website is at URL http://www.activestate.comA. Upon installation, PERL will be installed in a directory we will call <perl>. It contains the following directory structure:

DEISL1   ISU        32 403  23/06/00  17:16 DeIsL1.isu
BIN            <REP>        23/06/00  17:15 bin
LIB            <REP>        23/06/00  17:15 lib
HTML           <REP>        23/06/00  17:15 html
EG             <REP>        23/06/00  17:15 eg
SITE           <REP>        23/06/00  17:15 site
HTMLHELP       <REP>        28/06/00  18:37 htmlhelp

The executable perl.exe is located in <perl>\bin. Perl is a scripting language that runs on Windows and Unix. It is also used in WEB programming. Let’s write our first script:

# script PERL displaying the time

# modules
use strict;

# program
my ($secondes,$minutes,$heure)=localtime(time);
print "Il est $heure:$minutes:$secondes\n";

Save this script to a file named heure.pl. Open a DOS window, navigate to the directory containing the previous script, and run it:


E:\data\serge\Perl\Essais>e:\perl\bin\perl.exe heure.pl
Il est 9:34:21

8.1.6. Vbscript, Javascript, Perlscript

These are scripting languages for Windows. They can run in various environments such as

  • Windows Scripting Host for direct use in Windows, particularly for writing system administration scripts
  • Internet Explorer. It is then used within HTML pages, to which it brings a certain level of interactivity that cannot be achieved with HTML alone.
  • Internet Information Server (IIS), Microsoft’s web server on NT/2000, and its equivalent, Personal Web Server (PWS), on Win9x. In this case, vbscript is used for server-side web programming, a technology called ASP (Active Server Pages) by Microsoft.

Download the installation file from URL: http://msdn.microsoft.com/scripting and follow the Windows Script links. The following are installed:

  • the Windows Scripting Host container, which allows the use of various scripting languages, such as Vbscript and Javascript, as well as others like PerlScript, which comes with Active Perl.
  • an interpreter VBscript
  • an interpreter Javascript

Let’s run a few quick tests. Let’s build the following vbscript program:

' a class
class personne
  Dim nom
  Dim age
End class

' creation of a person object
Set p1=new personne
With p1
  .nom="dupont"
  .age=18
End With

' display properties person p1
With p1
  wscript.echo "nom=" & .nom
  wscript.echo "age=" & .age
End With

This program uses objects. Let's call it objets.vbs (the .vbs extension indicates a vbscript file). Navigate to the directory where it is located and run it:

E:\data\serge\windowsScripting\vbscript\poly\objets>cscript objets.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

nom=dupont
age=18

Now let's build the following javascript program that uses arrays:

// painting in a variant
// empty table
tableau=new Array();
affiche(tableau);
// table grows dynamically
for(i=0;i<3;i++){
  tableau.push(i*10);
}
// display panel
affiche(tableau);
// still
for(i=3;i<6;i++){
  tableau.push(i*10);
}
affiche(tableau);

// multi-dimensional tables
WScript.echo("-----------------------------");

tableau2=new Array();
for(i=0;i<3;i++){
  tableau2.push(new Array());
  for(j=0;j<4;j++){
    tableau2[i].push(i*10+j);
  }//for j
}// for i
affiche2(tableau2);

// end
WScript.quit(0);

// ---------------------------------------------------------
function affiche(tableau){
  // display panel
  for(i=0;i<tableau.length;i++){
    WScript.echo("tableau[" + i + "]=" + tableau[i]);
  }//for
}//function

// ---------------------------------------------------------
function affiche2(tableau){
  // display panel
  for(i=0;i<tableau.length;i++){
    for(j=0;j<tableau[i].length;j++){
      WScript.echo("tableau[" + i + "," + j + "]=" + tableau[i][j]);
    }// for j
  }//for i
}//function

This program uses arrays. Let’s call it arrays.js (the suffix js refers to a file named javascript). Navigate to the directory where it is located and run it:

E:\data\serge\windowsScripting\javascript\poly\tableaux>cscript tableaux.js
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. Tous droits réservés.

tableau[0]=0
tableau[1]=10
tableau[2]=20
tableau[0]=0
tableau[1]=10
tableau[2]=20
tableau[3]=30
tableau[4]=40
tableau[5]=50
-----------------------------
tableau[0,0]=0
tableau[0,1]=1
tableau[0,2]=2
tableau[0,3]=3
tableau[1,0]=10
tableau[1,1]=11
tableau[1,2]=12
tableau[1,3]=13
tableau[2,0]=20
tableau[2,1]=21
tableau[2,2]=22
tableau[2,3]=23

One last example in PerlScript to finish up. You must have Active Perl installed to access PerlScript.

<job id="PERL1">
  <script language="PerlScript">
       # classic Perl
    %dico=("maurice"=>"juliette","philippe"=>"marianne");
    @cles= keys %dico;
    for ($i=0;$i<=$#cles;$i++){
        $cle=$cles[$i];
      $valeur=$dico{$cle};
        $WScript->echo ("clé=".$cle.", valeur=".$valeur);
    }
     # perlscript using Windows Script objects
    $dico=$WScript->CreateObject("Scripting.Dictionary");
    $dico->add("maurice","juliette");
    $dico->add("philippe","marianne");
    $WScript->echo($dico->item("maurice"));
    $WScript->echo($dico->item("philippe"));    
  </script>
</job>

This program demonstrates the creation and use of two dictionaries: one in the classic Perl style, the other using the Windows Script Scripting Dictionary object. Let’s save this code to the file dico.wsf (wsf is the file extension for Windows Script files). Navigate to the program’s folder and run it:

E:\data\serge\windowsScripting\perlscript\essais>cscript dico.wsf
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. Tous droits réservés.

clé=philippe, valeur=marianne
clé=maurice, valeur=juliette
juliette
marianne

Perlscript can use objects from the container in which it runs. Here, these were objects from the Windows Script container. In the context of web programming, the scripts VBscript, Javascript, Perlscript can be executed either within the IE browser or within a PWS or IIS server. If the script is somewhat complex, it may be wise to test it outside the web context, within the Windows Script container as discussed previously. This will only allow testing of script functions that do not use browser- or server-specific objects. Even with this limitation, this option remains useful because it is generally quite impractical to debug scripts running within web servers or browsers.

8.1.7. JAVA

Java is available at URL: http://www.sun.com (see the beginning of this document) and is installed in a directory structure called <java> that contains the following elements:

22/05/2002  05:51       <DIR>          .
22/05/2002  05:51       <DIR>          ..
22/05/2002  05:51       <DIR>          bin
22/05/2002  05:51       <DIR>          jre
07/02/2002  12:52                8 277 README.txt
07/02/2002  12:52               13 853 LICENSE
07/02/2002  12:52                4 516 COPYRIGHT
07/02/2002  12:52               15 290 readme.html
22/05/2002  05:51       <DIR>          lib
22/05/2002  05:51       <DIR>          include
22/05/2002  05:51       <DIR>          demo
07/02/2002  12:52           10 377 848 src.zip
11/02/2002  12:55       <DIR>          docs

In the bin directory, you will find javac.exe, the Java compiler, and java.exe, the Java Virtual Machine. You can perform the following tests:

  1. Write the following script:
//java program displaying the time

import java.io.*;
import java.util.*;

public class heure{
  public static void main(String arg[]){
     // retrieve date & time
     Date maintenant=new Date();
      // we display
     System.out.println("Il est "+maintenant.getHours()+
        ":"+maintenant.getMinutes()+":"+maintenant.getSeconds());
  }//hand
}//class
  1. Save this program as heure.java. Open a window named DOS. Navigate to the directory containing the file heure.java and compile it:
D:\data\java\essais>c:\jdk1.3\bin\javac heure.java
Note: heure.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.

In the command above, c:\jdk1.3\bin\javac must be replaced with the exact path to the javac.exe compiler. In the same directory as heure.java, you should find a file named heure.class, which is the program that will now be executed by the java.exe virtual machine.

  1. Run the program:
D:\data\java\essais>c:\jdk1.3\bin\java heure
Il est 10:44:2

8.1.8. Apache Server

We have seen that the Apache server can be obtained with the EasyPhp application. To get it directly, go to the Apache website: http://www.apache.org. The installation creates a directory structure containing all the files necessary for the server. Let’s call this directory <apache>. It contains a directory structure similar to the following:

UNINST   ISU       118 805  23/06/00  17:09 Uninst.isu
HTDOCS         <REP>        23/06/00  17:09 htdocs
APACHE~1 DLL       299 008  25/02/00  21:11 ApacheCore.dll
ANNOUN~1             3 000  23/02/00  16:51 Announcement
ABOUT_~1            13 197  31/03/99  18:42 ABOUT_APACHE
APACHE   EXE        20 480  25/02/00  21:04 Apache.exe
KEYS                36 437  20/08/99  11:57 KEYS
LICENSE              2 907  01/01/99  13:04 LICENSE
MAKEFI~1 TMP        27 370  11/01/00  13:47 Makefile.tmpl
README               2 109  01/04/98   6:59 README
README   NT          3 223  19/03/99   9:55 README.NT
WARNIN~1 TXT           339  21/09/98  13:09 WARNING-NT.TXT
BIN            <REP>        23/06/00  17:09 bin
MODULES        <REP>        23/06/00  17:09 modules
ICONS          <REP>        23/06/00  17:09 icons
LOGS           <REP>        23/06/00  17:09 logs
CONF           <REP>        23/06/00  17:09 conf
CGI-BIN        <REP>        23/06/00  17:09 cgi-bin
PROXY          <REP>        23/06/00  17:09 proxy
INSTALL  LOG         3 779  23/06/00  17:09 install.log
conf
directory containing Apache configuration files
logs
Apache log files directory (monitoring)
bin
Apache executables

8.1.8.1. Configuration

In the <Apache>\conf folder, you will find the following files: httpd.conf, srm.conf, access.conf. In the latest versions of Apache, these three files have been combined into httpd.conf. We have already covered the key points of this configuration file. In the following examples, the Apache instance version (derived from EasyPhp) was used for testing, and thus its configuration file. In this file, DocumentRoot, which designates the root of the web page directory tree, is e:\program files\easyphp\www.

To test, create the file intro.php with the following single line:

<? phpinfo() ?>

and place it in the root directory of the Apache server (DocumentRoot above). Request the URL URL://localhost/intro.php. You should see a list of information:

Image

The following script displays the time. We have already encountered it:

<?
   // time: number of milliseconds since 01/01/1970
   // "date-time display format
   // d: 2-digit day
   // m: 2-digit month
   // y: 2-digit year
   // H: hour 0.23
   // i : minutes
   // s: seconds
  print "Nous sommes le " . date("d/m/y H:i:s",time());
?>

Place this text file in the root directory of the Apache server (DocumentRoot) and name it date.php. Using a browser, request URL http://localhost/date.php. The following page is displayed:

Image

This is set up using a line of the form: ScriptAlias /cgi-bin/ "E:/Program Files/EasyPHP/cgi-bin/" in the file <apache>\conf\httpd.conf. Its syntax is ScriptAlias /cgi-bin/ "<cgi-bin>" where <cgi-bin> is the folder where CGI scripts can be placed. CGI (Common Gateway Interface) is a standard for communication between the WEB server and applications. A client requests a dynamic page from the web server, c.a.d—a page generated by a program. The server must therefore instruct a program to generate the page. CGI defines the communication between the server and the program, including how information is transmitted between these two entities.

If necessary, modify the line ScriptAlias /cgi-bin/ "<cgi-bin>" and restart the Apache server. Then perform the following test:

  1. Write the script:
#!c:\perl\bin\perl.exe

# script PERL displaying the time

# modules
use strict;

# program
my ($secondes,$minutes,$heure)=localtime(time);
print <<FINHTML
Content-Type: text/html

<html>
 <head>
  <title>heure</title>
 </head>
 <body>
  <h1>Il est $heure:$minutes:$secondes</h1>
 </body>
FINHTML
;
  1. Place this script in <cgi-bin>\heure.pl, where <cgi-bin> is the folder that can contain CGI scripts (see httpd.conf). The first line #!c:\perl\bin\perl.exe specifies the path to the perl.exe executable. Modify it if necessary.
  2. Start Apache if you haven't already
  3. Use a browser to request URL http://localhost/cgi-bin/heure.pl. The following page is displayed:

Image

8.1.9. The PWS server

8.1.9.1. Installation

The PWS server (Personal Web Server) is a personal version of Microsoft's IIS server (Internet Information Server). The latter is available on Windows 9x and 2000 machines. On Win9x machines, PWS is normally available with the Internet Explorer installation package. However, it is not installed by default. You must perform a custom installation of IE and request the installation of PWS. It is also available in the NT 4.0 Option pack for Windows 95.

8.1.9.2. Initial Tests

The root directory for web pages on the PWS server is drive:\inetpub\wwwroot, where drive is the disk on which you installed PWS. We will assume hereinafter that this drive is D. Thus, url http://machine/rep1/page1.html corresponds to the file d:\inetpub\wwwroot\rep1\page1.html. The PWS server interprets any file with the .asp (Active Server Pages) extension as a script that it must execute to generate a HTML page.

PWS runs on port 80 by default. The Apache web server does too... You must therefore stop Apache to work with PWS if you have both servers. The other solution is to configure Apache to run on a different port. So, in the Apache configuration file httpd.conf, replace the line "Port 80" with "Port 81"; Apache will now run on port 81 and can be used at the same time as PWS. If PWS has been launched and you request URL http://localhost, you will see a page similar to the following:

Image

  1. Below is a .reg file for modifying the registry. Double-click this file to modify the registry. Here, the required DLL is located in d:\php4 along with the php executable. Modify as needed. The \ characters must be doubled in the DLL path.
REGEDIT4

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w3svc\parameters\Script Map]
".php"="d:\\php4\\php4isapi.dll"
  1. Restart the machine so that the registry change takes effect.
  1. Create a folder named php in d:\inetpub\wwwroot, which is the root directory of the PWS server. Once this is done, enable PWS and go to the "Advanced" tab. Select the "Add" button to create a virtual directory:

Directory/Browse: d:\inetpub\wwwroot\php

Alias: php

Check the "Run" box.

  1. Confirm the settings and restart PWS. Place the file intro.php, containing only the following line, in d:\inetpub\wwwroot\php:

<? phpinfo() ?>

  1. Request the file intro.php from the server at PWS via URL http://localhost/php/intro.php. You should see the list of information already displayed with Apache.

8.1.10. Tomcat: Java servlets and JSP pages (Java Server Pages)

Tomcat is a web server that allows you to generate HTML pages using servlets (Java programs executed by the web server) or JSP pages (Java Server Pages), which combine Java code and HTML code. This is the equivalent of ASP (Active Server Pages) on Microsoft’s IIS/PWS server, where VBScript or Javascript code is mixed with HTML code.

8.1.10.1. Installation

Tomcat is available at URL: http://jakarta.apache.org. Download the .exe installation file. When you run this program, it first prompts you to select which JDK to use. This is because Tomcat requires a JDK to install itself and then to compile and run Java servlets. You must therefore have a Java JDK installed before installing Tomcat. The most recent JD is recommended. The installation will create a <tomcat> directory structure:

Image

simply involves extracting this archive into a directory. Choose a directory whose path contains only names without spaces (not, for example, "Program Files"), because there is a bug in the Tomcat installation process. For example, use C:\tomcat or D:\tomcat. Let’s call this directory <tomcat>. Inside it, you will find a folder named jakarta-tomcat, which contains the following directory structure:

LOGS           <REP>        15/11/00   9:04 logs
LICENSE              2 876  18/04/00  15:56 LICENSE
CONF           <REP>        15/11/00   8:53 conf
DOC            <REP>        15/11/00   8:53 doc
LIB            <REP>        15/11/00   8:53 lib
SRC            <REP>        15/11/00   8:53 src
WEBAPPS        <REP>        15/11/00   8:53 webapps
BIN            <REP>        15/11/00   8:53 bin
WORK           <REP>        15/11/00   9:04 work

8.1.10.2. Starting/Stopping the Tomcat Web Server

Tomcat is a web server, just like Apache or PWS. To launch it, use the links in the Programs menu:

Start Tomcat
to start Tomcat
Stop Tomcat
to stop it

When you start Tomcat, a DOS window appears with the following content:

Image

You can minimize this DOS window. It will remain open as long as Tomcat is running. You can then proceed to the initial tests. The Tomcat web server runs on port 8080. Once Tomcat is running, open a web browser and navigate to URL http://localhost:8080. You should see the following page:

Image

Follow the Servlet Examples link:

Image

Click the Execute link for RequestParameters, then the Source link. You will get a first glimpse of what a Java servlet is. You can do the same with the links on the JSP pages.

To stop Tomcat, use the Stop Tomcat link in the Programs menu.

8.1.11. JBuilder

JBuilder is a Java application development environment. To build Java servlets that do not have graphical interfaces, such an environment is not essential. A text editor and a JDK will suffice. However, JBuilder offers a few advantages over the previous method:

  • ease of debugging: the compiler flags erroneous lines in a program, and it is easy to navigate to them
  • code suggestions: when using a Java object, JBuilder displays a list of its properties and methods inline. This is very handy, given that most Java objects have a large number of properties and methods that are difficult to remember.

JBuilder can be found at http://www.borland.com/jbuilder. You must fill out a form to obtain the software. An activation key is sent via email. To install JBuilder 7, for example, the following steps were taken:

  • Three ZIP files were downloaded: one for the application, one for the documentation, and one for the examples. Each of these ZIP files has a separate link on the JBuilder website.
  • First, the application was installed, then the documentation, and finally the examples
  • When you launch the application for the first time, an activation key is requested: this is the one that was sent to you by email. In version 7, this key is actually an entire text file that can be placed, for example, in the JB7 installation folder. When the key is requested, you then select that file. Once this is done, the key will not be requested again.

There are a few useful configurations to set up if you want to use JBuilder to build Java servlets. In fact, version—known as the personal JBuilder—is a stripped-down version of version that does not include all the classes needed for Java web development. You can configure JBuilder to use the class libraries provided by Tomcat. Here’s how:

  • Launch JBuilder

Image

  • Go to Tools/Configure

Image

In the JDK Settings section above, the Name field normally displays JDK 1.3.1. If you have a newer version of JDK, use the Change button to specify its installation directory. Above, we have specified the directory E:\Program Files\jdk14 where a JDK 1.4 was installed. From now on, JBuilder will use this JDK for its compilations and executions. In the (Class, Source, Documentation) section, you’ll find a list of all the class libraries that will be explored by JBuilder—in this case, the classes from JDK 1.4. The classes in this version are not sufficient for Java web development. To add other class libraries, use the Add button and select the additional .jar files you want to use. The .jar files are class libraries. Tomcat 4.x includes all the class libraries necessary for web development. They are located in <tomcat>\common\lib, where <tomcat> is the Tomcat installation directory:

Image

Using the Add button, we will add these libraries, one by one, to the list of libraries scanned by JBuilder:

Image

From now on, you can compile Java programs compliant with the J2EE standard, including Java servlets. JBuilder is used only for compilation; execution is subsequently handled by Tomcat according to the procedures explained in the course.