Ok. Just completed this myself using Tomcat 5.5.7, JDK 5 on a Mandrake Linux system and got it to work right.

Here's what I did from clean install:
1) Setup Tomcat -- there's tons of docs on this and no need to rehash things.
2) Renamed $CATALINA_HOME/server/lib/servlets-cgi.renametojar to $CATALINA_HOME/server/lib/servlets-cgi.jar.
3) Made two changes to the global web.xml at $CATALINA_HOME/conf/web.xml:
a) Uncommented the <servlet> element for the cgi servlet
b) Uncommented the <servlet-mapping> for the cgi servlet.
i) I should mention here I added a parameter for my paricular test cgi script:
<init-param>
<param-name>executable</param-name>
<param-value>/bin/bash</param-value>
</init-param>
c) Just a note: I would imagine this stuff could also be copy/pasted to your webapp's web.xml file instead.
4) Created a testapp directory in the webapps directory
5) Created a WEB-INF directory in the testapp directory
6) Created a cgi directory in the WEB-INF directory
7) Placed a very basic shell script in the cgi directory making sure execute privileges were set for it.
8) Wrote a minimal web.xml file essentially empty except for the DOCTYPE declaration, and a <web-app> root element.
9) Started Tomcat
10) Opened a browser and requested http://localhost:8080/testapp/cgi/hello-world.sh


My very basic cgi (the blank line between the Content-type header and the rest is necessary):

echo 'Content-type: text/html'
echo ''
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'
echo '<HTML>'
echo '<head><title>Test CGI script</title></head>'
echo '<body><h3 align="center">Hello World from the testapp CGI folder!!!</h3></body>'
echo '</HTML>'
echo ''



I've seen the above howto for better or worse in a few places on the net. A quick google search should find something.


The only real difference that I can see between my setup and yours, Alex, is the mapping. I used a mapping of /cgi as provided in the global web.xml file and you mapped yours with *.cgi. I don't know what kind of difference that makes except the path to the cgi might get real interesting. My suggestion would be to start over with an empty webapp and set it up as I described above. If it works, go back and look for differences between the broken app and the working one.

Good luck.  If this doesn't do it, I'm out of ideas.


--David



Brelsfoard, Alex wrote:

Yeah, it's good thinking.  But these are my only mappings:
   <servlet-mapping>
       <servlet-name>default</servlet-name>
       <url-pattern>/</url-pattern>
   </servlet-mapping>

   <!-- The mapping for the JSP servlet -->
   <servlet-mapping>
       <servlet-name>jsp</servlet-name>
       <url-pattern>*.jsp</url-pattern>
   </servlet-mapping>

   <!-- The mapping for the CGI Gateway servlet -->
   <servlet-mapping>
       <servlet-name>cgi</servlet-name>
       <url-pattern>*.cgi</url-pattern>
   </servlet-mapping>

Doesn't look like any overwriting here....
--Alex
Alex Brelsfoard
Web Applications Developer
Web Development Office
Worcester Polytechnic Institute
508-831-6147
[EMAIL PROTECTED]


________________________________

From: David Smith [mailto:[EMAIL PROTECTED]
Sent: Thu 2/10/2005 9:27 AM
To: Tomcat Users List
Subject: Re: Trouble getting CGI script to execute



Ok. I may try to go through and try this setup myself to see what
happens, but that won't happen until tonight. My boss seems to expect
me to do some work for the department -- go figure. In the meantime,
you may want to try removing the existing servlet mappings from your web
application's web.xml file, reload the context and try the cgi script. If that works, we've found our gremlin.


According to the servlet spec, nothing in the WEB-INF directory can be
directly accessed by the client.  That's what leads met to believe a
servlet somewhere is handling the request and passing back the raw
file.  Does the app hide anything else in the WEB-INF folder (images,
css, pages, etc., ...) and send it to the client on request?

--David

Brelsfoard, Alex wrote:



Thanks David.
Question 1: Yes.  I've made this mistake enogh times in the past that I'm
pretty good about it now.  Plus I have made other changes that required (and
received) a Tomcat reboot after doing that name change.

Question 2: That's a good thought... I've gone through the mappings and
cannot find anything that would interfere with my cgi script....

Good thinking.  Any other ideas?
Thanks.
--Alex

Alex Brelsfoard
Web Applications Developer
Web Development Office
Worcester Polytechnic Institute
508-831-6147
[EMAIL PROTECTED]

________________________________

From: David Smith [mailto:[EMAIL PROTECTED]
Sent: Wed 2/9/2005 6:02 PM
To: Tomcat Users List
Subject: Re: Trouble getting CGI script to execute



I know I'm coming into this very late.  I was hoping Mark was going to
nail this on the head for you -- especially since I don't actually use
the cgi-servlets piece in my stuff.  But I also hate to see a problem
like this get stalled.

Question 1:  This is a basic one, but I've had my share of Homer Simpson
moments.  Did you restart the server after renaming
$CATALINA_HOME/server/lib/servlets-cgi.renametojar to
$CATALINA/server/lib/servlets-cgi.jar and uncommenting the relevant
parts of $CATALINA_HOME/conf/web.xml?

Question 2: What do you have in your web.xml file for servlet mappings?
It seems to me some kind of mapping is overriding the mappings in
$CATALINA_HOME/conf/web.xml and simply offering the file from
WEB-INF/cgi-bin/ rather than executing it.

--David

Brelsfoard, Alex wrote:





Thanks I really appreciate your help.
--Alex


Alex Brelsfoard Web Applications Developer Web Development Office Worcester Polytechnic Institute 508-831-6147 [EMAIL PROTECTED]

-----Original Message-----
From: Mark Thomas [mailto:[EMAIL PROTECTED]
Sent: Wednesday, February 09, 2005 4:42 PM
To: Tomcat Users List
Subject: Re: Trouble getting CGI script to execute

Brelsfoard, Alex wrote:






Luckily this server is dedicated to this one application.  And I have
everything backed up.  Though security is ALWAYS an issue, it's at
least less of an issue on this server.  If today's attempts do not get
this woprking, I am most likely just going to turn off Tomcat's CGI
abilities and then install Apache and just limit the heck out of it.
Here is the CGI bits from the web.xml config file:
--------------------------------------------






<snip>

This looks fine.

I am afraid I have run out of ideas. If this was my system I would run up
tomcat under a debugger and start stepping through code.

It must be a configuration problem but I just can't figure out what.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]







---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]






--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to