Want to request triggers a non-java applications deployed on tomcat, you need to use the Common Gateway Interface (CGI). Tomcat Servlet CGI provides support.
-
Modify web.xml
web.xml configuration file in the default annotated CGIServlet, only need to open the comment. Modify apache-tomcat-xxxx / conf / web.xml file can affect all deployed applications on the server. In addition, there are several configuration requires attention,
cgiPathPrefix: subordinates applications, location cgi script. tomcat will be looking at what the directory for all applications.
executable: program execution CGI scripts.
passShellEnvironment: the shell environment variables.
URL pattern: the practical application of webroot + / cgi-bin / *
1 <servlet> 2 <servlet-name>cgi</servlet-name> 3 <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class> 4 <init-param> 5 <param-name>cgiPathPrefix</param-name> 6 <param-value>WEB-INF/cgi</param-value> 7 </init-param> 8 <init-param> 9 <param-name>executable</param-name> 10 <param-value>C:\Anaconda3\python.exe</param-value> 11 </init-param> 12 <init-param> 13 <param-name>passShellEnvironment</param-name> 14 <param-value>true</param-value> 15 </init-param> 16 <load-on-startup>5</load-on-startup> 17 </servlet> 18 19 <servlet-mapping> 20 <servlet-name>cgi</servlet-name> 21 <url-pattern>/cgi-bin/*</url-pattern> 22 </servlet-mapping>
-
Modify context.xml
Modify apache-tomcat-xxxx / conf / context.xml file will affect all applications deployed on the server.
<Context privileged="true">
-
The python script to deploy a web application
Creating hello.py, put it in a web application test under the project, "WEB-INF / cgi" directory.
from os import * from cgi import * print('Hello')
-
Access program in the browser
http://localhost:8180/test/cgi-bin/hello.py
19-Dec-2019 14:39:55.232 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8109"] 19-Dec-2019 14:39:55.249 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 15210 ms 19-Dec-2019 14:40:04.408 INFO [http-nio-8180-exec-2] org.apache.catalina.servlets.CGIServlet$CGIRunner.run Bad header line [Hello]