Tuesday, October 13, 2009

Web Notes 1: Way to Setup CGI Environment

Recently, I have written javascript to paste data from excel sheet into input elements of web form. The javascript function invoked on "onpaste" event is successful implemented on IE but the integration of javascript into cgi script fails due to my empty knowledge about cgi. Thus, i decided to setup cgi environment in company's computer.

Wah, it's really a hard time to search and understand the pieces of relevant information. I have spent whole morning and finally success. The following are the main steps to setup CGI environment in Window XP with Apache Tomcat server. The IIS may also be used as the server.

  1. Install Perl: I obtained the installer from "http://www.activestate.com/activeperl/"

  2. Install Apache Tomcat Server: I obtained the installer from "http://tomcat.apache.org/download-60.cgi"

  3. Uncomment cgi portion in "conf/web.xml" at Apache root folder

  4. Insert "privileged="true"" in context element of respective xml file of the web applications

  5. By default in "web.xml", the cgi scripts should be placed in "WEB-INF/cgi". The following is the sample cgi script for testing:

    #!perlroot/bin/perl.exe
    print "Content-type: text/html\n\n" ;
    print <<HTML ;
    <html>
    <head><title>CGI Results</title></head>
    <body>
    <h1>Hello, world.</h1>
    </body>
    </html>
    HTML


  6. By default, the cgi scripts can be accessed under "cgi-bin" at the root of web application


You can refer to http://tomcat.apache.org/tomcat-6.0-doc/cgi-howto.html for more details to setup cgi environment in Apache Tomcat 6.0. The debug information can be found in "logs" folder at Apache root folder.

No comments:

Post a Comment