欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

讓Tomcat支持PHP

系統(tǒng) 1992 0
  在負(fù)責(zé)一個(gè)采用JSP動(dòng)態(tài)網(wǎng)頁(yè)技術(shù)的網(wǎng)站時(shí),剛好手頭有PHP寫(xiě)的一部分功能,所以就很直接地想到讓Tomcat支持PHP。Tomcat也是Apache出的,難道就只支持JSP嗎?到底能否在Tomcat上用PHP呢?上網(wǎng)搜索了一番,很快有了第一個(gè)問(wèn)題的答案:Tomcat可以支持CGI,如Perl(具體設(shè)置見(jiàn)附文)。但繼續(xù)搜索,卻遲遲無(wú)法找到讓Tomcat使用PHP的方法,一般都是采取裝Apache和Tomcat共存的方法來(lái)搭建所謂的支持PHP+JSP的Web平臺(tái)。
  當(dāng)然,其實(shí)PHP本身也支持CGI方式的使用,所以就自己動(dòng)手試了一試(在Windows操作系統(tǒng)上):先按照附文的做法讓Tomcat支持CGI,然后再改web.xml,在servlet-name為cgi的一段配置中加上:
???? < init-param >
????????
< param-name > executable </ param-name >
????????
< param-value > php </ param-value >
????
</ init-param >
并把PHP安裝路徑加入Path,這樣Tomcat就能運(yùn)行到PHP.exe了。重啟Tomcat后,在WEB-INF目錄下新建一個(gè)cgi目錄,把php文件放在這里,然后訪問(wèn)時(shí)用虛擬映射出來(lái)的cgi-bin目錄來(lái)訪問(wèn)這些PHP文件。
  但是如果對(duì)PHP文件不加任何改動(dòng)的話,可能會(huì)發(fā)現(xiàn)什么輸出都沒(méi)有。需要在PHP文件頭部加一行,輸出兩個(gè)回車:
echo? " \n\n " ;
原因不太清楚。可能在等待Content-type輸入,或是Perl的cgi程序風(fēng)格。
  但這樣配置,PHP(4.1.0以上版本)中$_REQUEST、$_GET、$_POST等變量就無(wú)法用了,只能從服務(wù)器變量或環(huán)境變量中獲取QueryString了:$_SERVER["QUERY_STRING"]、$_ENV["QUERY_STRING"]。也許不支持表單的POST提交了……具體還沒(méi)試過(guò)。
  由于對(duì)Tomcat不熟悉,所以這些只是在現(xiàn)在方法上的小修小補(bǔ),可能有好的做法,還希望大家不吝指教!

附:
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


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

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

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 久久99爱re热6在线播放 | 久久6国产| 精品视频一区二区三区在线观看 | 四虎4hutv永久在线影院 | 一级毛片免费看 | 亚洲 日本 欧美 日韩精品 | 欧美aaa级片 | 日韩在线视频一区 | 国产在线中文字幕 | 九九热线有精品视频99 | 99草在线| 免费国产精品视频在线 | 爱爱视频在线观看 | 国产精品拍拍拍福利在线观看 | 91久久精品国产91久久 | 久久综合九色综合91 | 日韩精品视频在线免费观看 | 亚洲一区二区三区在线免费观看 | 日韩在线视频一区 | 一级黄毛片| 欧美伊人 | 人人做人人爽人人爱 | 久久天天拍天天爱天天躁 | 日日干干夜夜 | 综合电影网 | 成人做爰视频免费 | 日韩久久精品电影 | 国产亚洲精品久久久极品美女 | 亚洲第一黄色网址 | 高清一区二区亚洲欧美日韩 | 亚洲国内精品 | 精品欧美一区二区三区久久久 | 亚洲一区国产 | 日韩欧美一区二区视频 | 国产精品一二三区 | y4480午夜66| 亚欧乱色一区二区三区 | 五月婷六月婷婷 | 免费无码一区二区三区A片18 | 国产拳头交一区二区 | 亚洲精品一区二区三区在线看 |