Hello,

I am running Manjaro Linux  (0.8.7) using the linux 3.4.69 kernel on a Dell
XPS m1330 laptop. I am trying to run a sample webpage that uses perl and
cgi to handle a form.
These are the steps I took:

 * wget
http://mirrors.sonic.net/apache/tomcat/tomcat-8/v8.0.0-RC5/bin/apache-tomcat-8.0.0-RC5.tar.gz
* tar xvzf apache-tomcat-8.0.0-RC5.tar.gz
* mkdir ~/tomcat
* sudo mv apache-tomcat-8.0.0-RC5 ~/tomcat
* sudo vi ~/.bashrc
* append export JAVA_HOME=/usr/lib/jvm/java-7-openjdk
* append export CATALINA_HOME=~/tomcat/apache-tomcat-8.0.0-RC5
* run $CATALINA_HOME/bin/startup.sh

I was able to pull up the tomcat control panel, I then edited the web.xml
file. I uncommented the cgi servlet block as well as the cgi-servlet
mapping block. I also changed path prefix:
<init-param>
          <param-name>cgiPathPrefix</param-name>
          <param-value>WEB-INF/cgi-bin/*</param-value>
        </init-param>
         <load-on-startup>5</load-on-startup>
    </servlet>

as well as created a user and password in the tomcat-users.xml, so i could
use the manager GUI.

I  proceeded to create a directory (web) in my home folder
and created a sub-directory (cgi-bin). I have 3 files that make up the web
page.
the html file is as follows:
  GNU nano 2.2.6                          File: ProjectAnalysis.html


<!- Program Name: projest.html ->

<HTML><HEAD><TITLE>Project Analysis</TITLE></HEAD>
<BODY>

<H2>Average Profit per Project Calculation</H2>
<FORM METHOD=POST
ACTION="
http://localhost/home/luis/tomcat/apache-tomcat-8.0.0-RC5/web/cgi-bin/projest.cgi
">
Total cost of projects last year? <INPUT TYPE=text NAME=projcost SIZE=10>
Number of Projects? <INPUT TYPE=text NAME=projects SIZE=10>
Project revenue received? <INPUT TYPE=text NAME=revenue SIZE=10>
<HR><INPUT TYPE=submit NAME=submit VALUE=Submit>
<INPUT TYPE=reset NAME=reset VALUE="Start over">
</FORM>
</BODY>
</HTML>

 the .cgi file is as follows:
#!/usr/bin/perl

# Program name: projest.cgi

require "subparseform.lib";

&Parse_Form;
$projcost = $formdata{'projcost'};
$projects = $formdata{'projects'};
$revenue = $formdata{'revenue'};

$average = $projcost / $projects;
$average = sprintf("%.2f", $average);
$grossprofit = $revenue - $projcost;

print "Content-type: text/html\n\n";
print "<P>Project Cost Last Year was $projcost dollars.";
print "<P>We completed $projects projects during the year.
That works out to an average of $average cost per project.";
print "<P>Our annual Project Revenue was $revenue dollars.
We made a gross profit of $grossprofit dollars";

the subparse.lib file:
  GNU nano 2.2.6                           File: subparseform.lib


sub Parse_Form {
        if ($ENV{'REQUEST_METHOD'} eq 'GET') {
                @pairs = split(/&/, $ENV{'QUERY_STRING'});
        } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
                read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
                @pairs = split(/&/, $buffer);

                if ($ENV{'QUERY_STRING'}) {
                        @getpairs =split(/&/, $ENV{'QUERY_STRING'});
                        push(@pairs,@getpairs);
                        }
        } else {
                print "Content-type: text/html\n\n";
                print "<P>Use Post or Get";
        }

        foreach $pair (@pairs) {
                ($key, $value) = split (/=/, $pair);
                $key =~ tr/+/ /;
                $key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
                $value =~ tr/+/ /;
                $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

                $value =~s/<!--(.|\n)*-->//g;

                if ($formdata{$key}) {
                        $formdata{$key} .= ", $value";
                } else {
                        $formdata{$key} = $value;
                }
        }
}
1;


I have manually open the html file from firefox's menu, and I when I submit
data into the farm, I get an unable to connect to server error. I'm not
sure where to go from here, I believe the folder(s) for the web page should
be in the tomcat/apache... folder , I'm just not sure where.
I would appreciate any help on this specific problem. Thanks in advance

Reply via email to