Running cgi-bin on Tomcat: Simple steps & gotchas运行的CGI斌对雄猫:简单的步骤& gotchas
cgi-bin programs (common executables) can be run from Tomcat.的CGI斌程序(共同可执行)可以从本机运行的Tomcat 。 It is however not enabled by default.不过,这是默认情况下不启用。
To enable it carefully follow the steps below:使它能仔细按照下列步骤进行:
1. 1 。 Uncomment (or add) the following sections to $CATALINA_HOME/conf/web.xml (%CATALINA_HOME%\conf\web.xml on windows), between the取消(或添加)以下各节至catalina_home /设置/ web.xml ( % catalina_home % \设置\ web.xml在Windows ) ,之间的
2. 2 。 Rename the $CATALINA_HOME/server/lib/servlets-cgi.renametojar (%CATALINA_HOME%\server\lib\servlets-cgi.renametojar on windows) file to $CATALINA_HOME/server/lib/servlets-cgi.jar (%CATALINA_HOME%\server\lib\servlets-cgi.jar on windows)重新命名为catalina_home /服务器/ lib中/ / Servlets - cgi.renametojar ( % catalina_home % \服务器\库\ / Servlets - cgi.renametojar在Windows )文件美元catalina_home /服务器/ lib中/ / Servlets - cgi.jar ( % catalina_home % \服务器\库\ / Servlets - cgi.jar在Windows )
3. 3 。 Restart Tomcat重新启动的Tomcat
Testing with Hello.bat 测试与hello.bat
A simple way to test would be to create a cgi directory under WEB-INF directory of your Web application.一个简单的方法来测试,将创建一个目录下的CGI Web的INF目录您的Web应用程序。
Lets add a simple file called hello.bat (for windows users).允许添加一个简单的档案,称为hello.bat ( Windows用户) 。
The file contains just the line:该文件包含刚才的路线:
echo Hello World!回声世界您好!
This displays the String “Hello World!”这显示字符串“世界您好” !
Create a file called env.bat创建一个名为env.bat
The file contains just the line:该文件包含刚才的路线:
set 设置
This displays all the available environment variables for the cgi-bin program.这会显示所有可用的环境变量的CGI斌计划。
Gotchas on windows gotchas在Windows
—————— ------
Normally we use @echo off in a batch file to turn off displaying the command.通常我们使用@回声小康在一个批处理文件,关闭显示命令。 However when we do the following, no output is displayed:然而,当我们做好以下工作,没有输出显示:
@echo off @回声小康
echo Hello World!回声世界您好!
It just needs a newline to be happy.它只是需要一个换行符要快乐。 So create a file (say empty.txt) which just contains a newline.因此,建立一个档案, (说empty.txt )刚刚包含一个换行符。 Then change hello.bat to the following:然后改变hello.bat符合下列规定:
@echo off @回声小康
type empty.txt类型empty.txt
echo Hello World!回声世界您好!
echo on回声对
This works as intended.这一工程的原意。
Note: Would you like to show a注:您想显示 token of appreciation心意,以示感谢 for my hard work?我的辛勤工作? I enjoy a cup of我喜欢一杯 Cafe Estima Blend网吧estima共混 from Starbucks.从星巴克。
Filed under提起下 Headline News头条新闻 , , How To如何 , , Java Software Java软件 | |
| |
RSS 2.0 2.0 | |
Email this Article电子邮件此文章
You may also like to read您也可以想读 |





