【正文】
但我們的立場是:服務器端Java本非一項新的、未經(jīng)證實的技術(shù)。存在幾種低廉的插件,通過應用這些插件,Microsoft IIS和Zeus也同樣支持servlet和jsp技術(shù),它們運行在Windows,Unix/Linus,MacOS,VMS,和IBM大型機操作系統(tǒng)之上。Servelt不存在這些問題。實現(xiàn)這項預防措施的難度可能超出我們的想象,在廣泛應用的CGI庫中,不斷發(fā)現(xiàn)由這類問題引發(fā)的弱點。最后,如果他們的項目變得更龐大,他們或許將他從Linux轉(zhuǎn)移到運行IBM WebSphere的IBM大型機上。同樣,他們的servelt和jsp沒有任何部分需要重寫。項目取得成功之后,他們可以轉(zhuǎn)移到性能更高、管理更容易,但需要付費的服務器。首先,這兩個國家都擁有大量訓練有素的軟件開發(fā)人員。例如,Marty記錄了所有通過電子郵件向他發(fā)送問題的讀者的所在國?!×畠r對于開發(fā)用的網(wǎng)站、低容量或中等容量網(wǎng)站的部署,有大量免費或極為廉價的Web服務器可供選擇。為Macromedia JRun編寫的servlet,可以不經(jīng)過任何修改地在Apache Tomcat,Microsoft Internet Information Server,IBM WebSphere ?!】梢浦残許ervelt使用Java編程語言,并且遵循標準的API。Servlet能夠直接于Web服務器對話,而常規(guī)的CGI程序做不到這一點,至少在不使用服務器專有API的情況下是這樣。然而,servelt會一直停留在內(nèi)存中(即使請求處理完畢),因而可以直接存儲客戶請求之間的任意復雜數(shù)據(jù)。同樣的情況,如果使用servlet則啟動N個線程,單僅僅載入servlet類的單一副本。 效率 應用傳統(tǒng)的CGI,針對每個HTTP請求都用啟動一個新的進程。例如,servlet能夠嵌入到FTP或郵件服務器中,擴展他們的功能。顯然,這樣很愚蠢;這種情況下,我們需要與數(shù)據(jù)庫進行會話。具體應該采用哪種方式要根據(jù)具體情況而定,但后一種方式常常更為方便,因為它只需簡單地等待用戶的請求。兩種輸入都可用來構(gòu)建輸出頁面。然而,許多情況下靜態(tài)的結(jié)果不能滿足要求,我們需要針對每個請求生成一個頁面。但是,實際發(fā)送的數(shù)據(jù)有兩種:文檔本身,以及后臺的HTTP信息。因此,我們需要Web中間層從HTTP流中提取輸入數(shù)據(jù),與應用程序會話,并將結(jié)果嵌入到文檔中。實際的數(shù)據(jù)可能存儲在關(guān)系型數(shù)據(jù)庫中。 讀取由瀏覽器發(fā)送的隱式請求數(shù)據(jù),但實際上從客戶端傳送到Web服務器的數(shù)據(jù)有兩種,它們分別為用戶在表單中輸入的顯式數(shù)據(jù),以及后臺的HTTP信息。關(guān)鍵字:JSP技術(shù);Servlet;HTTP服務1 Servlet的功能Servlet是運行在Web或應用服務器上的Java程序,它是一個中間層,負責連接來自Web瀏覽器或其他HTTP客戶程序的請求和HTTP服務器上的數(shù)據(jù)庫或應用程序。re already convinced that Java technology makes for more reliable and reusable code than does Visual Basic, VBScript, or C++. Why go back to those languages for serverside programming? PowerfulServlets support several capabilities that are difficult or impossible to acplish with regular CGI. Servlets can talk directly to the Web server, whereas regular CGI programs cannot, at least not without using a serverspecific API. Communicating with the Web server makes it easier to translate relative URLs into concrete path names, for instance. Multiple servlets can also share data, making it easy to implement database connection pooling and similar resourcesharing optimizations. Servlets can also maintain information from request to request, simplifying techniques like session tracking and caching of previous putations. PortableServlets are written in the Java programming language and follow a standard API. Servlets are supported directly or by a plugin on virtually every major Web server. Consequently, servlets written for, say, Macromedia JRun can run virtually unchanged on Apache Tomcat, Microsoft Internet Information Server (with a separate plugin), IBM WebSphere, iPlanet Enterprise Server, Oracle9i AS, or StarNine WebStar. They are part of the Java 2 Platform, Enterprise Edition (J2EE。t talk directly to the database. Even if it could, for security reasons, you probably would not want it to. The same argument applies to most other need the Web middle layer to extract the results inside a document. Send the explicit data (., the document) to the client.This document can be sent in a variety of formats, including text (HTML or XML), binary (GIF images), or even a pressed format like gzip that is layered on top of some other underlying format. But, HTML is by far the most mon format, so an important servlet/JSP task is to wrap the results inside of HTML. Send the implicit HTTP response data.Figure 11 shows a single arrow going from the Web middle layer (the servlet or JSP page) to the client. But, there are really two varieties of data sent: the document itself and the behindthescenes HTTP information. Again, both varieties are critical to effective development. Sending HTTP response data involves telling the browser or other client what type of document is being returned (., HTML), setting cookies and caching parameters, and other such tasks. 2 Why Build Web Pages Dynamically?many client requests can be satisfied by prebuilt documents, and the server would handle these requests without invoking servlets. In many cases, however, a static result is not sufficient, and a page needs to be generated for each request. There are a number of reasons why Web pages need to be built onthe