Re: [OT] Issue with cgi/perl webpage
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 Felipe, On 11/22/13, 10:29 AM, Felipe wrote: Interesting, so do container-based systems such as Tomcat rely heavely on httpd? No, but it's quite common to see httpd used to front a Tomcat-based application. This is a good strategy when you need complicated deployments with different JVMs running different applications (or maybe just multiple JVMs running the same application, for fail-over and load-balancing). I've read that many people use Tomcat just for webapp deployment and use apache to handle static pages, among other things, but is it reasonable to use Tomcat to handle static pages, or is it solely for webapp server? Tomcat does a great job as a static web server, but to get better performance from the default you should: 1. Enable APR (connectors will auto-detect and use) if you use HTTPS or 2. Switch to the NIO connector if you don't use HTTPS APR's OpenSSL-based TLS implementation turns out to be faster than other combinations of code. NIO and APR are about evenly-matched when it comes to throughput and scalability, though I would bet on NIO all other things being equal. I'm actually interested in using Tomcat for a personal project. It is using an Arduino Uno microcontroller (an AVR microcoontroller, specifically Atmel's ATMEGA 328), I would like to use the arduino as a server that could handle requests by way of a web interface control panel. I think this is would be an appropiate scenario to use JSP and Tomcat. A JVM will not likely be a great choice on that platform. Modest processor and low memory? Sounds like a disaster for a server-quality JVM. You could look at an embedded JVM, but running Tomcat on top of that isn't likely to pay off. Initially I would create a simple webapp that has prompt (where a user can input a command that the arduino will then act on) and display analog reading's (so as to monitor). This kind of thing can be done with a simple Bash script, and use a lot less memory. Be aware that what you are doing is (intentionally) opening a huge security hole in your setup. I'm just no sure how to go about hosting tomcat, I'm pretty sure it is not possible to run on the arduino, but maybe using port forwarding or web socket to have Tomcat on a laptop or maybe a rasberry pi. Would this be a feasible method? Probably not. If you were going to do all that, what's the point in running Tomcat at all? - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.15 (Darwin) Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBCAAGBQJSk1pJAAoJEBzwKT+lPKRYUXgP/3e4+xfJIAieTw8U9ohtvLfZ Jjl65dwjlhCRH26imhqIK9MK3w9ox+odGpjSlMM+cUPYgiIGZhxbFtUvLOigdkW4 0ENutvSzXg/mLdrDVM035IjRJMSXyIjk4Av2Wc+kJOeSyNEKREClN9Kgjojx2y44 8GoaoZCNhXgI76JfqBIgwidxrLhECS7Y5UIWzuDI0bsW0x6r1B5VhZdQBnpp2t9g 6Eb3BmfA8fE4hZYjkimKEvPCdryB/+lFuDgf5dBMIUVAemMK1fl+yn4hCaL9MKbY DJnJeEM7Keu9KaYY4hQxQg9do/y7CNWMTqIfpB0/L2fYEu4HriNItQm0sATJ8XYB Kjkd7TP0NU1lyhQLI7ikbkDDA/48oYBS0GkvN3F1TNYENyRuNW9fzUNMEPp6cXvd HH5vPGn4NerJpdXq5wV6m0zVXCuOyl9uUDuP0LRHzx9fkA991RcxYqR4m21kHugD Qi31kvw3klUJfPls7oRAY0LQJ2E3+sjGbtPccvCo4reQoxh1w7BcRxRKxwh63nKE Cb4ITADi3qITfPRmRIHUVlDk/YD5/c2jZXxWU8Ecw4UwD9Aa9PsYzjwD2hkPBgGx mvcTA4q0Lep8MZg+Il2/2sN0wAvMBRY8eu6fkDpFMrkDzEkYEa8jbx0znQYDeJBx 7CmJMGl2LBOcIJu1s55h =vBKG -END PGP SIGNATURE- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: [OT] Issue with cgi/perl webpage
Felipe wrote: Interesting, so do container-based systems such as Tomcat rely heavely on httpd? Not necessarily. Read on. I've read that many people use Tomcat just for webapp deployment and use apache to handle static pages, among other things, but is it reasonable to use Tomcat to handle static pages, or is it solely for webapp server? By design, Tomcat is primarily a java servlet container, meaning that its primary design goal is to provide an environment to run java servlets efficiently. But it is rarely so that applications would consist only of java servlets, so there exists also within Tomcat a default servlet, which is invoked by Tomcat to serve any request which cannot clearly be assigned to any other servlet, and which consequently does serves most static content (html pages, stylesheets, images, ..). And it just so happens that this default servlet is very efficient too, so that in the end Tomcat can perfectly be used as a generic webserver to serve both static content, along with the results of servlets execution. There also exists a cgi-bin servlet which can run cgi-bin scripts and programs. But this cgi-bin servlet is not really optimised for any particular kind of cgi-bin programs/scripts, and that is where other webservers may beat tomcat in terms of efficiency. For example, if you are talking about cgi-bin scripts written in Perl or PHP : there exist special add-on modules for the Apache httpd webserver, which can optimise the running of scripts written in such languages (usually by pre-compiling them and keeping the compiled version in some cache memory)(*). Such add-on modules do not exist for tomcat, and thus if a main part of an application would consist of such scripts, it would be more efficient in an overall sense to use a front-end webserver like Apache httpd, to run these parts of the application, and then have Apache httpd delegate to a tomcat back-end what is destined for java servlets. When you reflect about this, it is exactly the same in reverse : Apache httpd could also run cgi-bin scripts written in Java. It would just have to start a JVM at each invocation, to compile and run the java script. Of course, that would be very inefficient, which is why for running java servlets it is better to use tomcat (or another java servlet container). There is nothing /in the principle/ that would prevent someone from writing a special java perl cgi-bin servlet for tomcat, which would duplicate the functionality of some of what the mod_perl module does for Apache httpd, and make it very efficient to run perl cgi-bin scripts under tomcat (**). It just hasn't been done yet, the main reason being probably : why do it ? (when it is easy to configure Apache httpd as a front-end to tomcat, and do it there using mod_perl). (*) See http://perl.apache.org (**) and similarly, one could think about a mod_java add-on module for Apache httpd - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: [OT] Issue with cgi/perl webpage
Interesting, so do container-based systems such as Tomcat rely heavely on httpd? I've read that many people use Tomcat just for webapp deployment and use apache to handle static pages, among other things, but is it reasonable to use Tomcat to handle static pages, or is it solely for webapp server? Thanks Neven, I was able to get the cgi script working, I'm in the process of dissecting and writing the steps to have tomcat host the cgi-script for my professor, we talked and he saw that apache was what was meant to be used but he encouraged my efforts in using Tomcat instead. Even if it isn't the logical way to the exercise. There's a possibility that they might use the this as an example of Tomcat's cgi support. I'm actually interested in using Tomcat for a personal project. It is using an Arduino Uno microcontroller (an AVR microcoontroller, specifically Atmel's ATMEGA 328), I would like to use the arduino as a server that could handle requests by way of a web interface control panel. I think this is would be an appropiate scenario to use JSP and Tomcat. Initially I would create a simple webapp that has prompt (where a user can input a command that the arduino will then act on) and display analog reading's (so as to monitor). I'm just no sure how to go about hosting tomcat, I'm pretty sure it is not possible to run on the arduino, but maybe using port forwarding or web socket to have Tomcat on a laptop or maybe a rasberry pi. Would this be a feasible method? On Thu, Nov 21, 2013 at 8:36 PM, Christopher Schultz ch...@christopherschultz.net wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA256 Neven, On 11/20/13, 11:48 AM, Neven Cvetkovic wrote: Ultimately, CGI is a very old technology that had its own share of performance (and security) problems. Usually, CGI scripts were replaced with superior Java Servlet technology (or some other better technology) and hence the need for Tomcat application server (servlet container). Hopefully, the rest of the mailing list members share my sentiments about the CGI :) - -0 The only thing that really makes CGI outdated is that CGI itself didn't have an API... or if you could call it an API, it was very basic. It basically said you get the query string in a big blob and you can read standard input if you want to get the entity body. Then everyone set to work writing their own custom parsing routines. I remember copy/pasting stuff in Perl way back in 1994 and now having any idea what the code actually did. These days, you can pretty much write a Perl script and say use CGI; and it's just magic, safe, etc. CGI has come a long way. The last remaining problem is really that of performance: the CGI model launches a new process for each request (even though you can cheat a bit using things like mod_perl, etc.) and so there is a performance hit right there. If you want to keep information between requests, you have no choice but to write it to some form of non-volatile storage (as far as the application is concerned). RDBMS, flat file, etc. More recent systems (I hesitate to say modern because it implies that they are better simply because they are newer, and that the older methodologies are simply worse by definition) are supported by much more complicated software, APIs, etc. Note that container-based systems like Tomcat have their own performance problems: they have to manage all the stuff that they are ... well, required to support. If you peel-away all of the stuff that Apache httpd provides *aside* from the Common Gateway Interface, you are left with a server that primarily pumps bytes back and forth between the client and the script. Tomcat has all kinds of moving parts that make it possible to do nice things, but those moving parts have a cost. (It's worth noting that I believe such costs are worth it. That's why I live in the container-based world instead of writing Perl- or PHP-based applications.) Want to deploy a single Hello, World! CGI script? No problem. Just drop #!/bin/sh\n\necho Hello, World! into a .cgi file in your document root and tell Apache httpd it's okay to run it. Want to deploy a single Hello, World! script on Tomcat? Well, first you have to know where the auto-deployment directory is (hint: it's not a document root), and then you have to create a directory in there, and then drop a .jsp file in there. The good news is that Hello, World! is a valid JSP file without any of the fluff you need to make a shell script run. But the small amount of orientation required just to get the point of dropping text into a file can be confusing. Once the almighty container is involved, there is pressure to make it do more things. Sessions. Replication. Websockets. These are all very good and very useful things, but it further complicates the scenario. It's just a tough world to jump into with little to no planning. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.15 (Darwin)
Re: [OT] Issue with cgi/perl webpage
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 Neven, On 11/20/13, 11:48 AM, Neven Cvetkovic wrote: Ultimately, CGI is a very old technology that had its own share of performance (and security) problems. Usually, CGI scripts were replaced with superior Java Servlet technology (or some other better technology) and hence the need for Tomcat application server (servlet container). Hopefully, the rest of the mailing list members share my sentiments about the CGI :) - -0 The only thing that really makes CGI outdated is that CGI itself didn't have an API... or if you could call it an API, it was very basic. It basically said you get the query string in a big blob and you can read standard input if you want to get the entity body. Then everyone set to work writing their own custom parsing routines. I remember copy/pasting stuff in Perl way back in 1994 and now having any idea what the code actually did. These days, you can pretty much write a Perl script and say use CGI; and it's just magic, safe, etc. CGI has come a long way. The last remaining problem is really that of performance: the CGI model launches a new process for each request (even though you can cheat a bit using things like mod_perl, etc.) and so there is a performance hit right there. If you want to keep information between requests, you have no choice but to write it to some form of non-volatile storage (as far as the application is concerned). RDBMS, flat file, etc. More recent systems (I hesitate to say modern because it implies that they are better simply because they are newer, and that the older methodologies are simply worse by definition) are supported by much more complicated software, APIs, etc. Note that container-based systems like Tomcat have their own performance problems: they have to manage all the stuff that they are ... well, required to support. If you peel-away all of the stuff that Apache httpd provides *aside* from the Common Gateway Interface, you are left with a server that primarily pumps bytes back and forth between the client and the script. Tomcat has all kinds of moving parts that make it possible to do nice things, but those moving parts have a cost. (It's worth noting that I believe such costs are worth it. That's why I live in the container-based world instead of writing Perl- or PHP-based applications.) Want to deploy a single Hello, World! CGI script? No problem. Just drop #!/bin/sh\n\necho Hello, World! into a .cgi file in your document root and tell Apache httpd it's okay to run it. Want to deploy a single Hello, World! script on Tomcat? Well, first you have to know where the auto-deployment directory is (hint: it's not a document root), and then you have to create a directory in there, and then drop a .jsp file in there. The good news is that Hello, World! is a valid JSP file without any of the fluff you need to make a shell script run. But the small amount of orientation required just to get the point of dropping text into a file can be confusing. Once the almighty container is involved, there is pressure to make it do more things. Sessions. Replication. Websockets. These are all very good and very useful things, but it further complicates the scenario. It's just a tough world to jump into with little to no planning. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.15 (Darwin) Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBCAAGBQJSjrUUAAoJEBzwKT+lPKRYdcsQAIWqzHUbSimrUmXcYw9KH0zs fkZCQvi3Hqon1afyun6fU+NT8Ta0YkOYKW8gEiWvrogcZtMl1Q/oxOKSWZvPG8g1 8nPyDbACRL2715VUKuWgCTfABuQnHYOjFuakqAfZsXcVigxfpwWyw8eS7KfwpaDv vr/ZwqDv2ThQs63rk2rO5HW9o65nk2+XX4RBaUAw6lRZ7AfKMH5upR5Qwe231aKR DBF6GsuoWGeyONPXyGGIcrjLeizg1pOf1m0W3cTTIgI6UBNFUez+hZHGpFxbkrNE FX3onEVfrjlaxfSFmDx4ytDyOo973fhMALrasvIUSPqdKhjvIFHTYarZHRrOxex1 /L+YWnth7xAWTHPz+SzM7YWzRTDfWeOMq9PCx8wdoV88BJ35tQerxowdvbo+fPJN S+Y+zw2iZwlyN8bVfwVpG81my8SEtFgrxhyPZMTqDK8RppL1QlC+aemQHiafTwoH 78+JP1HRR/tgYM9WXsDmOhIFgZp2pjATvuklqc5gw7BWX6J9UF8LjqEAmgwj5/KI JlcMgCLH91WvjU/7p0jFnTMGHalL8Bz4L4KFp9OwA4gwkvjZQF1q1MbEGU/GVHP+ z2hJHeC4ugXk9zzO9imlUMZhC/pNGkwc/5leSMaHhwd0uZMatKh3sM4LLmoptiDP 0/kSWWI/zKK0USODk240 =21G3 -END PGP SIGNATURE- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Issue with cgi/perl webpage
On Wed, Nov 20, 2013 at 12:21 AM, Felipe felipeh...@gmail.com wrote: Neven, First of all, I'd like to thank you for all the help. I can say I have learned a great deal through this experience. To clarify, the choice of using tomcat for this was not mine. I am trying to lend a hand to a professor of mine. This specific exercise is in his Unix class. For some reason he thinks tomcat or at least every time he mentioned this exercise to me he made reference to apache tomcat, is meant to be used in the exercise. The exercise is on hosting a web page with perl scripts/cgi. So in his instructions it's clearly using apache on Ubuntu. So he mentioned to Felipe, just wanted to make sure you are aware, there are two often confused Apache projects: Apache HTTP Server (webserver) - also referred just as 'Apache' - http://httpd.apache.org/ Apache Tomcat (Java appserver) - also referred just as 'Tomcat' - http://tomcat.apache.org/ Searching online, this seems like a very typical CGI programming project many universities use in their curriculum. Also, it seems the examples come from Guide to UNIX Using Linux by Michael Palmer (ISBN: 978-1-4188-3723-5) Thus, Tomcat is not the best web server to serve your CGI scripts, this is usually done using Apache (httpd server) - as Konstantin pointed out - using Tomcat will not give you the most optimal performance. However, if you insist working with Tomcat, here's how you do it: (Thanks Konstantin for pointing that out) You probably should update web.xml of your application and not the global CATALINA_HOME/conf/web.xml... You application then looks like this: /home/luis/tomcat/apache-tomcat-8.0.0-RC5/webapps/FelipeAppWithCgi: META-INF/context.xml (to make your application privileged) WEB-INF/web.xml (to define servlet and servlet mapping) WEB-INF/cgi/projects.cgi (your cgi script) WEB-INF/cgi/subparseform.lib (your cgi library) ProjectAnalysis.html (your html form) index.html (your welcome page that includes) Here's the dropbox link I created that works with Tomcat: https://www.dropbox.com/sh/c32ecuryj2mgb6i/-eC0FQOCbF There are two ways to deploy it: 1) As a unpackaged folder FelipeAppWithCgi - you need to get all the files and directory structure 2) As a packaged WAR file FelipeAppWithCgi.war (WAR is essentially a zip archive with certain directory structure) Ultimately, CGI is a very old technology that had its own share of performance (and security) problems. Usually, CGI scripts were replaced with superior Java Servlet technology (or some other better technology) and hence the need for Tomcat application server (servlet container). Hopefully, the rest of the mailing list members share my sentiments about the CGI :) me that he was having trouble with the exercise and asked if I maybe I had any idea. I'm not in his class, but I love working in linux and more importantly helping out wherever I can. So I took it upon myself to try to learn the material in this exercise and re-write the instructions, but now -once again thanks for all the help No worries. Glad we could shed some light.
Issue with cgi/perl webpage
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-namecgiPathPrefix/param-name param-valueWEB-INF/cgi-bin/*/param-value /init-param load-on-startup5/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 - HTMLHEADTITLEProject Analysis/TITLE/HEAD BODY H2Average 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 HRINPUT 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 PProject Cost Last Year was $projcost dollars.; print PWe completed $projects projects during the year. That works out to an average of $average cost per project.; print POur 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 PUse 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
Re: Issue with cgi/perl webpage
Felipe your form action seem to be wrong. Nothing is listening on port 80 as notwd in your html. It should be more like http://localhost:8080/... Depending how that default servlet has been mapped to cgi programs. Hopefully that will get you going :) On Nov 20, 2013 3:01 AM, Felipe felipeh...@gmail.com wrote: 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-namecgiPathPrefix/param-name param-valueWEB-INF/cgi-bin/*/param-value /init-param load-on-startup5/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 - HTMLHEADTITLEProject Analysis/TITLE/HEAD BODY H2Average 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 HRINPUT 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 PProject Cost Last Year was $projcost dollars.; print PWe completed $projects projects during the year. That works out to an average of $average cost per project.; print POur 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 PUse 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
Re: Issue with cgi/perl webpage
Thank you Neven, So, basically I've tried your suggestion, but I tried it again to see if anything would change, but I got this error: *type* Status report *message* */home/luis/tomcat/apache-tomcat-8.0.0-RC5/web/cgi-bin/project.cgi* *description* *The requested resource is not available.* Could it be that the web folder should be somewhere else in the tomcat/apache-tomcat-8.0.0-RC5? On Tue, Nov 19, 2013 at 9:09 PM, Neven Cvetkovic neven.cvetko...@gmail.comwrote: Felipe your form action seem to be wrong. Nothing is listening on port 80 as notwd in your html. It should be more like http://localhost:8080/... Depending how that default servlet has been mapped to cgi programs. Hopefully that will get you going :) On Nov 20, 2013 3:01 AM, Felipe felipeh...@gmail.com wrote: 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-namecgiPathPrefix/param-name param-valueWEB-INF/cgi-bin/*/param-value /init-param load-on-startup5/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 - HTMLHEADTITLEProject Analysis/TITLE/HEAD BODY H2Average 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 HRINPUT 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 PProject Cost Last Year was $projcost dollars.; print PWe completed $projects projects during the year. That works out to an average of $average cost per project.; print POur 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 PUse 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
Re: Issue with cgi/perl webpage
Felipe, As noted in the web.xml comments, in order to make cgi-servlet working, you need to package cgi scripts with your web application (e.g. yourapp.war): Common Gateway Includes (CGI) processing servlet, which supports execution of external applications that conform to the CGI spec requirements. Typically, this servlet is mapped to the URL pattern /cgi-bin/*, which means that any CGI applications that are executed must be present within the web application... So, if you deployed your webapp as /home/luis/tomcat/apache-tomcat-8.0.0-RC5/webapps/YOURAPP You will need the following files in your YOURAPP folder: WEB-INF/cgi/project.cgi WEB-INF/cgi/subparseform.lib ProjectAnalysis.html Your ProjectAnalysis.html will have the following form action URL, e.g. form action=http://localhost:8080/YOURAPP/cgi-bin/project.cgi; method=post ... /form Make sure that both servlet and servlet-mapping are uncommented. Read more details about CGI support here: http://tomcat.apache.org/tomcat-7.0-doc/cgi-howto.html Now, more important questions for you: Why are you using Tomcat and CGI support in Tomcat? If you are not deploying Java applications, what's the point of using Tomcat, why not just use Apache web server (httpd)? Why are you using subparseform.lib? It would be so much cleaner to use JSP+Servlet code for that ... provided you have nice JSP/Java development environment, etc... The easiest to develop (also terrible way to do it) is to use just JSPs and code all your logic, calculations etc... in JSP itself. For example, e.g. CATALINA_HOME/webapps/YOURAPP: ProjectAnalysis.html projects.jsp begin projects.jsp html body h1Results/h1 % String projcost = request.getParameter(projcost); String projects = request.getParameter(projects); String revenue = request.getParameter(revenue); double projcostValue = Double.parseDouble(projcost); double projectsValue = Double.parseDouble(projects); double revenueValue = Double.parseDouble(revenue); double average = projcostValue / projectsValue; double grossprofit = revenueValue - projcostValue; % pProject Cost Last Year was $projcost dollars./p pWe completed %= projectsValue % projects during the year. That works out to an average of %= average % cost per project./p pOur annual Project Revenue was %= revenueValue % dollars. We made a gross profit of %= grossprofit % dollars/p /body /html end projects.jsp Or something like that ... now, I don't guarantee for the correctness of the JSP code, since I just typed it here and not actually tried it out and tested, but you get the idea... You really should ask yourself - why Tomcat and not some other simpler webserver? Good luck! n.
Re: Issue with cgi/perl webpage
Neven, First of all, I'd like to thank you for all the help. I can say I have learned a great deal through this experience. To clarify, the choice of using tomcat for this was not mine. I am trying to lend a hand to a professor of mine. This specific exercise is in his Unix class. For some reason he thinks tomcat or at least every time he mentioned this exercise to me he made reference to apache tomcat, is meant to be used in the exercise. The exercise is on hosting a web page with perl scripts/cgi. So in his instructions it's clearly using apache on Ubuntu. So he mentioned to me that he was having trouble with the exercise and asked if I maybe I had any idea. I'm not in his class, but I love working in linux and more importantly helping out wherever I can. So I took it upon myself to try to learn the material in this exercise and re-write the instructions, but now I see there was some confusion on his part.But thank you for pointing me in the right direction. * I did not package the cgi script in WAR file, this is most likely the reason it is not working. If you don't mind I would like to work on your JSP code and see if maybe I could write to separate guides for his class, one for the cgi scipt on apache and another for tomcat using JSP. One more thing: Your ProjectAnalysis.html will have the following form action URL, e.g. form action=http://localhost:8080/YOURAPP/cgi-bin/project.cgi; method=post /form? since it was an example I assume I have to list the whole path for the project .cgi : FORM METHOD=POST ACTION= http://localhost:8080/home/luis/tomcat/apache-tomcat-8.0.0-RC5/webapps/web /WEB-INF/cgi-bin/project.cgi -once again thanks for all the help On Tue, Nov 19, 2013 at 11:09 PM, Neven Cvetkovic neven.cvetko...@gmail.com wrote: Felipe, As noted in the web.xml comments, in order to make cgi-servlet working, you need to package cgi scripts with your web application (e.g. yourapp.war): Common Gateway Includes (CGI) processing servlet, which supports execution of external applications that conform to the CGI spec requirements. Typically, this servlet is mapped to the URL pattern /cgi-bin/*, which means that any CGI applications that are executed must be present within the web application... So, if you deployed your webapp as /home/luis/tomcat/apache-tomcat-8.0.0-RC5/webapps/YOURAPP You will need the following files in your YOURAPP folder: WEB-INF/cgi/project.cgi WEB-INF/cgi/subparseform.lib ProjectAnalysis.html Your ProjectAnalysis.html will have the following form action URL, e.g. form action=http://localhost:8080/YOURAPP/cgi-bin/project.cgi; method=post ... /form Make sure that both servlet and servlet-mapping are uncommented. Read more details about CGI support here: http://tomcat.apache.org/tomcat-7.0-doc/cgi-howto.html Now, more important questions for you: Why are you using Tomcat and CGI support in Tomcat? If you are not deploying Java applications, what's the point of using Tomcat, why not just use Apache web server (httpd)? Why are you using subparseform.lib? It would be so much cleaner to use JSP+Servlet code for that ... provided you have nice JSP/Java development environment, etc... The easiest to develop (also terrible way to do it) is to use just JSPs and code all your logic, calculations etc... in JSP itself. For example, e.g. CATALINA_HOME/webapps/YOURAPP: ProjectAnalysis.html projects.jsp begin projects.jsp html body h1Results/h1 % String projcost = request.getParameter(projcost); String projects = request.getParameter(projects); String revenue = request.getParameter(revenue); double projcostValue = Double.parseDouble(projcost); double projectsValue = Double.parseDouble(projects); double revenueValue = Double.parseDouble(revenue); double average = projcostValue / projectsValue; double grossprofit = revenueValue - projcostValue; % pProject Cost Last Year was $projcost dollars./p pWe completed %= projectsValue % projects during the year. That works out to an average of %= average % cost per project./p pOur annual Project Revenue was %= revenueValue % dollars. We made a gross profit of %= grossprofit % dollars/p /body /html end projects.jsp Or something like that ... now, I don't guarantee for the correctness of the JSP code, since I just typed it here and not actually tried it out and tested, but you get the idea... You really should ask yourself - why Tomcat and not some other simpler webserver? Good luck! n. -- Luis Felipe Hernandez
Re: Issue with cgi/perl webpage
2013/11/20 Felipe felipeh...@gmail.com: 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-namecgiPathPrefix/param-name param-valueWEB-INF/cgi-bin/*/param-value /init-param load-on-startup5/load-on-startup /servlet 1. conf/web.xml provides defaults to all web applications that are deployed on Tomcat. Instead of uncommenting the servlet and servlet-mapping there you would better copy them into WEB-INF/web.xml file of your own web application. 2. Your web application (aka context) must be marked as privileged. Non-privileged web applications are not allowed to use CgiServlet. This servlet poses a security risk and thus this additional protection is in place. 3. While it is technically possible to use Perl with Apache Tomcat (as well as to start external programs from within Java), using it with Apache HTTPD would provide better performance. Best regards, Konstantin Kolinko - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org