引自 http://blog.csdn.net/peihaozhu/article/details/50590418python
1、打開web.xml文件web
1 <servlet> 2 <servlet-name>cgi</servlet-name> 3 <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class> 4 <init-param> 5 <param-name>debug</param-name> 6 <param-value>0</param-value> 7 </init-param> 8 <init-param> 9 <param-name>passShellEnvironment</param-name> 10 <param-value>true</param-value> 11 </init-param> 12 <init-param> 13 <param-name>cgiPathPrefix</param-name> 14 <param-value>WEB-INF/cgi-bin</param-value> 15 </init-param> 16 <init-param> 17 <param-name>executable</param-name> 18 <param-value>C:/Users/LENOVO/AppData/Local/Programs/Python/Python36/python.exe</param-value> 19 </init-param> 20 <load-on-startup>5</load-on-startup> 21 </servlet>
1 <servlet-mapping> 2 <servlet-name>cgi</servlet-name> 3 <url-pattern>/cgi-bin/*</url-pattern> 4 </servlet-mapping>
2、打開context.xml,添加:privileged=」true」apache
1 <Context privileged="true"> 2 3 <!-- Default set of monitored resources --> 4 <WatchedResource>WEB-INF/web.xml</WatchedResource> 5 6 <!-- Uncomment this to disable session persistence across Tomcat restarts --> 7 <!-- 8 <Manager pathname="" /> 9 --> 10 11 <!-- Uncomment this to enable Comet connection tacking (provides events 12 on session expiration as well as webapp lifecycle) --> 13 <!-- 14 <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /> 15 --> 16 17 </Context>
3、瀏覽器中打開 http://localhost:8081/python_cgi/cgi-bin/hello.py瀏覽器