Tomcat7 部署CGI程序

部署环境:
1. ubuntu14.04.3_x64
2. jdk1.7.0_79
3. apache-tomcat-7.0.63

Apache官方参考资料: CGI How To

1) 修改$CATALINA_HOME/conf/web.xml

<!-- The CGI Gateway servlet -->
<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>
  <load-on-startup>5</load-on-startup>
</servlet>

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

根据web.xml中的描述,关于executable部分,默认值如下

<!-- if you leave the param blank it will run any script type. -->
<init-param>
  <param-name>executable</param-name>
  <param-value></param-value>
</init-param>

2) 修改$CATALINA_HOME/conf/context.xml

<Context privileged="true">
...
</Context>

在原来的基础上将Context部分添加上privileged="true"

3) 目录结构

|-tomcat
|--webapps
|---cgi-example
|----WEB-INF
|-----cgi
|------first.py
|------second.pl

4) 启动Tomcat

user@ubuntu:/opt/tomcat7/bin $./startup.sh

5) 访问路径

http://localhost:8080/cgi-example/cgi-bin/first.py
http://localhost:8080/cgi-example/cgi-bin/second.pl


附录

python first.py

#! /usr/bin/python

print "content-type: text/html"
print ""

print "<html><head><title>Welcome</title></head>"
print "<body><h1>Welcome to the output of a CGI under Tomcat</h1>"
print "<p>The subject says all.</p>"
print "</body></html>"

Perl second.pl

#! /usr/bin/perl 

print "content-type: text/html"; 

$now = localtime(); 
print "<h1>It is $now</h1>";
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值