亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

讓Tomcat支持PHP

系統 2245 0
  在負責一個采用JSP動態網頁技術的網站時,剛好手頭有PHP寫的一部分功能,所以就很直接地想到讓Tomcat支持PHP。Tomcat也是Apache出的,難道就只支持JSP嗎?到底能否在Tomcat上用PHP呢?上網搜索了一番,很快有了第一個問題的答案:Tomcat可以支持CGI,如Perl(具體設置見附文)。但繼續搜索,卻遲遲無法找到讓Tomcat使用PHP的方法,一般都是采取裝Apache和Tomcat共存的方法來搭建所謂的支持PHP+JSP的Web平臺。
  當然,其實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安裝路徑加入Path,這樣Tomcat就能運行到PHP.exe了。重啟Tomcat后,在WEB-INF目錄下新建一個cgi目錄,把php文件放在這里,然后訪問時用虛擬映射出來的cgi-bin目錄來訪問這些PHP文件。
  但是如果對PHP文件不加任何改動的話,可能會發現什么輸出都沒有。需要在PHP文件頭部加一行,輸出兩個回車:
echo? " \n\n " ;
原因不太清楚。可能在等待Content-type輸入,或是Perl的cgi程序風格。
  但這樣配置,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:
  1. Rename the file servlets-cgi.renametojar (found in CATALINA_HOME/server/lib/ ) to servlets-cgi.jar , so that the servlet that processes CGI scripts will be on Tomcat's CLASSPATH .
  2. In Tomcat's CATALINA_BASE/conf/web.xml file, uncomment the definition of the servlet named cgi (this is around line 241 in the distribution).
  3. Also in Tomcat's web.xml , uncomment the servlet mapping for the cgi servlet (around line 299 in the distributed file). Remember, this specifies the HTML links to the CGI script.
  4. Either place the CGI scripts under the WEB-INF/cgi directory (remember that WEB-INF is a safe place to hide things that you don't want the user to be able to view, for security reasons), or place them in some other directory within your context and adjust the cgiPathPrefix initialization parameter of the CGIServlet to identify the directory containing the files. This specifies the actual location of the CGI scripts, which typically will not be the same as the URL in the previous step.
  5. Restart Tomcat, and your CGI processing should now be operational.
The default directory for the servlet to locate the actual scripts is WEB-INF/cgi . As has been noted, the WEB-INF directory is protected against casual snooping from browsers, so this is a good place to put CGI scripts, which may contain passwords or other sensitive information. For compatibility with other servers, though, you may prefer to keep the scripts in the traditional directory, /cgi-bin , but be aware that files in this directory may be viewable by the curious web surfer. Also, on Unix, be sure that the CGI script files are executable by the user under which you are running Tomcat.

讓Tomcat支持PHP


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久久一区不卡中文字幕 | 久热中文字幕在线观看 | 国产99福利视频在线 | 四虎精品影视 | 日本aa在线观看 | 日本一级毛片视频网站 | 国产精品一久久香蕉产线看 | 综合视频网| 欧美亚洲国产另类 | 免费国产一区二区三区四区 | 特级a毛片 | 国产在线公开视频 | 亚洲一区二区三区麻豆 | 香蕉久久久 | 成人午夜视频在线播放 | 深夜成人 | 欧美三级在线观看不卡视频 | 特黄a大片免费视频 | 香蕉大黄香蕉在线观看 | 国产高清自拍视频 | 欧美做爰xxxⅹ性欧 欧美做爰xxxⅹ在线视频hd | 欧美日韩中文一区二区三区 | 色综合九九 | 爱爱一级视频 | 久久精品国产清白在天天线 | 亚洲一级黄色 | 久久这里只有精品国产 | 久久精品中文字幕首页 | 国产精品一级 | 草的我好爽的网站 | 美女色影院 | 男人天堂网在线视频 | 好吊妞视频998www | 欧美一区二区手机在线观看视频 | 特级毛片在线大全免费播放 | 国产精品九九久久一区hh | 成人亚洲欧美 | 美女超爽久久久久网站 | 天天干天天噜 | 在线免费观看一区二区三区 | 久久久久亚洲香蕉网 |