【正文】
al? you ask. The big deal is that XML quickly is being the global standard for inter and intraapplication munication. Passing data around in an XML format lets any other application that employs basic XML datahandling facilities use your application39。 圖 中間件的作用 ( 1) 讀取客戶(hù)發(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è)基于客戶(hù)發(fā)送的數(shù)據(jù)。但是,如果頁(yè)面周期性地改變,我們可以用兩種方式來(lái)處理它:周期性地在服務(wù)器上構(gòu)建新的頁(yè)面(和客戶(hù)請(qǐng)求無(wú)關(guān)),或者僅僅在用戶(hù)請(qǐng)求該頁(yè)面時(shí)再構(gòu)建。畢竟數(shù)據(jù)庫(kù)調(diào)用通常是對(duì)速度影響最大的步驟,因而,經(jīng)過(guò)中間層可以執(zhí)行高速緩存和連接共享。類(lèi)似地,應(yīng)用傳統(tǒng)的 CGI 技術(shù),如果存在對(duì)同一 CGI程序的 N 個(gè)請(qǐng)求,那么 CGI 程序的代碼會(huì)載入內(nèi)存 N次。另外,如果您已經(jīng)了解了 Java 編程語(yǔ)言,為什么還有學(xué)校 Perl 呢?您已經(jīng)承認(rèn)應(yīng)用 Java 技術(shù)編寫(xiě)的代碼要比 Visual Basic, VBScript 或 C++編寫(xiě)的代碼更可靠,且更易重用,為什么還 有倒退回去選擇那些語(yǔ)言來(lái)開(kāi)發(fā)服務(wù)器端的程序呢? 強(qiáng)大 Servlet 支持常規(guī) CGI 難以實(shí)現(xiàn)或根本不能實(shí)現(xiàn)的幾項(xiàng)功能。因此。 價(jià)格和可移植性在某種程度上是相互關(guān)聯(lián)的。 但是,使用 servlet 和 JSP,他們能夠從免費(fèi)的服務(wù)器開(kāi)始: Apache Tomcat。如果項(xiàng)目變得極為龐大,錯(cuò)綜復(fù)雜,他們或許希望使用Ent。其次,這兩個(gè)國(guó)家的貨幣對(duì)美元的匯率都極為不利。因此,通過(guò)使用 servelt 和 jsp,我們可以從免費(fèi)或廉價(jià)的服務(wù)器開(kāi)始,在項(xiàng)目獲得初步成功后,在移植到更高性能或高級(jí)管理工具的昂貴的服務(wù)器上。所有主要的 Web 服務(wù)器。 便利 Servelt 提供大量的基礎(chǔ)構(gòu)造,可以自動(dòng)分析和解碼 HTML 的表單數(shù)據(jù),讀取和設(shè)置 HTTP 報(bào)頭,處理 cookie,跟蹤會(huì)話,以及其他次類(lèi)高級(jí)功能。如果 CGI程序自身相對(duì)比較簡(jiǎn)短,那么啟動(dòng)進(jìn)程的開(kāi) 銷(xiāo)會(huì)占用大部分執(zhí)行時(shí)間。顯然,這樣很愚蠢;這種情況下,我們需要與數(shù)據(jù)庫(kù)進(jìn)行會(huì)話。 頁(yè)面由頻繁改變的數(shù)據(jù)導(dǎo)出。 動(dòng)態(tài)構(gòu)建網(wǎng)頁(yè)的原因 預(yù)先建立的文檔可以滿(mǎn)足客戶(hù)的許多請(qǐng)求,服務(wù)器無(wú)需調(diào)用 servlet 就可以處理這些請(qǐng)求。 ( 4) 向客戶(hù)發(fā)送顯式數(shù)據(jù)( 即文檔)。 HTTP 信息包括 cookie、瀏覽器所能識(shí)別的媒體類(lèi)型和壓縮模式等。 關(guān)鍵字 : JSP 技術(shù), Servlet, HTTP 服務(wù) Servlet 的功能 Servlets 是運(yùn)行在 Web 或應(yīng)用服務(wù)器上的 Java 程序,它是一個(gè)中間層,負(fù)責(zé)連接來(lái)自 Web瀏覽器或其他 HTTP客戶(hù) 程序的請(qǐng)求和 HTTP服務(wù)器上的數(shù)據(jù)庫(kù)或應(yīng)用程序。s features was also intentional. So JSP authors were given the option to add Java code into their vs. developerA final (and admirable) goal of JSP technology worth mentioning is that it seeks to establish clearly defined roles in the application development process. By ostensibly breaking content from presentation, JSP technology creates a clearer distinction between the designer and developer. The designer creates markup, using only standard HTML, WML, or whatever language is appropriate, and the developer writes code. Of course, many designers today have learned JavaScript, so it should e as no surprise that many of these same designers have begun to learn JSP coding. Often, instead of just doing pure markup, they encode a plete JSP page and hand it over to the developer. Then the usual tweaking takes place, and the developer puts the JSP page into place as a frontend for some portion of the overall application. The key, though, is that many designers do not learn JSP coding, so it must also be workable in that vs. XMLOne of the most significant disadvantages of JSP technology, and one of the most overlooked, is its inpatibility with XML. More precisely, and particularly in the HTML realm, JSP pages are not required to be XHTMLpatible. XHTML is a World Wide Web Consortium (W3C) specification that is now replacing HTML . XHTML defines the HTML tagset in terms of a wellformed XML document. For example, the br tag must be converted toto ensure XML pliance. (If this doesn39。s source code from the developer are off limits. Of course, this is an errorprone, dangerous way to operate. Once you39。 now we expect flashy graphics, moving images, colorcoordinated presentations that would look good in any room in the house, and speedy rendering to premiseToday, a decade beyond those fledgling Windows applications, we are still dealing with this huge shift in the presentation paradigm. The woeful Visual Basic and C programmers who remain now find themselves working either on backend systems or Windowsonly applications, or they have added a Webcapable language such as the Java language to their toolbox. An application that doesn39。t know what to display until you read the data that the user submits. Just remember that the user submits two kinds of data: explicit (., HTML form data) and implicit (., HTTP request headers). Either kind of input can be used to build the output page. In particular, it is quite mon to build a userspecific page based on a cookie value. 2. The Web page is derived from data that changes frequently. If the page changes for every request, then you certainly need to build the response at request time. If it changes only periodically, however, you could do it two ways: you could periodically build a new Web page on the server (independently of client requests), or you could wait and only build the page when the user requests it. The right approach depends on the situation, but sometimes it is more convenient to do the latter: wait for the user request. For example, a weather report or news headlines site might build the pages dynamically, perhaps returning a previously built page if that page is still up to date. 3. The Web page uses information from corporate databases or other serverside sources. If the information is in a database, you need serverside processing even if the client is using dynamic Web content such as an applet. Imagine using an applet by itself for a search engine site: Downloading 50 terabyte applet, please wait! Obviously, that is silly。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. 4. 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. 5. 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.