【正文】
) 生成結(jié)果。 這個(gè)文檔可以用各種格式發(fā)送,包括文本( HTML或 XML),二進(jìn)制( GIF 圖),甚至可以式建立在其他底層格式之上的壓縮格式,如 gzip。然而,許多情況下靜態(tài)的結(jié)果不能滿足要求,我們需要針對(duì)每個(gè)請(qǐng)求生成一個(gè)頁(yè)面。 如果頁(yè)面需要根據(jù)每個(gè)具體的請(qǐng)求做出相應(yīng)的改變,當(dāng)然需要在請(qǐng)求發(fā)生時(shí)構(gòu)建響應(yīng)。從客戶端到 Web 層再到數(shù)據(jù)庫(kù)(三層結(jié)構(gòu)),要比從 applet 直接到數(shù)據(jù)庫(kù)(二層結(jié)構(gòu))更靈活,也更安全,而性能上的損失很少甚至沒(méi)有。而使用 servelt, Java虛擬機(jī)會(huì)一直運(yùn)行,并用輕量級(jí)的 Java 線程處理每個(gè)請(qǐng)求,而非重量級(jí)的操作系統(tǒng)進(jìn)程。而在 CGI 中,大部分工作都需要我們資金完成。實(shí)際上都直接或通過(guò)插件支持 servlet。這與其他 CGI 方案形成鮮明的對(duì)比,這些 CGI 方案在初期都需要為購(gòu)買專利軟件包投入大量的資金。因此,從美國(guó)公司那里購(gòu)買專用 Web 服務(wù)器會(huì)消耗掉項(xiàng)目的大部分前期資金。因此,他們可以切換到 BEA WebLogic 或 Oracle9i AS。例如,在 C 和 C++中,可以分配一個(gè) 100 個(gè)元素的數(shù)組,然后向第 999個(gè) “元素 “寫入數(shù)據(jù) ——實(shí)際上是程序內(nèi)存的隨機(jī)部分,這完全合法。 當(dāng)然,僅僅是流行并不能證明技術(shù)的優(yōu)越性。存在幾種低廉的插件,通過(guò)應(yīng)用這些插件, Microsoft IIS 和 Zeus 也同樣支持 servlet 和 jsp 技 術(shù) , 它 們運(yùn) 行 在 Windows ,Unix/Linus,MacOS,VMS,和 IBM 大型機(jī)操作系統(tǒng)之上。實(shí)現(xiàn)這項(xiàng)預(yù)防措施的難度可能超出我們的想象,在廣泛應(yīng)用的 CGI 庫(kù)中,不斷發(fā)現(xiàn)由這類問(wèn)題引發(fā)的弱點(diǎn)。同樣,他們的 servelt 和 jsp 沒(méi)有任何部分需要重寫。首先,這兩個(gè)國(guó)家都擁有大量訓(xùn)練有素的軟件開發(fā)人員。 廉價(jià) 對(duì)于開發(fā)用的網(wǎng)站、低容量或中等容量網(wǎng)站的部署,有大量免費(fèi)或極為廉價(jià)的Web 服務(wù)器可供選擇。 可移植性 Servelt 使用 Java 編程語(yǔ)言,并且遵循標(biāo)準(zhǔn)的 API。然而, servelt 會(huì)一直停留在內(nèi)存中(即使請(qǐng)求處理完畢),因而可以直接存儲(chǔ)客戶請(qǐng)求之間的任意復(fù)雜數(shù)據(jù)。 效率 應(yīng)用傳統(tǒng)的 CGI,針對(duì)每個(gè) HTTP 請(qǐng)求都用啟動(dòng)一個(gè)新的進(jìn)程。想象以下,如果一個(gè)搜索引擎網(wǎng)站完全使用 applet,那么用戶將會(huì)看到: “正在下載 50TB 的 applet,請(qǐng)等待! ”?;?cookie 值針對(duì)具體用戶構(gòu)建頁(yè)面的情況尤其普遍。 HTTP 響應(yīng)數(shù)據(jù)的發(fā)送過(guò)程涉及告知瀏覽器或其他客戶程序所返回文檔的類型(如 HTML),設(shè)置 cookie 和緩存參數(shù),以及其他類似的任務(wù)。因此,我們需要 Web 中間層從 HTTP流中提取輸入數(shù)據(jù),與應(yīng)用程序會(huì)話,并將結(jié)果嵌入到文檔中。兩種數(shù)據(jù)都很重要。t know how to use them, what good are they? Servlet and JSP technology is supported by servers from Apache, Oracle, IBM, Sybase, BEA, Macromedia, Caucho, Sun/iPla, New Atlanta, ATG, Fujitsu, Lutris, Silverstream, the World Wide Web Consortium (W3C), and many others. Several lowcost plugins add support to Microsoft IIS and Zeus as well. They run on Windows, Unix/Linux, MacOS, VMS, and IBM mainframe operating systems. They are the single most popular application of the Java programming language. They are arguably the most popular choice for developing medium to large Web applications. They are used by the airline industry (most United Airlines and Delta Airlines Web sites), emerce (), online banking (First USA Bank, Banco Popular de Puerto Rico), Web search engines/portals (), large financial sites (American Century Investments), and hundreds of other sites that you visit every day. Of course, popularity alone is no proof of good technology. Numerous counterexamples abound. But our point is that you are not experimenting with a new and unproven technology when you work with serverside Java. Servlet 和 JSP 技術(shù)簡(jiǎn)述 Nagle and Wiegley, Aug. 2020, 953 – 958. 摘要: Servlet 程序在服務(wù)器端運(yùn)行,動(dòng)態(tài)地生成 Web 頁(yè)面與傳統(tǒng)的 CGI 和許多其他類似 CGI 的技術(shù)相比, Java Servlet 具有更高的效率,更容易使用,功能更強(qiáng)大,具有更好的可移植性,更節(jié)省投 資。t speak HTTP or return results in HTML, so the Web browser can39。 you need to talk to the database. Going from the client to the Web tier to the database (a threetier approach) instead of from an applet directly to a database (a twotier approach) provides increased flexibility and security with little or no performance penalty. After all, the database call is usually the ratelimiting step, so going through the Web server does not slow things down. In fact, a threetier approach is often faster because the middle tier can perform caching and connection pooling. In principle, servlets are not restricted to Web or application servers that handle HTTP requests but can be used for other types of servers as well. For example, servlets could be embedded in FTP or mail servers to extend their functionality. And, a servlet API for SIP (Session Initiation Protocol) servers was recently standardized (see In practice, however, this use of servlets has not caught on, and we39。 圖 中間件的作用 ( 1) 讀取客戶發(fā)送的顯式數(shù)據(jù)。 這個(gè)過(guò)程可能需要訪問(wèn)數(shù)據(jù)庫(kù)、執(zhí)行 RMI 或 EJB調(diào)用、調(diào)用 Web 服務(wù),或者直接計(jì)算得出對(duì)應(yīng)的響應(yīng)。但是,到目前為止, HTML式最常用的格式,故而 servelt 和 JSP 的重要任務(wù)之一就式將結(jié)果包裝到 HTML中。實(shí)時(shí)構(gòu)建頁(yè)面的理由有很多種: 網(wǎng)頁(yè)基于客戶發(fā)送的數(shù) 據(jù)。但是,如果頁(yè)面周期性地改變,我們可以用兩種方式來(lái)處理它:周期性地在服務(wù)器上構(gòu)建新 的頁(yè)面(和客戶請(qǐng)求無(wú)關(guān)),或者僅僅在用戶請(qǐng)求該頁(yè)面時(shí)再構(gòu)建。畢竟數(shù)據(jù)庫(kù)調(diào)用通常是對(duì)速度影響最大的步驟,因而,經(jīng)過(guò)中間層可以執(zhí)行