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 ) ,之间的 and tags.标记。


cgi的CGI

org.apache.catalina.servlets.CGIServlet org.apache.catalina.servlets.cgiservlet

clientInputTimeout clientinputtimeout 100

debug调试 6

cgiPathPrefix cgipathprefix WEB-INF/cgi web-inf/cgi
5


cgi的CGI

/cgi-bin/* /的CGI斌/ *

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.从星巴克。