在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
当然,其实PHP本身也支持CGI方式的使用,所以就自己动手试了一试(在Windows操作系统上):先按照附文的做法让Tomcat支持CGI,然后再改web.xml,在servlet-name为cgi的一段配置中加上:
<init-param>
<param-name>executable</param-name> <param-value>php</param-value> </init-param> 但是如果对PHP文件不加任何改动的话,可能会发现什么输出都没有。需要在PHP文件头部加一行,输出两个回车:
echo "\n\n";
但这样配置,PHP(4.1.0以上版本)中$_REQUEST、$_GET、$_POST等变量就无法用了,只能从服务器变量或环境变量中获取QueryString了:$_SERVER["QUERY_STRING"]、$_ENV["QUERY_STRING"]。也许不支持表单的POST提交了……具体还没试过。 由于对Tomcat不熟悉,所以这些只是在现在方法上的小修小补,可能有好的做法,还希望大家不吝指教! 附: Using CGI Scripts with Tomcat Tomcat is primarily meant to be a servlet/JSP container, but it has many capabilities rivalling a traditional web server. One of these is support for the Common Gateway Interface (CGI), which provides a means for running an external program in response to a browser request, typically to process a web-based form. CGI is called "common" because it can invoke programs in almost any programming or scripting language: Perl, Python, awk , Unix shell scripting, and even Java are all supported options. However, you probably wouldn't run a Java application as a CGI due to the start-up overhead; elimination of this overhead was what led to the original design of the servlet specification. Servlets are almost always more efficient than CGIs because you're not starting up a new operating-system-level process every time somebody clicks on a link or button.
Tomcat includes an optional CGI servlet that allows you to run legacy CGI scripts; the assumption is that most new back-end processing will be done by user-defined servlets and JSPs. To enable Tomcat's CGI servlet, you must do the following:
|
2022-08-17
2022-09-18
2022-08-17
2022-07-08
2022-08-15
请发表评论