Servlet程序畢業(yè)論文外文翻譯.doc_第1頁(yè)
Servlet程序畢業(yè)論文外文翻譯.doc_第2頁(yè)
Servlet程序畢業(yè)論文外文翻譯.doc_第3頁(yè)
Servlet程序畢業(yè)論文外文翻譯.doc_第4頁(yè)
Servlet程序畢業(yè)論文外文翻譯.doc_第5頁(yè)
免費(fèi)預(yù)覽已結(jié)束,剩余1頁(yè)可下載查看

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、.譯文Servlet程序在服務(wù)器端運(yùn)行,動(dòng)態(tài)地生成Web頁(yè)面與傳統(tǒng)的CGI和許多其他類似CGI的技術(shù)相比,Java Servlet具有更高的效率,更容易使用,功能更強(qiáng)大,具有更好的可移植性,更節(jié)省投資。Servlet是運(yùn)行在Web或應(yīng)用服務(wù)器上的Java程序,它是一個(gè)中間層,負(fù)責(zé)連接來(lái)自Web瀏覽器或其他HTTP客戶程序的請(qǐng)求和HTTP服務(wù)器上的數(shù)據(jù)庫(kù)或應(yīng)用程序。Servlet的工作是執(zhí)行西門的任務(wù),如圖1-1所示 。圖1-1Web中間件的作用圖1-1中顯示了一條從客戶端到Web服務(wù)器的單箭頭,但實(shí)際上從客戶端傳送到Web服務(wù)器的數(shù)據(jù)有兩種,它們分別為用戶在表單中輸入的顯式數(shù)據(jù),以及后臺(tái)的HT

2、TP信息。兩種數(shù)據(jù)都很重要。HTTP信息包括Cookie、瀏覽器所能識(shí)別的媒體類型和壓縮模式等。這個(gè)過(guò)程可能需要訪問(wèn)數(shù)據(jù)庫(kù)、執(zhí)行RMI或EJB調(diào)用、調(diào)用Web服務(wù),或者直接計(jì)算得出對(duì)應(yīng)的響應(yīng)。實(shí)際的數(shù)據(jù)可能存儲(chǔ)在關(guān)系型數(shù)據(jù)庫(kù)中。該數(shù)據(jù)庫(kù)可能不理解HTTP,或者不能返回HTML形式的結(jié)果,所有Web瀏覽器不能直接與數(shù)據(jù)庫(kù)進(jìn)行會(huì)話。即使它能夠做到這一點(diǎn),為了安全上的考慮,我們也不希望讓它這么做。對(duì)應(yīng)大多數(shù)其他應(yīng)用程序,也存在類似的問(wèn)題。因此,我們需要Web中間層從HTTP流中提取輸入數(shù)據(jù),與應(yīng)用程序會(huì)話,并將結(jié)果嵌入到文檔中。這個(gè)文檔可以用各種格式發(fā)送,包括文本(HTML或XML),二進(jìn)制(GIF

3、圖),甚至可以式建立在其他底層格式之上的壓縮格式,如gzip。但是,到目前為止,HTML式最常用的格式,故而servelt和JSP的重要任務(wù)之一就式將結(jié)果包裝到HTML中。圖1-1中顯示了一條從Web中間層到客戶端的單箭頭。但是,實(shí)際發(fā)送的數(shù)據(jù)有兩種:文檔本身,以及后臺(tái)的HTTP信息。同樣,兩種數(shù)據(jù)對(duì)開發(fā)來(lái)說(shuō)都式至關(guān)重要的。HTTP響應(yīng)數(shù)據(jù)的發(fā)送過(guò)程涉及告知瀏覽器或其他客戶程序所返回文檔的類型(如HTML),設(shè)置Cookie和緩存參數(shù),以及其他類似的任務(wù)。預(yù)先建立的文檔可以滿足客戶的許多請(qǐng)求,服務(wù)器無(wú)需調(diào)用Servlet就可以處理這些請(qǐng)求。然而,許多情況下靜態(tài)的結(jié)果不能滿足要求,我們需要針對(duì)每

