Linux Tomcat cgi配置

有apache为什么不用,非要用Tomcat,哎客户是上帝。cgi配置主要是为C/C++使用,当然perl等也差不多。

1.首先/usr/local/apache-tomcat-7.0.29/conf/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

2./usr/local/apache-tomcat-7.0.29/conf/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></param-value>
        </init-param>
         <load-on-startup>5</load-on-startup>

 </servlet>

注释去掉,使cgi生效。


3.还是web.xml下

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

把CGI映射这一段注释去掉。

4.最后bin下shutdown.sh startup.sh脚本重启下Tomcat就生效了。

最后附个测试helloworld

#include<stdio.h>
int main()
{
        printf("Content-type:text/html\n\n");
        printf("hello,world!");
        return 0;
}编译后cp到cgi目录,浏览器中就看到了hello,world!




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值