【正文】
ccessful, 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 large and plex, they might want to use Enterprise JavaBeans (EJB) to encapsulate their business logic. So, they might switch to BEA WebLogic or Oracle9i AS. Again, none of their servlets or JSP pages have to be rewritten. Finally, if their project bees even bigger, they might move it off of their Linux box and onto an IBM mainframe running IBM WebSphere. But once again, none of their servlets or JSP pages have to be rewritten. 6. Secure One of the main sources of vulnerabilities in traditional CGI stems from the fact that the programs are often executed by generalpurpose operating system shells. So, the CGI programmer must be careful to filter out characters such as backquotes and semicolons that are treated specially by the shell. Implementing this precaution is harder than one might think, and weaknesses stemming from this problem are constantly being uncovered in widely used CGI libraries. A second source of problems is the fact that some CGI programs are processed by languages that do not automatically check array or string bounds. For example, in C and C++ it is perfectly legal to allocate a 100element array and then write into the 999th element, which is really some random part of program memory. So, programmers who forget to perform this check open up their system to deliberate or accidental buffer overflow attacks. Servlets suffer from neither of these problems. Even if a servlet executes a system call (., with or JNI) to invoke a program on the local operating system, it does not use a shell to do so. And, of course, array bounds checking and other memory protection features are a central part of the Java programming language. 7. Mainstream There are a lot of good technologies out there. But if vendors don39。 Servlet的工作是執(zhí)行 下面 的任務(wù),如圖 11所示 。 2. 讀取由瀏覽器發(fā)送的隱式請求數(shù)據(jù)。 3. 生成結(jié)果。即使它能夠做到這一 點(diǎn),為了安全上的考慮,我們也不希望讓它這么做。 這個文檔可以用各種格式發(fā)送,包括文本( HTML或 XML),二進(jìn)制( GIF圖 像 ),甚至可以 是 建立在其他底層格式之上的壓縮格式,如 gzip。但是,實(shí)際發(fā)送的數(shù)據(jù)有兩種:文檔本身,以及后臺的 HTTP信息。然而,許多情況下靜態(tài)的結(jié)果不能滿足要求,我們需要針對每個請求生成一個頁面。要記住,用戶提交兩種類型的數(shù)據(jù):顯示(即 HTML 表單的數(shù)據(jù))和隱式(即 HTTP請求的報(bào)頭)。 如果頁面需要根據(jù)每個具體的請求做出相應(yīng)的改變,當(dāng)然需要在請求發(fā)生時(shí)構(gòu)建響應(yīng)。 頁面中使用了來自公司數(shù)據(jù)庫或其他數(shù)據(jù)庫斷數(shù)據(jù)源的信息。從客戶端到 Web 層再到數(shù)據(jù)庫(三層結(jié)構(gòu)),要比從 applet 直接到數(shù)據(jù)庫(二層結(jié)構(gòu))更靈活,也更安全,而性能上的損失很少甚至沒有。而且,用于會話啟動協(xié)議服務(wù)器的 servlet API最近已經(jīng)被標(biāo)準(zhǔn)化(參見 servlet的這種用法尚不流行,在此,我們只論述 HTTP Servlet。而使用servlet, Java虛擬機(jī)會一直運(yùn)行,并用輕量級的 Java線程處理每個請求,而非重量級的操作系統(tǒng)進(jìn)程。最后,當(dāng) CGI 程序結(jié)束對請求的處理之后,程序結(jié)束。而在CGI 中,大部分工作都需要我們資金完成。多個 servlet 還可以共享數(shù)據(jù),從而易于實(shí)現(xiàn)數(shù)據(jù)庫連接共享和類似的資源共享優(yōu)化。實(shí)際上都直接或通過插件支持 servlet。 廉價(jià) 對于開發(fā)用的網(wǎng) 站、低容量或中等容量網(wǎng)站的部署,有大量免費(fèi)或極為廉價(jià)的 Web服務(wù)器可供選擇。例如, Marty 記錄了所有通過電子郵件向他發(fā)送問題的讀者的所在國。首先,這兩個國家都擁有大量訓(xùn)練有素的軟件開發(fā)人員。項(xiàng)目取得成功之后,他們可以轉(zhuǎn)移到性能更高、管理更容易,但需要付費(fèi)的服務(wù)器。同樣,他們的 servlet和 jsp沒有任何部分需要重寫。最后,如果他們的項(xiàng)目變得更龐大,他們或許將他從 Linux轉(zhuǎn)移到運(yùn)行 IBM WebSphere 的 IBM大型機(jī)上。實(shí)現(xiàn)這項(xiàng)預(yù)防措施的難度可能超出我們的想象,在廣泛應(yīng)用的CGI庫中,不斷發(fā)現(xiàn)由這類問題引發(fā)的弱點(diǎn)。 Servlet不存在這些問題。存在幾種低廉的插件,通過應(yīng)用這些插件,Microsoft IIS 和 Zeus 也同樣支持 servlet 和 jsp 技術(shù),它們運(yùn)行在 Windows,Unix/Linus, MacOS, VMS 和 IBM 大型機(jī)操作系統(tǒng)之上。但我們的立場是:服務(wù)器端 Java本非一項(xiàng)新的、為經(jīng)證實(shí)的技術(shù) 。 當(dāng)然,僅僅是流行并不能證明技術(shù)的優(yōu)越性。當(dāng)然,數(shù)組邊界的檢查以及其他內(nèi)存包含特性是 java編程語言的核心部分。例如,在 C和 C++中,可以分配一個 100個元素的數(shù)組,然后向第999個“元素”寫入數(shù)據(jù) —— 實(shí)際上 是程序內(nèi)存的隨機(jī)部分,這完全合法。 安全 傳統(tǒng) CGI程序中主要的漏洞來源之一就是, CGI程序常常由通過的操作系統(tǒng)外殼來執(zhí)行。因此,他們可以切換到 BEA WebLogic 或Oracle9i AS。如果他們 的項(xiàng)目變得更龐大,他們或許希望轉(zhuǎn)移到分布式環(huán)境。因此,從美國公司那里購買專用 Web服務(wù)器會消耗掉項(xiàng)目的大部分前期資金。