欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Tomcat6 调用C/C++的cgi配置

程序员文章站 2022-05-10 17:46:49
...
context.xml
<Context privileged="true">

    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
	
    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->

    <!-- Uncomment this to enable Comet connection tacking (provides events
         on session expiration as well as webapp lifecycle) -->
    <!--
    <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
    -->
</Context>

要加上privileged="true",否则tomcat启动报错,Servlet of class org.apache.catalina.servlets.CGIServlet is privileged and cannot be loaded by this web application
web.xml
    <servlet>
        <servlet-name>cgi</servlet-name>
        <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
        <init-param>
          <param-name>debug</param-name>
          <param-value>0</param-value>
        </init-param>
        <init-param>
          <param-name>cgiPathPrefix</param-name>
          <param-value>WEB-INF/cgi</param-value>
        </init-param>
        <init-param>
          <param-name>executable </param-name>
          <param-value>cmd /c </param-value>
        </init-param> 
        <load-on-startup>5</load-on-startup>
    </servlet>


C++代码
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{  
	cout<<"Content-type:text/html"<<endl<<endl;
	cout<<"Hello,World!";
	return 0;
}

编译后放在WEB-INF/cgi下。