【正文】
y mix ColdFusion and servlet/JSP code.Versus PHP PHP (a recursive acronym for “PHP: Hypertext Preprocessor”) is a free, opensource, HTMLembedded scripting language that is somewhat similar to both ASP and Sponge advantage of JSP is that the dynamic part is written in Java, which already has an extensive API for networking, database access, distributed objects, and the like, whereas PHP requires learning an entirely new, less widely used language. A second advantage is that JSP is much more widely supported by tool and server vendors than is PHP.Versus Pure Servlets JSP doesn’t provide any capabilities that couldn’t, in principle, be acplished with servlets. In fact, JSP documents are automatically translated into servlets behind the scenes. But it is more convenient to write (and to modify!) regular HTML than to use a zillion println statements to generate the HTML. Plus, by separating the presentation from the content, you can put different people on different tasks: your Web page design experts can build the HTML by using familiar tools and either leave places for your servlet programmers to insert the dynamic content or invoke the dynamic content indirectly by means of XML tags. Does this mean that you can just learn JSP and forget about servlets? Absolutelynot! JSP developers need to know servlets for four reasons: 1. JSP pages get translated into servlets. You can’t understand how JSP works without understanding servlets. 2. JSP consists of static HTML, specialpurpose JSP tags, and Java kind of Java code? Servlet code! You can’t write that code if you don’t understand servlet programming. 3. Some tasks are better acplished by servlets than by JSP. JSP is good at generating pages that consist of large sections of fairly well structured HTML or other character data. Servlets are better for generating binary data, building pages with highly variable structure, and performing tasks (such as redirection) that involve little or no output. 4. Some tasks are better acplished by a bination of servlets and JSP than by either servlets or JSP alone. Versus JavaScript JavaScript, which is pletely distinct from the Java programming language, is normally used to dynamically generate HTML on the client, building parts of the Web page as the browser loads the document. This is a useful capability and does not normally overlap with the capabilities of JSP (which runs only on the server). JSP pages still include SCRIPT tags for JavaScript, just as normal HTML pages do. In fact, JSP can even be used to dynamically generate the JavaScript that will be sent to the client. So, JavaScript is not a peting technology。 it is a plementary one. It is also possible to use JavaScript on the server, most notably on Sun ONE (formerly iPlanet), IIS, and BroadVision servers. However, Java is more powerful, flexible, reliable, and portable.l 中文翻譯JSP相對(duì)于競(jìng)爭(zhēng)技術(shù)的優(yōu)勢(shì)許多年前,本書的作者(Marty)受到邀請(qǐng),參見一個(gè)有關(guān)軟件技術(shù)的小型(20個(gè)人)研討會(huì)。坐在Marty旁邊的人是James Gosling――Java編程語言的發(fā)明者。隔幾個(gè)位置,使來自華盛頓雷蒙德一家超大型軟件公司的高級(jí)經(jīng)理。在討論過程中,研討會(huì)的主席提出了Jini的議題,這在當(dāng)時(shí)是一項(xiàng)新的Java技術(shù)。主席向該經(jīng)理詢問他的想法,這個(gè)經(jīng)理回答說想在談?wù)撍€為時(shí)過早,但看起來是一個(gè)出色的想法。他繼續(xù)說,他們會(huì)持續(xù)關(guān)注這項(xiàng)技術(shù),如果這項(xiàng)技術(shù)變得流行起來,他們會(huì)遵循公司的“接受并擴(kuò)充(embrace and extend)”的策略。此時(shí),Gosling隨意地插話說“你的意思其實(shí)就是不接受且不擴(kuò)充(disgrace and distend)?!痹诖耍珿osling的抱怨顯示出,他感到這個(gè)公司會(huì)從其他公司那里拿走技術(shù),用于他們自己的目的。但你猜這次怎么樣?這次的鞋子穿在了另一只腳上。Java社團(tuán)沒有發(fā)明這一思想――將頁面設(shè)計(jì)成由靜態(tài)HTML和用特殊標(biāo)簽標(biāo)記的動(dòng)態(tài)代碼混合組成。ColdFusion多年前就已經(jīng)這樣做了。甚至ASP(來自于前述經(jīng)理所在公司的一項(xiàng)產(chǎn)品)都在JSP出現(xiàn)之前推廣了這種方式。實(shí)際上,JSP不止采用了這種通用概念,它甚至使用許多和ASP相同的特殊標(biāo)簽。因此,問題便成:為什么使用JSP,而不使用其他技術(shù)呢?我們的第一反應(yīng)是我們不是在爭(zhēng)論所有的人應(yīng)該做什么。其他這些技術(shù)中,有一些也很不錯(cuò),在某種情況下也的確是合情合理的選擇。然而,在其他情形中,JSP明顯要更好一些。下面給出幾個(gè)理由。 Server Page(ASP)相比.NET是Microsoft精心設(shè)計(jì)的一項(xiàng)技術(shù)。JSP的優(yōu)勢(shì)體現(xiàn)在兩個(gè)方面。首先,JSP可以移植到多種操作系統(tǒng)和Web服務(wù)器,您不必僅僅局限于部署在Windows和IIS上。,但ASP這一部分不可以。對(duì)于某些應(yīng)用,這種差異沒有什么影響。但有些應(yīng)用,這種差異卻非常重要。其次,對(duì)于某些應(yīng)用,底層語言的選擇至關(guān)重要。例如,語言設(shè)計(jì)優(yōu)良,且和Java類似,但熟悉核心C語法和眾多工具庫(kù)的程序員很少。此外,許多開發(fā)者依舊使用最初版本的ASP。相對(duì)于這個(gè)版本,JSP在動(dòng)態(tài)代碼方面擁有明顯的優(yōu)勢(shì)。使用JSP,動(dòng)態(tài)部分是用Java編寫,而非VBScript或其他ASP專有的語言,因此JSP更為強(qiáng)勁,更始合于要求組件重用的復(fù)雜應(yīng)用。當(dāng)使用JSP與之前的版本ColdFusioin對(duì)比時(shí),您可能會(huì)得到相同的結(jié)論。應(yīng)用JSP您可以使用Java編寫“真正的代碼”,不必依賴于特定的服務(wù)器產(chǎn)品。然而,當(dāng)前版本的ColdFusion滿足J2EE服務(wù)器的環(huán)境,允許開發(fā)者容易地混合使用ColdFusion和servlet/JSP代碼。與PHP相比PHP(“PHP:Hypertext Preprocessor”的遞歸首字母縮寫詞)是免費(fèi)的、開放源碼的、HTML嵌入其中的腳本語言,與ASP和JSP都有某種程度的類似。JSP的一項(xiàng)優(yōu)勢(shì)是動(dòng)態(tài)部分用Java編寫,而Java已經(jīng)在聯(lián)網(wǎng)、數(shù)據(jù)庫(kù)訪問、分布式對(duì)象等方面擁有廣泛的API,而PHP需要學(xué)習(xí)全新的、應(yīng)用相對(duì)不廣泛的語言。JSP的第二項(xiàng)優(yōu)勢(shì)是,和PHP相比,JSP擁有極為廣泛的工具和服務(wù)器提供商的支持。與純servlet相比原則上,JSP并沒有提供servlet不能提完成的功能。實(shí)際上,JSP文檔在后臺(tái)被自動(dòng)轉(zhuǎn)換成servlet。但是編寫(和修改)常規(guī)的HTML,要比使用無數(shù)println語句生成HTML要方便得多。另外,通過將表示與內(nèi)容分離,可以為不同的人分配不同的任務(wù):網(wǎng)頁設(shè)計(jì)人員使用熟練的工具構(gòu)建HTML,要么為servlet程序員流出空間插入動(dòng)態(tài)內(nèi)容,要么通過XML標(biāo)簽間接調(diào)用動(dòng)態(tài)內(nèi)容。這是否表示您可以只學(xué)習(xí)JSP,將servlet丟到一邊呢?當(dāng)然不是!由于以下4種原因,JSP開發(fā)人員需要了解servlet:JSP頁面需要轉(zhuǎn)換成servlet。不了解servlet就無法知道JSP如何工作。JSP有靜態(tài)HTML、專用的JSP標(biāo)簽和Java代碼組成,哪種類型的Java代碼呢?當(dāng)然是servlet代碼!如果不了解servlet編程,那么就無法編寫這種代碼?! ∫恍┤蝿?wù)用servlet完成比用JSP來完成要好。JSP擅長(zhǎng)生成大量組織有序的機(jī)構(gòu)化HTML或其他字符數(shù)據(jù)組成的頁面。Servlet擅長(zhǎng)生成二進(jìn)制數(shù)據(jù),構(gòu)建結(jié)構(gòu)多樣的頁面,以及執(zhí)行輸出很少或者沒有輸出的任務(wù)(比如重定向)?! ∮行┤蝿?wù)更適合組合使用servlet和JSP來完成,而非單獨(dú)使用servlet或JSP。與JavaScript相比JavaScript和Java編程序語言完全是兩碼事,前者一般用于在客戶端動(dòng)態(tài)生成HTML,在瀏覽器載入文檔時(shí)構(gòu)建網(wǎng)頁的部分內(nèi)容。這是一項(xiàng)有用的功能,一般與JSP的功能(只在服務(wù)器端運(yùn)行)并不發(fā)生重疊。和常規(guī)HTML頁面一樣,JSP頁面依舊可以包括用于JavaScript的SCRIPT標(biāo)簽。實(shí)際上,JSP甚至能夠用來動(dòng)態(tài)生成發(fā)送到客戶端的JavaScript。因此,JavaScript不是一項(xiàng)競(jìng)爭(zhēng)技術(shù),它是一項(xiàng)補(bǔ)充技術(shù)。JavaScript也可以用在服務(wù)器端,最引人注意的是Sun ONE(以前的iPlanet)、IIS和BroadVision服務(wù)器。然而,Java更為強(qiáng)大、靈活??煽壳铱梢浦?。謝 辭大學(xué)四年,轉(zhuǎn)眼就要結(jié)束?;仡櫵鶎W(xué)過的知識(shí)真不少,很感謝在校期間所有教導(dǎo)過我的老師們,是你們傳授了我現(xiàn)在和將來賴以生存的知識(shí),培養(yǎng)了我的適應(yīng)與應(yīng)變能力。更要特別感謝的是我的導(dǎo)師馬潔老師。在整個(gè)課題的研究開發(fā)過程中,馬潔老師給了我悉心的指導(dǎo)、耐心的幫助,其淵博的知識(shí)、嚴(yán)謹(jǐn)負(fù)責(zé)的治學(xué)態(tài)度給我留下了深遠(yuǎn)的影響,這些都將使我終身受益,在這里我向馬老師表示深深的謝意。此外,我還要向所有關(guān)心、幫助過我的同學(xué)們表示感謝,因?yàn)橛辛四銈兾业拇髮W(xué)才如此精彩!最后,對(duì)百忙之中審閱我論文的各們老師以及參加答辯會(huì)的各們老師表示深深的謝意!