版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、<p> Java and the Internet</p><p> If Java is, in fact, yet another computer programming language, you may question why it is so important and why it is being promoted as a revolutionary step in compu
2、ter programming. The answer isn’t immediately obvious if you’re coming from a traditional programming perspective. Although Java is very useful for solving traditional standalone programming problems, it is also importan
3、t because it will solve programming problems on the World Wide Web.</p><p> What is the Web?</p><p> The Web can seem a bit of a mystery at first, with all this talk of “surfing,” “presence,”
4、and “home pages.” It’s helpful to step back and see what it really is, but to do this you must understand client/server systems, another aspect of computing that’s full of confusing issues.</p><p> Client/S
5、erver computing</p><p> The primary idea of a client/server system is that you have a central repository of information—some kind of data, often in a database—that you want to distribute on demand to some s
6、et of people or machines. A key to the client/server concept is that the repository of information is centrally located so that it can be changed and so that those changes will propagate out to the information consumers.
7、 Taken together, the information repository, the software that distributes the information and the</p><p> The basic concept of client/server computing, then, is not so complicated. The problems arise becau
8、se you have a single server trying to serve many clients at once. Generally, a database management system is involved, so the designer “balances” the layout of data into tables for optimal use. In addition, systems often
9、 allow a client to insert new information into a server. This means you must ensure that one client’s new data doesn’t walk over another client’s new data, or that data isn’t lost i</p><p> The simple idea
10、of distributing information has so many layers of complexity that the whole problem can seem hopelessly enigmatic. And yet it’s crucial: Client/server computing accounts for roughly half of all programming activities. It
11、’s responsible for everything from taking orders and credit-card transactions to the distribution of any kind of data—stock market, scientific, government, you name it. What we’ve come up with in the past is individual s
12、olutions to individual problems, inventing a</p><p> The Web as a giant server</p><p> The Web is actually one giant client/server system. It’s a bit worse than that, since you have all the se
13、rvers and clients coexisting on a single network at once. You don’t need to know that, because all you care about is connecting to and interacting with one server at a time (even though you might be hopping around the wo
14、rld in your search for the correct server).</p><p> Initially it was a simple one-way process. You made a request of a server and it handed you a file, which your machine’s browser software (i.e., the clien
15、t) would interpret by formatting onto your local machine. But in short order people began wanting to do more than just deliver pages from a server. They wanted full client/server capability so that the client could feed
16、information back to the server, for example, to do database lookups on the server, to add new information to the server, or to</p><p> The Web browser was a big step forward: the concept that one piece of i
17、nformation could be displayed on any type of computer without change. However, browsers were still rather primitive and rapidly bogged down by the demands placed on them. They weren’t particularly interactive, and tended
18、 to clog up both the server and the Internet because any time you needed to do something that required programming you had to send information back to the server to be processed. It could take many seconds or </p>
19、<p> To solve this problem, different approaches have been taken. To begin with, graphics standards have been enhanced to allow better animation and video within browsers. The remainder of the problem can be solve
20、d only by incorporating the ability to run programs on the client end, under the browser. This is called client-side programming.</p><p> Client-side programming</p><p> The Web’s initial serv
21、er-browser design provided for interactive content, but the interactivity was completely provided by the server. The server produced static pages for the client browser, which would simply interpret and display them. Bas
22、ic HyperText Markup Language (HTML) contains simple mechanisms for data gathering: text-entry boxes, check boxes, radio boxes, lists and drop-down lists, as well as a button that can only be programmed to reset the data
23、on the form or “submit” the data on th</p><p> Many powerful Web sites today are built strictly on CGI, and you can in fact do nearly anything with CGI. However, Web sites built on CGI programs can rapidly
24、become overly complicated to maintain, and there is also the problem of response time. The response of a CGI program depends on how much data must be sent, as well as the load on both the server and the Internet. (On top
25、 of this, starting a CGI program tends to be slow.) The initial designers of the Web did not foresee how rapidly this ban</p><p> The solution is client-side programming. Most machines that run Web browsers
26、 are powerful engines capable of doing vast work, and with the original static HTML approach they are sitting there, just idly waiting for the server to dish up the next page. Client-side programming means that the Web b
27、rowser is harnessed to do whatever work it can, and the result for the user is a much speedier and more interactive experience at your Web site.</p><p> The problem with discussions of client-side programmi
28、ng is that they aren’t very different from discussions of programming in general. The parameters are almost the same, but the platform is different; a Web browser is like a limited operating system. In the end, you must
29、still program, and this accounts for the dizzying array of problems and solutions produced by client-side programming. The rest of this section provides an overview of the issues and approaches in client-side programming
30、.</p><p><b> Plug-ins</b></p><p> One of the most significant steps forward in client-side programming is the development of the plug-in. This is a way for a programmer to add new
31、functionality to the browser by downloading a piece of code that plugs itself into the appropriate spot in the browser. It tells the browser “from now on you can perform this new activity.” (You need to download the plug
32、-in only once.) Some fast and powerful behavior is added to browsers via plug-ins, but writing a plug-in is not a trivial task, and is</p><p> Scripting languages</p><p> Plug-ins resulted in
33、an explosion of scripting languages. With a scripting language, you embed the source code for your client-side program directly into the HTML page, and the plug-in that interprets that language is automatically activated
34、 while the HTML page is being displayed. Scripting languages tend to be reasonably easy to understand and, because they are simply text that is part of an HTML page, they load very quickly as part of the single server hi
35、t required to procure that page. The tr</p><p> This points out that the scripting languages used inside Web browsers are really intended to solve specific types of problems, primarily the creation of riche
36、r and more interactive graphical user interfaces (GUIs). However, a scripting language might solve 80 percent of the problems encountered in client-side programming. Your problems might very well fit completely within th
37、at 80 percent, and since scripting languages can allow easier and faster development, you should probably consider a scrip</p><p> The most commonly discussed browser scripting languages are JavaScript (whi
38、ch has nothing to do with Java; it’s named that way just to grab some of Java’s marketing momentum), VBScript (which looks like Visual BASIC), and Tcl/Tk, which comes from the popular cross-platform GUI-building language
39、. There are others out there, and no doubt more in development.</p><p> JavaScript is probably the most commonly supported. It comes built into both Netscape Navigator and the Microsoft Internet Explorer (I
40、E). Unfortunately, the flavor of JavaScript on the two browsers can vary widely (the Mozilla browser, freely downloadable from www.Mozilla.org, supports the ECMAScript standard, which may one day become universally suppo
41、rted). In addition, there are probably more JavaScript books available than there are for the other browser languages, and some tools automaticall</p><p> 原文來源:(美)Bruce Ecket. Thinking in JAVA第三版. 2003</
42、p><p> Java 和Internet</p><p> 可能你會問,如果Java只是一種新的計算機(jī)編程語言的話(實(shí)際上這話也沒錯),它為什么會那么重要,為什么會被除數(shù)拔高到“計算機(jī)編程領(lǐng)域的革命性的進(jìn)步”,這個高度。如果你是從傳統(tǒng)編程的立場上來看這個問題,也許答案還不是那么有說服力。盡管在解決傳統(tǒng)的,孤立的編程問題方面,Java也是很能干的,但是真正讓它脫穎而出的,是因?yàn)樗芙鉀Q在萬
43、維網(wǎng)上編程的問題。</p><p><b> Web就什么?</b></p><p> 剛開始的時候,Web看上去很神秘,大家都江堰市在談沖浪、在線、主頁什么的。要把講Web講清楚,最好是退回來從頭開始。但是這么做,先得理解客戶/服務(wù)器系統(tǒng)。這是計算機(jī)技術(shù)的另一個領(lǐng)域,里面也有大把讓人頭暈的問題。</p><p><b> 客戶
44、/服務(wù)器系統(tǒng)</b></p><p> 客戶機(jī)/服務(wù)器系統(tǒng)的主要思想是,你有一個中央信息庫———通常是保存在數(shù)據(jù)庫中的一些信息———要根據(jù)需要,把它們分配給某些人或機(jī)器。客戶機(jī)/服務(wù)器系統(tǒng)的關(guān)鍵在于,信息庫會集中管理信息,因此信息的修改能夠傳播到用戶那里。信息庫,分發(fā)信息的軟件,以及存儲信息的軟件的機(jī)器合起來稱為服務(wù)器。存儲在遠(yuǎn)程機(jī)器上的軟件會同這個服務(wù)器通訊,提取信息,處理信息,并且在過程機(jī)器上顯
45、示結(jié)果。這被除數(shù)稱為客戶。</p><p> 這么看來,客戶/服務(wù)器計算機(jī)的基本概念沒那么復(fù)雜。但是,當(dāng)你試圖用孤零零的一個服務(wù)器來為很多客戶服務(wù)的時候,問題就來了。這個架構(gòu)通常都會牽扯到數(shù)據(jù)庫管理系統(tǒng),所以為了優(yōu)化應(yīng)用,設(shè)計人員會去“平衡”數(shù)據(jù)的格式。此外,通常系統(tǒng)還允許客戶往服務(wù)器里插入新的數(shù)據(jù)。這就意味著你必須保證一個客戶的新數(shù)據(jù)不會和另一個客戶的新數(shù)據(jù)攪在一起,以及數(shù)據(jù)不會在添加的過程中遺失(這被稱為事
46、務(wù)處理)。當(dāng)客戶端的程序修改之后,還必須重新編譯,調(diào)試并且安裝到客戶機(jī)上,這要比你想像的復(fù)雜昂貴得多。而且如果要支持多種機(jī)器或操作系統(tǒng)的話,事情會更麻煩。最后還有一個最重要的性能問題:服務(wù)器可能會同時響應(yīng)成百上千個客戶,所以再小的耽擱都是很要命的。為了把延時降到最低,程序員們盡量減輕服務(wù)的負(fù)載,通常會把這些處理任務(wù)挪到客戶端,不過有時也會移到所謂的中間件的服務(wù)器上。(中間件也被用來增進(jìn)系統(tǒng)的可維護(hù)性。)</p><p
47、> 分發(fā)數(shù)據(jù)這個簡單的思想竟然會引出這么些復(fù)雜層次,而所有這些問題看起來都像是根本不可能解開的謎。但還有更重要的:大約有一半的開發(fā)項(xiàng)目都是基于客戶/服務(wù)器架構(gòu)的。它們包括像接收訂單,信用卡交易額以及分發(fā)各種各樣的數(shù)據(jù)———股票市場的,科研的,政府部門的,只要你能叫的上名字的。以前我們的作法是為每個問題設(shè)計不同的解決方案,每次都發(fā)明一種新方法。這種項(xiàng)目開發(fā)起來難,用戶用起來也不方便,它們必須適應(yīng)新的界面??蛻?服務(wù)器架構(gòu)這個問題必
48、須要能在總體上解決。</p><p> 把Web當(dāng)作巨型的服務(wù)器</p><p> Web實(shí)際上就是一個巨型的客戶/服務(wù)器系統(tǒng)。實(shí)際上還差一點(diǎn),因?yàn)樗械姆?wù)器和客戶機(jī)是共存在同一個網(wǎng)絡(luò)上的。不過這點(diǎn)你并不知道,因?yàn)槟阒魂P(guān)心是不是能連到那臺服務(wù)器,并且對它進(jìn)行操作(盡管你可能得先在什么地方找到那臺服務(wù)器)。</p><p> 最初這只是個關(guān)向過程。你向服務(wù)器提
49、請求,它交給你一個文件,然后你用本地機(jī)上的瀏覽器(也就是客戶)來解釋這個文件并且為它重新排版。但沒過多久,人們就不滿足于僅僅從服務(wù)器收發(fā)文件了。他們需要完整的客戶/服務(wù)器功能,所以客戶也能向服務(wù)器發(fā)送信息了,比如查詢服務(wù)器端的數(shù)據(jù)庫,向服務(wù)器添加新的信息,或者下單(這項(xiàng)任務(wù)所要求的安全性比系統(tǒng)原先能提供的要高得多)。這些就是我們在Web的發(fā)展歷程中親眼目睹的變化。</p><p> Web瀏覽器是一項(xiàng)巨大的進(jìn)步
50、:它的思想是要讓同樣的信息以通常的形式顯示在所有的機(jī)器上。然而瀏覽器還是太原始了一些,而且也很快被加在它身上的任務(wù)給拖垮了。它的互動性不好,而且所有需要編程解決的任務(wù)都要交到服務(wù)器上去處理,所以經(jīng)常會把服務(wù)器和Internet給堵了。有時可能會花幾秒鐘,甚至是幾分鐘,才會發(fā)現(xiàn)提交的請求里面有一個拼寫錯誤。由于瀏覽器只是用來顯示,不能承擔(dān)哪怕是最簡單的計算任務(wù)。(另一方面這樣也很安全,因?yàn)樗粫谀愕谋镜貦C(jī)上執(zhí)行可能包含bug或病毒程序。
51、)</p><p> 為了解決這個問題,人們用了很多辦法。開始是升級圖形超標(biāo)準(zhǔn),讓瀏覽器能顯示效果更佳的動畫和視頻。但是有些問題,只能通過讓客戶端的瀏覽器運(yùn)行程序來解決了。這被稱為客戶端編程。</p><p><b> 客戶端編程</b></p><p> Web最初的服務(wù)器——瀏覽器設(shè)計提供了互動內(nèi)容,但是這種互動性是完全建立在服務(wù)器之
52、上的。服務(wù)器為客戶端提供靜態(tài)頁面,而瀏覽器只是簡單的解釋頁面,然后顯示出來。HTML包括了基本的數(shù)據(jù)采集功能:輸入框,復(fù)選框,單選按鈕,列表,下拉式列表,以及只能用于清除表單或是把表單數(shù)據(jù)“提交”給服務(wù)器的按扭。提交上來的數(shù)據(jù)會交給Web服務(wù)器上的通用網(wǎng)關(guān)接口程序。這些文本會告訴CGI該做些什么。最常見的就是在服務(wù)器上運(yùn)行一個程序,這個程序一般會放在“cgi-bin”目錄中。(如果按完Web頁面上的按扭之后,你仔細(xì)觀察瀏覽器頂部的地址條
53、的話,有時你就會在那些不知所云的東西中看到“cgi-bin”。)大多數(shù)語言都可以寫這些程序。Perl是最常用的,因?yàn)樗O(shè)計的目的就是為了處理和解釋文本,所以不論服務(wù)器用的是那種處理器,或是那種操作系統(tǒng),都能安裝Perl。但Python(我的最愛———見www.Pythoin.org)由于其功能強(qiáng)大簡單易用,已經(jīng)對Perl的霸主地位發(fā)起了挑戰(zhàn)。</p><p> 很多大型網(wǎng)站都是完全建立在CGI之上的,而且實(shí)際上
54、你能用CGI來做幾乎任何事情。但是建立在CGI之上的網(wǎng)站會很快變得過于復(fù)雜而難以維護(hù),此處還有一個相應(yīng)時間的問題。CGI程序的相應(yīng)時間取決于它要發(fā)送多少數(shù)據(jù),以及服務(wù)器端各Internet的負(fù)載。(而且CGI程序本身就啟動很慢。)最初設(shè)計Web的人沒能預(yù)料到帶寬會消耗在這類應(yīng)用程序中。舉例來說,動態(tài)圖形實(shí)際上是不可能一致地運(yùn)行的,所以服務(wù)器會把所有版本的GIF文件都傳到客戶端。而且,毫無疑問你肯定做過像填寫表格這種簡單的事。當(dāng)你按了發(fā)送
55、按鈕之后,數(shù)據(jù)會被送回到服務(wù)器,然后服務(wù)器啟動CGI程序,但是發(fā)現(xiàn)有個錯誤,于是重新生成一個HTML告訴你出來錯,再把這個頁面?zhèn)鹘o你;然后你再重頭來一遍。這樣做不但慢,而且蠢。</p><p> 解決方案就是客戶端編程。絕大多數(shù)運(yùn)行Web瀏覽器的機(jī)器都有強(qiáng)大的引擎,能作很多工作,而且在原告靜態(tài)的HTML方法下,大多數(shù)時間,它們都是在傻等著服務(wù)器發(fā)送下一個頁面。客戶端編程意味著Web瀏覽器能物盡其用,結(jié)果是用戶能
56、更快同時也更互動地體驗(yàn)?zāi)愕木W(wǎng)站。</p><p> 客戶端編程所遇到的問題同通用編程的沒有什么本質(zhì)性的區(qū)別。參數(shù)幾乎是相同的,只是平臺有寫差異;瀏覽器就是一個小型的操作系統(tǒng)。最后,你還得寫程序,還要解決一串讓人眼花繚亂的問題,還是提供客戶端編程的解決方案。本節(jié)的余下部分會簡要介紹客戶端編程的問題與方法。</p><p><b> 插件</b></p>
57、<p> 在客戶端編程方面最重要的步驟之一就是開發(fā)插件。這是程序員就為瀏覽器提供新功能的辦法。它要求用戶從網(wǎng)上下載插件程序,然后把它集成到瀏覽器里。插件告訴瀏覽器“從今往后,你可以進(jìn)行這些新的工作了。”(插件只需下載一次。)插件為瀏覽器添加了一些快速強(qiáng)大的功能,但是寫一個插件可不是什么輕松的任務(wù),也不應(yīng)該是建網(wǎng)站應(yīng)該作的事。插件對于客戶端編程的價值在于,它能讓專家級的程序員開發(fā)一種新的語言,并且不經(jīng)開發(fā)商的同意,就把這種語
58、言加進(jìn)瀏覽器里。于是插件提供了一個能創(chuàng)建新的客戶端編程語言的“后門”(盡管不是所有的語言都是通過插件來實(shí)現(xiàn)的)。</p><p><b> 腳本語言</b></p><p> 插件導(dǎo)致了腳本語言的泛濫。你可以用腳本語言把客戶端程序的源代碼直接嵌進(jìn)HTML頁面里去,HTML頁面顯示的時候,會自動激活這個插件去解釋這些程序的。腳本語言應(yīng)該比較簡單,而且作為HTML頁面
59、的一個部分,它們都是簡單的文本,所以會隨頁面一起獲取,而且裝載也很快。不過代價就是代碼只能給別人看了(或者說偷了)。總之,由于你沒法用腳本語言做非常復(fù)雜的東西,所以它的難度不會太大。</p><p> 這一點(diǎn)決定了Web瀏覽器所用的腳本語言實(shí)際上是用來解決某些具體的問題的,主要是創(chuàng)建更豐富的,更互動的用戶界面的(GUI)。然而,腳本語言也許能解決百分之十的客戶端編程的問題。可能你要解決的問題正好落進(jìn)這百分之八十
60、的范圍,而且由于腳本語言開發(fā)起來更簡單也更快,所以你應(yīng)該在選用Java或ActiveX這類難度更大的方案之前,先考慮一下腳本語言。</p><p> 最常被提及的瀏覽器用的腳本語言有JavaScript(跟Java沒什么關(guān)系;它取這個名字只是想搭Java的順風(fēng)車),VBScript(看上去像Visual BASIC),以及Tcl/Tk,這是一種很流行的跨平臺的創(chuàng)建GUI的語言。此外還有一些,但是正在開發(fā)肯定還要
61、多。</p><p> JavaScript可能是人氣最旺的。Netscape Navigator同Microsoft Internet(IE)都內(nèi)置了這個語言。然而不幸的是這兩個瀏覽器所支持的JavaScript在風(fēng)格上有很大的不同(Mozilla支持的ECMAScript或許有一天能成為普遍支持的標(biāo)準(zhǔn)。可以到www.Mozilla.org去下載這個瀏覽器)。此外講JavaScript的書可能要比其它語言的都
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 計算機(jī)專業(yè)外文翻譯--計算機(jī)
- 計算機(jī)外文翻譯---計算機(jī)引論
- 計算機(jī)外文翻譯
- 計算機(jī)外文資料翻譯
- 計算機(jī)科學(xué)外文翻譯
- 計算機(jī)外文翻譯(完整)
- 計算機(jī)外文翻譯1
- 計算機(jī)外文翻譯9
- 計算機(jī)外文翻譯63
- 計算機(jī)外文翻譯3
- 計算機(jī)專業(yè)-外文翻譯
- 計算機(jī)外文翻譯.doc
- 外文翻譯---計算機(jī)程序
- 計算機(jī)外文翻譯 (2)
- 計算機(jī)專業(yè)外文翻譯(文獻(xiàn)翻譯)
- 計算機(jī)病毒外文翻譯
- 計算機(jī)控制外文翻譯
- 計算機(jī)相關(guān)專業(yè)外文翻譯
- 計算機(jī)編程類外文翻譯
- 計算機(jī)專業(yè)外文翻譯----計算機(jī)視覺中的學(xué)習(xí)
評論
0/150
提交評論