April 23rd, 2004 at 1:07 pm 2004年4月23日在下午1时07分
Don’t forget to uncomment the servlet-mapping for cgi不要忘了取消对Servlet的映射为的CGI
December 11th, 2004 at 2:11 pm 2004年12月11日在下午2时11分
I did at the bottom.我曾在底部。
March 25th, 2005 at 1:58 pm 2005年3月25日在下午1时58分
I had to specify an executable init param equal to the full path of perl in order to get this to work.我要指定一个可执行的init参数相等的完整路径的Perl在为了得到这个工作。
executable可执行
full path of perl完整路径的Perl
I am not sure why I had to do this since perl should already be in the path.我不知道为什么,我不得不这样做以来的Perl应该已经在路径中。 I’m running TomCat 5 on Windows XP Professional.我的Tomcat 5运行在Windows XP Professional 。
April 4th, 2005 at 3:14 pm 2005年4月4日在下午3时14分
@Giles Specifying full-path looks logical to me. @贾尔斯指定全路径看起来是合乎逻辑的我。 Java doesn’t invoke executables by looking at the path variable. Java的不引用可执行看PATH变量。
May 6th, 2005 at 1:43 am 2005年5月6日在上午01时43分
Add添加
executable可执行
or (windows xp)或( Windows XP中)
executable可执行
cmd /c cmd /炭
May 6th, 2005 at 1:47 am 2005年5月6日在上午01时47分
add添加
param-name=executable参数名称=可执行
value=值=
or (windows xp)或( Windows XP中)
param-name=executable参数名称=可执行
value=cmd /c值= cmd /炭
May 6th, 2005 at 1:49 am 2005年5月6日在上午01时49分
Directly add executables including batch files.直接添加可执行文件,包括批处理文件。
However if your want to execute cmd commands like dir then you will have to use cmd /c dir.但是如果您要执行cmd命令一样,迪尔那么你将不得不使用cmd /炭迪尔。
October 4th, 2005 at 5:04 am 2005年10月4日在上午05时04分
December 2nd, 2005 at 4:55 am 2005年12月2日在上午04时55分
hi all.can anybody help me to send and receive mail from my localhost.im using tomcat5 as my localserver.plz help me out..thanks to all喜all.can任何人帮助我发送和接收电子邮件从我的localhost.im使用tomcat5作为我的localserver.plz向我提供帮助..感谢所有
December 2nd, 2005 at 7:24 am 2005年12月2日在上午07时24分
Hi Rock,喜的岩石,
Please refer to this article -请参阅此文章-
How to Send / Receive Emails (SMTP & POP) From Localhost; Simple Freeware MailServer如何传送/接收电子邮件(的SMTP与流行音乐)由本地;简单的免费邮件服务器
It has been written to address your question.它已写信给解决您的问题。
Best,最好的,
Angsuman由Angsuman
December 15th, 2005 at 10:14 am 2005年12月15日在上午10时14分
Please, what is the URL that I shoul enter in order to get the cgi executed?请,网址是什么,我应当在进入,以获取的CGI执行?
Does the url below shouldn’t work?请问下面的网址不应该工作? it isn’t.事实并非如此。
http:localhost:8080//cgi-bin/foo.sh
thanks谢谢
Breno Leitão breno leitão
December 15th, 2005 at 11:44 am 2005年12月15日在上午11时44分
Try:尝试:
http://localhost:8080/Your http://localhost:8080/your web application directory]/cgi-bin/foo.sh Web应用程序目录] / cgi-bin/foo.sh
Please closely follow the instructions above.请密切合作,按照上述指示。
April 20th, 2006 at 12:42 pm 2006年4月20日在下午12时42分
I have been trying to put perl scripts in webapps/ROOT/WEB-INF/cgi-bin:我一直试图把Perl脚本在webapps /根/网络-干扰素/的CGI斌:
A) printEnv.cgi一) printenv.cgi
#!/usr/bin/perl # !修改/ usr / bin /的Perl
print “Content-type: text/html\n\n”;打印“的内容类型:为text / html \ n \ n已” ;
print “\n”;打印“ \ n ” ;
foreach $key (sort keys(%ENV)) { foreach美元的关键(排序键( %的Env ) ) (
print “$key = $ENV{$key}”;打印“ $关键=美元的Env ( $关键) ” ;
} )
B) Changes to web.xml b )改变以web.xml
cgi的CGI
org.apache.catalina.servlets.CGIServlet org.apache.catalina.servlets.cgiservlet
executable可执行
/usr/bin/perl修改/ usr / bin /的Perl
clientInputTimeout clientinputtimeout
100
debug调试
6六
cgiPathPrefix cgipathprefix
WEB-INF/cgi-bin web-inf/cgi-bin
5五
cgi的CGI
/cgi-bin/* /的CGI斌/ *
D) Renamed to servlets-cgi.jar d )在更名为/ Servlets - cgi.jar
E) Restarted server e )在重新启动服务器
But when I do:但是,当我这样做:
http://mydomain/cgi-bin/printEnv.cgi http://mydomain/cgi-bin/printenv.cgi
it does not go to the URL它不会转到该网址
April 28th, 2006 at 12:24 pm 2006年4月28日在下午12时24分
The steps have worked perfectly for many including myself.步骤,工作完全对许多包括我自己在内。
Unfortunately I don’t have time at this moment to support your specific issue.可惜我没有时间在这一刻来支持您的具体问题。
April 25th, 2007 at 1:47 pm 2007年4月25日在下午1时47分
Hi,嗨,
I followed the steps but I cannot start bat file as cgi script on WinXP.我在的步骤,但我无法启动bat文件作为CGI脚本就winxp 。 The error is: “java.io.IOException: Cannot run program “perl” (in directory “C:\Program Files\Tomcat 5.5\webapps\test\WEB-INF\cgi”)错误是: “ java.io.ioexception :不能运行程序”的Perl “ (在目录中的” C : \程式档案\的Tomcat 5.5 \ webapps \测试\网站-干扰素\的CGI “ )
I tried to add我曾尝试添加
param-name=executable参数名称=可执行
value=cmd /c值= cmd /炭
or param-name=executable或参数名称=可执行
value=cmd值= cmd
but without success.但未获成功。 Any ideas?任何想法?
October 19th, 2007 at 3:37 am 2007年10月19日在上午03时37分
test.cgi is : test.cgi是:
#!\perl\bin\perl.exe# ! \的Perl \斌\ perl.exeprint “Content-type: text/html\n\n”;打印“的内容类型:为text / html \ n \ n已” ;
print “IN TEST!\n”;打印“在测试! \ n ” ;
print “\n”;打印“ \ n ” ;
print “IN TEST!\n”;打印“在测试! \ n ” ;
print “\n”;打印“ \ n ” ;
Store Location of test.cgi is : webapps/test/商店的位置test.cgi是: webapps /测试/
Output in在输出 http://localhost:8080/test/test.cgi http://localhost:8080/test/test.cgi
#!\perl\bin\perl.exe print “Content-type: text/html\n\n”; print “\n”; print “\n”; print “# ! \的Perl \斌\ perl.exe打印“的内容类型:为text / html \ n \ n已” ;打印“ \ n ” ;打印“ \ n ” ;打印“IN TEST!在测试!\n”; print “\n”;\ n “ ;打印” \ n “ ;October 19th, 2007 at 3:48 am 2007年10月19日在上午03时48分
Please help me to fix the working of CGI which I mentioned above.请帮我修复工作的CGI ,我上述的。 I am not able to execute ang CGI through TOMCAT.我无法执行昂的CGI通过的Tomcat 。