i792439187
挨踢的小胖
2012-11-06 20:10

Tomcat 6如何配置C/C++的cgi

已采纳

在web.xml的配置:

cgi
org.apache.catalina.servlets.CGIServlet

debug
0


passShellEnvironment
true


cgiPathPrefix
WEB-INF/cgi-bin


executable
cmd /c



clientInputTimeout
100

5

<servlet-mapping>
    <servlet-name>cgi</servlet-name>
    <url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>

在context.xml的配置:

cgi
/cgi-bin/*

调用cgi的网页代码:

<!Sample web page for illustrating CGI>
<!Author: M. Liu, 9/15/01>


A Web Page that invokes a Web script

The Web Page illustrates the use of a Web script

This page contains an action tag which specifies a Web script. Upon retrieving this page from the Web server, the browser processes the contents and, when the SUBMIT button is pressed, requests the server to run the script or program specified with the action tag.
The script o program is either a run-script written in a script language such asa Perl, or an executable generated from a source program written in a language such as C/C++



Press to submit your query.


cgi运行不了。求大神指导。
[img]http://dl.iteye.com/upload/attachment/0076/2560/350574ac-02df-3df6-b111-267a895dcb22.png[/img]

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • blogzhoubo blogzhoubo 9年前

    如果用c或者c++的话,应该编译成hello.exe这样的可执行文件,然后

    改成

    然后在浏览器访问 http://localhost:8080/cgi-bin/hello.exe

    此外,因为hello.exe本身就是可执行程序,所以executable的值配置成空也没问题

    executable

    报错的原因应该是windows不知道hello.cgi应该用什么程序打开(没有设置cgi的文件关联),也就是不识别cgi扩展名。直接在windows的cmd窗口中执行cmd /c hello.cgi的话,会直接弹出对话框,让你选择用什么程序打开hello.cgi文件。

    点赞 评论 复制链接分享

相关推荐