4、個(gè)請(qǐng)求生成一個(gè)頁(yè)面。實(shí)時(shí)構(gòu)建頁(yè)面的理由有很多種:例如,搜索引擎生成的頁(yè)面,以及在線商店的訂單確認(rèn)頁(yè)面,都要針對(duì)特定的用戶請(qǐng)求而產(chǎn)生。在沒(méi)有讀取到用戶提交的數(shù)據(jù)之前,我們不知道應(yīng)該顯示什么。要記住,用戶提交兩種類型的數(shù)據(jù):顯示(即HTML表單的數(shù)據(jù))和隱式(即HTTP請(qǐng)求的報(bào)頭)。兩種輸入都可用來(lái)構(gòu)建輸出頁(yè)面?;贑ookie值針對(duì)具體用戶構(gòu)建頁(yè)面的情況尤其普遍。如果頁(yè)面需要根據(jù)每個(gè)具體的請(qǐng)求做出相應(yīng)的改變,當(dāng)然需要在請(qǐng)求發(fā)生時(shí)構(gòu)建響應(yīng)。但是,如果頁(yè)面周期性地改變,我們可以用兩種方式來(lái)處理它:周期性地在服務(wù)器上構(gòu)建新的頁(yè)面(和客戶請(qǐng)求無(wú)關(guān)),或者僅僅在用戶請(qǐng)求該頁(yè)面時(shí)再構(gòu)建。具體應(yīng)該采用哪種方式

5、要根據(jù)具體情況而定,但后一種方式常常更為方便,因?yàn)樗恍韬?jiǎn)單地等待用戶的請(qǐng)求。例如,天氣預(yù)報(bào)或新聞網(wǎng)站可能會(huì)動(dòng)態(tài)地構(gòu)建頁(yè)面,也有可能會(huì)返回之前構(gòu)建的頁(yè)面(如果它還是最新的話)。如果數(shù)據(jù)存儲(chǔ)在數(shù)據(jù)庫(kù)中,那么,即使客戶端使用動(dòng)態(tài)Web內(nèi)容,比如applet,我們依舊需要執(zhí)行服務(wù)器端處理。想象以下,如果一個(gè)搜索引擎網(wǎng)站完全使用applet,那么用戶將會(huì)看到:“正在下載50TB的applet,請(qǐng)等待!”。顯然,這樣很愚蠢;這種情況下,我們需要與數(shù)據(jù)庫(kù)進(jìn)行會(huì)話。從客戶端到Web層再到數(shù)據(jù)庫(kù)(三層結(jié)構(gòu)),要比從applet直接到數(shù)據(jù)庫(kù)(二層結(jié)構(gòu))更靈活,也更安全,而性能上的損失很少甚至沒(méi)有。畢竟數(shù)據(jù)庫(kù)調(diào)用

6、通常是對(duì)速度影響最大的步驟,因而,經(jīng)過(guò)中間層可以執(zhí)行高速緩存和連接共享。理論上講,servelt并非只用于處理HTTP請(qǐng)求的Web服務(wù)器或應(yīng)用服務(wù)器,它同樣可以用于其他類型的服務(wù)器。例如,Servlet能夠嵌入到FTP或郵件服務(wù)器中,擴(kuò)展他們的功能。而且,用于會(huì)話啟動(dòng)協(xié)議服務(wù)器的Servlet API最近已經(jīng)被標(biāo)準(zhǔn)化(參見/en/jsr/detail?id=116)。但在實(shí)踐中,servelt的這種用法尚不流行,在此,我們只論述HTTP Servlet。和傳統(tǒng)CGI及許多類CGI技術(shù)相比,Java servelt效率更高、更易用、更強(qiáng)大、更容易移植、更安全、也更廉價(jià)。

7、應(yīng)用傳統(tǒng)的CGI,針對(duì)每個(gè)HTTP請(qǐng)求都用啟動(dòng)一個(gè)新的進(jìn)程。如果CGI程序自身相對(duì)比較簡(jiǎn)短,那么啟動(dòng)進(jìn)程的開銷會(huì)占用大部分執(zhí)行時(shí)間。而使用Servelt,Java虛擬機(jī)會(huì)一直運(yùn)行,并用輕量級(jí)的Java線程處理每個(gè)請(qǐng)求,而非重量級(jí)的操作系統(tǒng)進(jìn)程。類似地,應(yīng)用傳統(tǒng)的CGI技術(shù),如果存在對(duì)同一CGI程序的N個(gè)請(qǐng)求,那么CGI程序的代碼會(huì)載入內(nèi)存N次。同樣的情況,如果使用Servlet則啟動(dòng)N個(gè)線程,單僅僅載入Servlet類的單一副本。這種方式減少了服務(wù)器的內(nèi)存需求,通過(guò)實(shí)例化更少的對(duì)象從而節(jié)省了時(shí)間。最后,當(dāng)CGI程序結(jié)束對(duì)請(qǐng)求的處理之后,程序結(jié)束。這種方式難以緩存計(jì)算結(jié)果,保持?jǐn)?shù)據(jù)庫(kù)連接打開,或

