Tomcat 配置参考 : http://www.jianshu.com/p/1efb1b627070
1. 修改Tomcat目录下的 xx/conf/web.xml.
(比如我的:/usr/local/apache-tomcat-8.5.11/conf/web.xml
)
- 取消<servlet>注释
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>cgiPathPrefix</param-name>
<!-- <param-value>WEB-INF/cgi</param-value> -->
<param-value></param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
注意 : <param-value></param-value>
本来是有值得 <param-value>WEB_INF/cgi</param-value>
但是我为了简化目录层级所以删除了.
- 取消cgi<servlet-mapping>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>
2. 修改xx/conf/context.xml
为<Context> 标签添加privileged="true"
属性.
<Context privileged="true">
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
</Context>
3. 测试.
- 创建测试文件
first.pl
#!C:/strawberry/perl/binperl.exe
print "Content-type: text/html\n\n";
print "Hello, world! I am CGI\n"
-
在xx/webapps/下创建cgi_app 文件夹.名字可自定义.名字不同URL不同. 将刚才创建的测试文件拷贝到该目录下.
-
在浏览器中输入(如果你的也是cgi_app则可以直接点击否则需要修改下图标红部分和你的文件夹名称保持一致) : http://localhost:8080/cgi_app/cgi-bin/first.pl
-
成功