【正文】
二個(gè)來(lái)源是,一些 CGI 程序用不自動(dòng)檢查數(shù)組和字符串邊界的語(yǔ)言編寫而成。即使 servelt 執(zhí)行系統(tǒng)調(diào)用激活本地操作系統(tǒng)上的程序,它也不會(huì)用到外殼來(lái)完成這項(xiàng)任務(wù)。它們用在航空業(yè)、電子商務(wù)、在線銀行、 web 搜索引擎、門戶、大型金融網(wǎng)站、以及成百上千您日常光顧的其他網(wǎng)站。 。很多泛美的例子。 主流 雖然存在許多很好的技術(shù),但是,如果提供商助支持他們,或開發(fā)人員不知道如何使用這些技術(shù), 那么它們的優(yōu)點(diǎn)又如何體現(xiàn)呢? servelt 和 jsp 技術(shù)得到服務(wù)器提供商的廣泛支持,包括 Apache, Oracle, IBM, Sybase, BEA, Maromedia,Causho, Sun/iPla, New Atlanta, ATG, Fujitsu, Lutris, Silverstream, World Wide Web Consortinrm ,以及其他服務(wù)器。因而,如果程序員忘記執(zhí)行這項(xiàng)檢查,就會(huì)將系統(tǒng)暴露在蓄意或偶然的緩沖區(qū)溢出攻擊之下。因此 ,CGI 程序必須仔細(xì)地過(guò)濾掉那些可能被外殼特殊處理的字符,如反引導(dǎo)和分號(hào)。同樣,不 需要對(duì) servlet 和 jsp 做出更改。沒(méi)有問(wèn)題:他們可以轉(zhuǎn)而使用 Macromedia JRun Professional,該服務(wù)器支持分布式應(yīng)用。 但是,使用 servlet 和 JSP,他們能夠從免費(fèi)的服務(wù)器開始: Apache Tomcat。 那么,為什么印度和菲律賓都對(duì)這項(xiàng)技術(shù)著呢感興趣呢?我們推測(cè)答案可能分兩部分。 價(jià)格和可移植性在某種程度上是相互關(guān)聯(lián)的。他們是 java2 平臺(tái)企業(yè)版的一部分,所以對(duì) servlet 的支持越來(lái)越普遍。因此。 Servelt 還能維護(hù)請(qǐng)求之間的信息 ,使得諸如會(huì)話跟蹤和計(jì)算結(jié)果緩存等技術(shù)變得更為簡(jiǎn)單。另外,如果您已經(jīng)了解了 Java 編程語(yǔ)言,為什么還有學(xué)校 Perl 呢?您已經(jīng)承認(rèn)應(yīng)用 Java 技術(shù)編寫的代碼要比 Visual Basic, VBScript 或 C++編寫的代碼更可靠,且更易重用,為什么還有倒退回去選擇那些語(yǔ)言來(lái)開發(fā)服務(wù)器端的程序呢? 強(qiáng)大 Servlet 支持常規(guī) CGI 難以實(shí)現(xiàn)或根本不能實(shí)現(xiàn)的幾項(xiàng)功能。這種方式難以緩存計(jì)算結(jié)果,保持?jǐn)?shù)據(jù)庫(kù)連接打開,或是執(zhí)行依靠持續(xù)性數(shù)據(jù)的其他優(yōu)化。類似地,應(yīng)用傳統(tǒng)的 CGI 技術(shù),如果存在對(duì)同一 CGI 程序的 N 個(gè)請(qǐng)求,那么 CGI 程序的代碼會(huì)載入內(nèi)存 N 次。 Servlet 相對(duì)于 “ 傳統(tǒng) ” CGI 的優(yōu)點(diǎn) 和傳統(tǒng) CGI 及許多類 CGI 技術(shù)相比, Java servelt 效率更高、更易用、更強(qiáng)大、更容易移植、更安全、也更廉價(jià)。畢竟數(shù)據(jù)庫(kù)調(diào)用通常是對(duì)速度影響最大的步驟,因而,經(jīng)過(guò)中間層可以執(zhí)行高速緩存和連接共享。 如果數(shù)據(jù)存儲(chǔ)在數(shù)據(jù)庫(kù)中,那么,即使客戶端使用動(dòng)態(tài) Web 內(nèi)容,比如applet,我們依舊需要執(zhí)行服務(wù)器端處理。但是,如果頁(yè)面周期性地改變,我們可以用兩 種方式來(lái)處理它:周期性地在服務(wù)器上構(gòu)建新的頁(yè)面(和客戶請(qǐng)求無(wú)關(guān)),或者僅僅在用戶請(qǐng)求該頁(yè)面時(shí)再構(gòu)建。兩種輸入都可用來(lái)構(gòu)建輸出頁(yè)面。實(shí)時(shí)構(gòu)建頁(yè)面的 理由有很多種: 網(wǎng)頁(yè)基于客戶發(fā)送的數(shù)據(jù)。同樣,兩種數(shù)據(jù)對(duì)開發(fā)來(lái)說(shuō)都式至關(guān)重要的。但是,到目前為止, HTML 式最常用的格式,故而 servelt 和 JSP 的重要任務(wù)之一就式將結(jié)果包裝到 HTML 中。對(duì)應(yīng)大多數(shù)其他應(yīng)用程序,也存在類似的問(wèn)題。 這個(gè)過(guò)程可能需要訪問(wèn)數(shù)據(jù)庫(kù)、執(zhí)行 RMI 或 EJB 調(diào)用、調(diào)用 Web 服務(wù),或者直接計(jì)算得出對(duì)應(yīng)的響應(yīng)。 圖 中顯示了一條從客戶端到 Web 服務(wù)器的單箭頭,但實(shí)際上從客戶端傳送到 Web 服務(wù)器的數(shù)據(jù)有兩種,它們分別為用戶在表單中輸入的顯式數(shù)據(jù),以及后臺(tái)的 HTTP 信息。 圖 中間件的作用 ( 1) 讀取客戶發(fā)送的顯式數(shù)據(jù)。 see so industry support for servlets is being even more pervasive. 5. Inexpensive A number of free or very inexpensive Web servers are good for development use or deployment of low or mediumvolume Web sites. Thus, with servlets and JSP you can start with a free or inexpensive server and migrate to more expensive servers with highperformance capabilities or advanced administration utilities only after your project meets initial success. This is in contrast to many of the other CGI alternatives, which require a significant initial investment for the purchase of a proprietary package. Price and portability are somewhat connected. For example, Marty tries to keep track of the countries of readers that send him questions by . India was near the top of the list, probably 2 behind the . Marty also taught one of his JSP and servlet training courses (see in Manila, and there was great interest in servlet and JSP technology there. Now, why are India and the Philippines both so interested? We surmise that the answer is twofold. First, both countries have large pools of welleducated software developers. Second, both countries have (or had, at that time) highly unfavorable currency exchange rates against the . dollar. So, buying a specialpurpose Web server from a . pany consumed a large part of early project funds. But, with servlets and JSP, they could start with a free server: Apache Tomcat (either standalone, embedded in the regular Apache Web server, or embedded in Microsoft IIS). Once the project starts to bee successful, they could move to a server like Caucho Resin that had higher performance and easier administration but that is not free. But none of their servlets or JSP pages have to be rewritten. If their project bees even larger, they might want to move to a distributed (clustered) environment. No problem: they could move to Macromedia JRun Professional, which supports distributed applications (Web farms). Again, none of their servlets or JSP pages have to be rewritten. If the project bees quite lar