8、是執(zhí)行依靠持續(xù)性數(shù)據(jù)的其他優(yōu)化。然而,Servelt會(huì)一直停留在內(nèi)存中(即使請(qǐng)求處理完畢),因而可以直接存儲(chǔ)客戶請(qǐng)求之間的任意復(fù)雜數(shù)據(jù)。Servlet支持常規(guī)CGI難以實(shí)現(xiàn)或根本不能實(shí)現(xiàn)的幾項(xiàng)功能。Servlet能夠直接于Web服務(wù)器對(duì)話,而常規(guī)的CGI程序做不到這一點(diǎn),至少在不使用服務(wù)器專有API的情況下是這樣。例如,與Web服務(wù)器的通信使得講相對(duì)URL轉(zhuǎn)換成具體的路徑名變得更為容易。多個(gè)Servelt還可以共享數(shù)據(jù),從而易于實(shí)現(xiàn)數(shù)據(jù)庫(kù)連接共享和類似的資源共享優(yōu)化。Servelt還能維護(hù)請(qǐng)求之間的信息,使得諸如會(huì)話跟蹤和計(jì)算結(jié)果緩存等技術(shù)變得更為簡(jiǎn)單。附錄2 英文參考資料Servlet pr

9、ogram running in the server-side, dynamically generated Web page with the traditional CGI and many other similar compared to CGI technology, Java Servlet with a more efficient, easier to use, more powerful and has better portability, more savings to invest.Servlets are Java programs that run on Web

10、or application servers, acting as a middle layer between requests coming from Web browsers or other HTTP clients and databases or applications on the HTTP server. Their job is to perform the following tasks, as illustrated in Figure 1-1.Figure 1-1 Web middleware roleFigure 1-1 shows a single arrow g

11、oing from the client to the Web server (the layer where servlets and JSP execute), but there are really two varieties of data: the explicit data that the end user enters in a form and the behind-the-scenes HTTP information. Both varieties are critical. The HTTP information includes cookies, informat

12、ion about media types and compression schemes the browser understands, and so on.This process may require talking to a database, executing an RMI or EJB call, invoking a Web service, or computing the response directly. Your real data may be in a relational database. Fine. But your database probably

13、doesn't speak HTTP or return results in HTML, so the Web browser can'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 applications.You need the Web middle layer to extract the results inside a

14、document.This document can be sent in a variety of formats, including text (HTML or XML), binary (GIF images), or even a compressed format like gzip that is layered on top of some other underlying format. But, HTML is by far the most common format, so an important servlet/JSP task is to wrap the res

15、ults inside of HTML.Figure 1-1 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 behind-the-scenes HTTP information. Again, both varieties are critical to effective development.

16、Sending HTTP response data involves telling the browser or other client what type of document is being returned (e.g., HTML), setting cookies and caching parameters, and other such tasks. For instance, the results page from search engines and order-confirmation pages at online stores are specific to

17、 particular user requests. You don'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 (i.e., HTML form data) and implicit (i.e., HTTP request headers). Either kind of input can be used to build the output page. In

18、 particular, it is quite common to build a user-specific page based on a cookie value.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

19、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 mi

20、ght build the pages dynamically, perhaps returning a previously built page if that page is still up to date.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

21、 FTP or mail servers to extend their functionality. And, a servlet API for SIP (Session Initiation Protocol) servers was recently standardized (see /en/jsr/detail?id=116). In practice, however, this use of servlets has not caught on, and we'll only be discussing HTTP servlets.Java s

22、ervlets are more efficient, easier to use, more powerful, more portable, safer, and cheaper than traditional CGI and many alternative CGI-like technologies.With traditional CGI, a new process is started for each HTTP request. If the CGI program itself is relatively short, the overhead of starting th

23、e process can dominate the execution time. With servlets, the Java virtual machine stays running and handles each request with a lightweight Java thread, not a heavyweight operating system process. Similarly, in traditional CGI, if there are N requests to the same CGI program, the code for the CGI p

24、rogram is loaded into memory N times. With servlets, however, there would be N threads, but only a single copy of the servlet class would be loaded. This approach reduces server memory requirements and saves time by instantiating fewer objects. Finally, when a CGI program finishes handling a request, the program terminates. This approach makes it difficult to cache computations, keep database connections open, and perform other optimizations that rely

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論