Tomcat7 部署CGI程序

来源:互联网 发布:sql distinct 所有字段 编辑:程序博客网 时间:2024/06/05 05:44

部署环境:
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/pythonprint "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>";
0 0
原创粉丝点击