Pre-installation requirements
1. Java
2. Python
steps
1. Download latest version of Tomcat (Tomcat 7) from
http://tomcat.apache.org/download-70.cgi
2. After successful installation of tomcat modify the web.xml file in the <TOMCAT_HOME>\conf\folder ( eg: C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf)
uncomment the cgi servlet and its mapping
<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>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>
3. Add an servlet parameter "passShellEnvironment" and set it to “true” (
"force" the environment variables to be passed)
<init-param>
<param-name>passShellEnvironment</param-name>
<param-value>true</param-value>
</init-param>
4. Add an servlet parameter "executable"
<init-param>
<param-name>executable</param-name>
<param-value>C:\Python27\python.exe</param-value>
</init-param>
so the overall cgi servlet in web.xml is given below
<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>C:\Python27\python.exe</param-value>
</init-param>
<init-param>
<param-name>passShellEnvironment</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
5. Modify <TOMCAT_HOME>\conf\context.xml to add a property on <Context>:
<Context privileged="true">
...
</Context>
6. Create a folder say "test" in <TOMCAT_HOME>\webapps directory . It is the root folder for your application
7. create a WEB-INF folder inside the root folder (test) and create a cgi folder inside WEB-INF folder
8. Create a python CGI script and put in in <TOMCAT_HOME>\webapps\test\WEB-INF\cgi\
hello.py
print "Content-type: text/html\n\n";
print "Hello, world!\n"
9. start the tomcat server and browse the url
http://localhost:8080/test/cgi-bin/hello.py
Configure Tomcat 7 to run Python CGI scripts in windows(Win7系统配置tomcat服务器,使用python进行cgi编程)
Posted 潘彬
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Configure Tomcat 7 to run Python CGI scripts in windows(Win7系统配置tomcat服务器,使用python进行cgi编程)相关的知识,希望对你有一定的参考价值。
以上是关于Configure Tomcat 7 to run Python CGI scripts in windows(Win7系统配置tomcat服务器,使用python进行cgi编程)的主要内容,如果未能解决你的问题,请参考以下文章
tomcat启动报错javax.servlet.ServletException: It is not allowed to configure supportsCredentials=[true]
How to run Tomcat without root privileges? 常规用户使用tomcat的80端口
Tomcat启动报错:This file is needed to run this program
Maven启动tomcat7:run运行异常:org.apache.catalina.LifecycleException: Failed to start component
Cannot find tomcat目录/bin/setclasspath.sh This file is needed to run this program
IntelliJ运行下载的Servlet时报错 Error running Tomcat 8.5.8: Unable to open debugger port (127.0.0.1:49551):