版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、<p><b> 畢業(yè)論文外文翻譯:</b></p><p><b> JSP 應(yīng)用框架</b></p><p><b> 什么是應(yīng)用框架:</b></p><p> 框架(framework)是可重用的,半成品的應(yīng)用程序,可以用來產(chǎn)生專門的定制程序。象人一樣,軟件應(yīng)用的相似性比不同
2、點(diǎn)要多。它們運(yùn)行在相似的機(jī)器上,期望從相同的設(shè)備輸入信息,輸出到相同的顯示設(shè)備,并且將數(shù)據(jù)存儲(chǔ)到相同的硬盤設(shè)備。開發(fā)傳統(tǒng)桌面應(yīng)用的開發(fā)人員更習(xí)慣于那些可以涵蓋應(yīng)用開發(fā)同一性的工具包和開發(fā)環(huán)境。構(gòu)架在這些公共基礎(chǔ)上的應(yīng)用框架可以為開發(fā)人員提供可以為他們的產(chǎn)品提供可重用服務(wù)的基礎(chǔ)架構(gòu)。</p><p> 框架向開發(fā)人員提供一系列具有以下特征的骨架組件:</p><p> 1.已經(jīng)知道它們?cè)?/p>
3、其它程序上工作得很好;</p><p> 2.它們隨時(shí)可以在下一個(gè)項(xiàng)目中使用;</p><p> 3.它們可以被組織的其它團(tuán)隊(duì)使用;</p><p> 對(duì)于框架是典型的構(gòu)建還是購買命題。如果你自己構(gòu)建它,在你完成時(shí)你就會(huì)理解它,但是在你被融入之前又將花費(fèi)多長時(shí)間呢?如果要購買,你必須得克服學(xué)習(xí)曲線,同樣,在你可以用它進(jìn)行工作之前又得花多長時(shí)間?這里沒有所謂正確
4、答案,但許多觀察者都會(huì)同意,象Struts這樣的框架能提供比從頭開始開發(fā)更顯著的投資回報(bào),特別是對(duì)于大型項(xiàng)目來說。</p><p><b> 其它類型的框架:</b></p><p> 框架的概念不僅用于應(yīng)用程序也可用于組件。在其它的資料里面,我們也介紹了一些可以和Struts一起使用的框架。這些包括Lucene搜索引擎,Scaffold工具包,Struts驗(yàn)證器
5、,以及Tiles標(biāo)簽庫。與應(yīng)用框架一樣,這些工具也提供了一些半完成的版本,可以用在用戶的定制組件之中。某些框架被限制于專門的開發(fā)環(huán)境中。Struts以及本文中涉及的組件卻不是這樣。你可以在很多環(huán)境中來開發(fā)Struts: Visual Age for Java, JBuilder, Eclipse, Emacs, 甚至使用Textpad。對(duì)于你的工具,如果你可以用來開發(fā)Java, 你就可以用它來開發(fā)Struts。</p>&
6、lt;p><b> 使用的技術(shù):</b></p><p> 使用Struts的應(yīng)用開發(fā)使用了大量的其他基礎(chǔ)技術(shù)。這些技術(shù)并不是專門針對(duì)Struts,而是所有Java web 應(yīng)用都可以使用的。開發(fā)者使用Struts之類的框架是為了隱藏在諸如HTTP,CGI,以及JSP之類技術(shù)后面的繁瑣的細(xì)節(jié)。作為一個(gè)Struts開發(fā)者,你并不需要知曉所有的相關(guān)知識(shí),但是這些基本技術(shù)的工作原理可能有
7、助于你針對(duì)棘手問題設(shè)計(jì)出創(chuàng)造性的方案。</p><p> 超文本傳輸協(xié)議 (HTTP):</p><p> 當(dāng)兩個(gè)國家之間進(jìn)行調(diào)解時(shí),外交官們總是遵循一定的正式協(xié)議。外交協(xié)議主要設(shè)計(jì)來避免誤解,以及防止談判破裂。同樣,當(dāng)計(jì)算機(jī)間需要對(duì)話,它們也遵循一個(gè)正式的協(xié)議。這個(gè)協(xié)議定義數(shù)據(jù)是如何傳輸,以及它們到達(dá)后如何進(jìn)行解碼。Web應(yīng)用程序就是使用HTTP協(xié)議在運(yùn)行瀏覽器的計(jì)算機(jī)和運(yùn)行的服務(wù)器
8、的程序間傳輸數(shù)據(jù)。</p><p> 很多服務(wù)器應(yīng)用程序使用HTTP之外的其他協(xié)議。他們?cè)谟?jì)算機(jī)之間維護(hù)一個(gè)持久性的連接。應(yīng)用服務(wù)器可以清楚的知道是誰連接上來,而且何時(shí)中斷連接。因?yàn)樗鼈冎烂恳粋€(gè)連接的狀態(tài),以及每一個(gè)使用它的人。這稱之為狀態(tài)協(xié)議。</p><p> 相反, HTTP是一個(gè)無狀態(tài)協(xié)議。HTTP Server 可以接受來自于各種客戶的各種請(qǐng)求,并提供各種響應(yīng),即使是這個(gè)響
9、應(yīng)僅僅是說No。沒有大量的協(xié)商和連接持久性,無狀態(tài)協(xié)議可以處理大量的請(qǐng)求。這也是Internet 可以擴(kuò)展到很多計(jì)算機(jī)的原因。</p><p> HTTP 成為通用標(biāo)準(zhǔn)的原因是其簡單性。HTTP請(qǐng)求看起來就像一個(gè)平常的文本文檔。這使應(yīng)用程序很容易創(chuàng)建HTTP請(qǐng)求。你甚至可以通過標(biāo)準(zhǔn)的程序如Telnet來手動(dòng)傳遞一個(gè)HTTP請(qǐng)求。當(dāng)HTTP響應(yīng)返回時(shí),它也是一個(gè)開發(fā)者可以直接閱讀的平面文本。HTTP請(qǐng)求的第一行包
10、含方法,其后是請(qǐng)求的來源地址和HTTP版本。HTTP請(qǐng)求頭跟在首行后面,可以沒有也可以有多個(gè)。HTTP頭向服務(wù)器提供額外的信息。可以包括瀏覽器的種類和版本,可接受的文檔類型,瀏覽器的cookies等等。7 種請(qǐng)求方法中, GET和 POST是用得最多的。</p><p> 一旦服務(wù)器接收到請(qǐng)求,它就要產(chǎn)生一個(gè)HTTP響應(yīng)。響應(yīng)的第一行稱為狀態(tài)行,包含了HTTP協(xié)議的版本,數(shù)字型狀態(tài),以及狀態(tài)的簡短描述。狀態(tài)行后
11、,服務(wù)器將返回一個(gè)HTTP響應(yīng)頭,類似于HTTP請(qǐng)求頭。如上所述,HTTP并不在請(qǐng)求間保持狀態(tài)信息。服務(wù)器接受請(qǐng)求,發(fā)出響應(yīng),并且繼續(xù)愉快地處理文本請(qǐng)求。</p><p> 因?yàn)楹唵魏托?,無狀態(tài)協(xié)議不適合于需要跟蹤用戶狀態(tài)的動(dòng)態(tài)應(yīng)用。Cookies和 URL 重寫是兩個(gè)在請(qǐng)求間跟蹤用戶狀態(tài)的方式。cookie是一種特殊的信息包,存儲(chǔ)于用戶的計(jì)算機(jī)中。URL重寫是在頁面地址中存儲(chǔ)一個(gè)特殊的標(biāo)記,Java服務(wù)器可
12、以用它來跟蹤用戶。這兩種方法都不是無縫的,是用哪一個(gè)都意味著在開發(fā)時(shí)都要進(jìn)行額外的工作。對(duì)其本身來說,標(biāo)準(zhǔn)的HTTP web服務(wù)器并不傳輸動(dòng)態(tài)內(nèi)容。它主要是使用請(qǐng)求來定位文件資源,并在響應(yīng)中返回此資源。通常這里的文件使用Hypertext Markup Language (HTML) [W3C,HTML] 格式化,以使瀏覽器可以顯示它們。HTML頁面通常包含一些到其他頁面的超文本連接,也可以顯示其他一些內(nèi)容比如圖像和視頻等等。用戶點(diǎn)擊連
13、接將產(chǎn)生另一個(gè)請(qǐng)求,就開始一個(gè)新的處理過程。標(biāo)準(zhǔn)web服務(wù)器處理靜態(tài)內(nèi)容處理得很好,但處理動(dòng)態(tài)內(nèi)容時(shí)則需要額外的幫助手段了。</p><p> 定義 靜態(tài)內(nèi)容直接來自于文本或數(shù)據(jù)文件,比如HTML或者 JPEG文件。這些文件可以隨時(shí)改變,但通過瀏覽器請(qǐng)求時(shí),卻不能自動(dòng)改變。相反,動(dòng)態(tài)內(nèi)容是臨時(shí)產(chǎn)生的,典型地,它是針對(duì)瀏覽器的個(gè)別請(qǐng)求的響應(yīng)。</p><p> 公共網(wǎng)關(guān)接口(CGI):&
14、lt;/p><p> 第一個(gè)普遍用來產(chǎn)生動(dòng)態(tài)內(nèi)容的標(biāo)準(zhǔn)是通用網(wǎng)關(guān)接口(Common Gateway Interface (CGI))。CGI使用標(biāo)準(zhǔn)的操作系統(tǒng)特征,比如環(huán)境變量和標(biāo)準(zhǔn)輸入輸出,在Web服務(wù)器間以及和主機(jī)系統(tǒng)間創(chuàng)建橋接和網(wǎng)關(guān)。其他程序可以看到web server傳遞過來的請(qǐng)求,并創(chuàng)建一個(gè)定制的響應(yīng)。當(dāng)web服務(wù)器接收到一個(gè)對(duì)CGI程序的請(qǐng)求時(shí),它便運(yùn)行這個(gè)程序并向其提供它請(qǐng)求里面所包含的信息。CGI程
15、序運(yùn)行,并將輸出返回給Web server,web server 則將輸出響應(yīng)給瀏覽器。CGI定義了一套關(guān)于什么信息將作為環(huán)境變量傳遞,以及它希望怎樣使用標(biāo)準(zhǔn)輸入和輸出的慣例。與HTTP一樣,CGI是靈活和易于實(shí)現(xiàn)的,并且已經(jīng)有大量現(xiàn)成的CGI程序。</p><p> CGI的主要缺點(diǎn)是它必須為每個(gè)請(qǐng)求運(yùn)行一個(gè)程序。這是一個(gè)相對(duì)昂貴的處理方法,對(duì)大容量站點(diǎn)來說,每分鐘有數(shù)千個(gè)請(qǐng)求,有可能使站點(diǎn)癱瘓。CGI程序的
16、另一個(gè)缺點(diǎn)是平臺(tái)依賴性,一個(gè)平臺(tái)上開發(fā)的程序不一定在另一個(gè)平臺(tái)上能運(yùn)行。</p><p> Java servlet:</p><p> Sun公司的Java Servlet平臺(tái)直接解決了CGI程序的兩個(gè)主要缺點(diǎn):</p><p> 首先,servlet 比常規(guī)CGI 程序提供更好的性能和資源利用。其次,一次編寫,隨處運(yùn)行的JAVA特性意味著servlet在有
17、JVM 的操作系統(tǒng)間是輕便的可移動(dòng)的。Servlet看起來好像是一個(gè)微小的web server。它接受請(qǐng)求并產(chǎn)生響應(yīng)。但,和常規(guī)web server不同,servlet API 是專門設(shè)計(jì)來幫助Java 開發(fā)人員創(chuàng)建動(dòng)態(tài)應(yīng)用的。</p><p> Servlet 本身是要編譯成字節(jié)碼的Java類,就像其他Java對(duì)象一樣。Servlet訪問HTTP 特定服務(wù)的API,但它仍然是一個(gè)運(yùn)行于程序之中的Java 對(duì)象
18、,并可以利用所有的Java 資產(chǎn)。為了使常規(guī)web servers能訪問servlet,servlet被安插在一個(gè)容器之中。Servlet容器連接到Web服務(wù)器。每servlet 都可以聲明它可以處理何種樣式的URL。當(dāng)符合所注冊(cè)樣式的請(qǐng)求到達(dá),web server將請(qǐng)求傳遞給容器,容器則調(diào)用響應(yīng)的servlet。但和CGI 程序不同,并不是針對(duì)每個(gè)請(qǐng)求都要?jiǎng)?chuàng)建一個(gè)新的servlet。一旦容器實(shí)例化了一個(gè)servlet,它就僅為每個(gè)新的
19、請(qǐng)求創(chuàng)建一個(gè)新的線程。Java線程可比使用CGI程序的服務(wù)器處理開銷小多了。</p><p> 一旦servlet被創(chuàng)建,使用它處理額外的請(qǐng)求僅帶來很小的額外開銷。Servlet開發(fā)人員可以使用init() 方法保持對(duì)昂貴資源的引用,比如到數(shù)據(jù)庫或者EJB Home接口的連接,以便它們可以在不同的請(qǐng)求之間進(jìn)行共享。獲得這些資源要耗費(fèi)數(shù)秒時(shí)間,這比大多數(shù)沖浪者愿意等的時(shí)間要長些。</p><p
20、> Servlet的另一個(gè)好處是,它是多線程的,servlet開發(fā)人員必須特別注意確保它們的servlet是線程安全的。學(xué)習(xí)servlet 編程,我們推薦Java Servlets by Example, 作者Alan R. Williamson[Williamson]。</p><p> JavaServer Pages:</p><p> 雖然servlets對(duì)CGI程序來
21、說前進(jìn)了一大步,但它也不是萬能靈藥。為了產(chǎn)生響應(yīng),開發(fā)人員不得不使用大量的println語句來生成HTML。比如這樣的代碼:</p><p> out.println("<P>One line of HTML.</P>");</p><p> out.println("<P>Another line of HTML.&l
22、t;/P>");</p><p> 在產(chǎn)生HTTP響應(yīng)的Servlet 中是很普遍的。也有一些庫有助于你產(chǎn)生HTML。隨著應(yīng)用越來越復(fù)雜,Java開發(fā)人員將不再扮演HTML頁面設(shè)計(jì)的角色。同時(shí),大多數(shù)項(xiàng)目經(jīng)理更喜歡將團(tuán)隊(duì)分成不同的小組。 它們喜歡HTML設(shè)計(jì)人員處理表現(xiàn)層的工作,而Java工程師則專注于業(yè)務(wù)邏輯。單獨(dú)使用servlet的做法鼓勵(lì)混合標(biāo)記和業(yè)務(wù)邏輯,很難區(qū)分團(tuán)隊(duì)人員的專業(yè)工作。&l
23、t;/p><p> 為解決這個(gè)問題,Sun提出了一個(gè)將腳本和模板技術(shù)結(jié)合到一個(gè)組件中的服務(wù)器頁面技術(shù)(JavaServer Pages)。為創(chuàng)建JSP頁面, 開發(fā)者按創(chuàng)建HTML頁面類似的方式創(chuàng)建頁面,使用相同的HTML 語法。為將動(dòng)態(tài)內(nèi)容引入頁面,開發(fā)人員可以將腳本元素置入頁面之中。腳本元素是一些標(biāo)記,封裝了可以被JSP識(shí)別的邏輯。你可以在JSP頁面中很容易的識(shí)別出腳本元素,他們被封裝在一對(duì)<% 和 %&g
24、t;標(biāo)記中。</p><p> 為了識(shí)別JSP頁面,文件需要保存為擴(kuò)展名.jsp。當(dāng)一個(gè)客戶請(qǐng)求JSP頁面時(shí),容器將頁面翻譯成Java servlet 源代碼文件,并將它編譯成Java 類文件——就象你寫的servlet文件一樣。在運(yùn)行時(shí),容器也能檢測JSP文件和相應(yīng)的類的最后更新時(shí)間。如果,JSP 文件自上次編譯以來被修改了,容器將重新翻譯和編譯JSP文件。項(xiàng)目經(jīng)理現(xiàn)在可以將表現(xiàn)層分派給HTML 開發(fā)人員,將
25、業(yè)務(wù)邏輯工作分派給JAVA開發(fā)人員。重要的是記住,JSP頁面事實(shí)上是一個(gè)servlet。你可以在servlet做的,也可以在JSP中做。</p><p><b> JavaBean:</b></p><p> JavaBean是一種 Java類,它遵從一定的設(shè)計(jì)模式,使它們易于和其他開發(fā)工具和組件一起使用。</p><p> 定義 Jav
26、aBean 是一種JAVA 語言寫成的可重用組件。要編寫JavaBean,類必須是具體類和公共類,并且具有無參數(shù)的構(gòu)造器(NON-ARGS CONSTRUCTOR)。JavaBean通過提供符合一致性設(shè)計(jì)模式的公共訪問方法將內(nèi)部字段暴露稱為屬性。眾所周知,屬性名稱也符合這種模式,其他JAVA 類可以通過自省機(jī)制發(fā)現(xiàn)和操作這些JavaBean 屬性。</p><p><b> 我們必須做的如下:<
27、/b></p><p> 1.編寫一個(gè)類,通過實(shí)現(xiàn)doStart()或者doEnd()方法來實(shí)現(xiàn)javax.servlet.jsp.tagext.TagSupport 或者javax.servlet.jsp.tagext.BodyTagSupport接口。這些方法獲得一個(gè)JspWriter對(duì)象,你可以用它來輸出你需要的HTML內(nèi)容。</p><p> 2.創(chuàng)建一個(gè)標(biāo)簽庫描述文件(
28、TLD)來將你的新建的類,映射到一個(gè)標(biāo)簽名稱。</p><p> 3.在你的Web 應(yīng)用描述符(web.xml)中定義你的<taglib> 元素。通過在JSP 頁面的頂部放置下面的語句:<%@tagliburi="/tags/app.tld prefix="app" %>來告訴JSP 頁面你將使用你自己的標(biāo)簽庫。</p><p>
29、4.這個(gè)語句導(dǎo)入將在本頁中使用的標(biāo)簽庫,并分配給它一個(gè)前綴。關(guān)于更多細(xì)節(jié),請(qǐng)參考JSP標(biāo)簽庫技術(shù)頁面。</p><p> JavaBean 設(shè)計(jì)模式提供兩種類型的方式來訪問bean 的內(nèi)部狀態(tài):訪問器(accessor) 用來讀JavaBean的狀態(tài),修改器(mutator )用來改變 JavaBean 的狀態(tài)。</p><p> Mutator 通常以小寫的set 前綴開始,后跟屬性
30、名。屬性名的第一個(gè)字母必須大寫。返回值通常是void,因?yàn)閙utator 僅僅改變屬性的值,而不返回它們。簡單屬性的mutator在其方法體中可能只有一個(gè)參數(shù),該參數(shù)可以是各種類型。Mutator也可根據(jù)其前綴稱為設(shè)置器setters 。例如,對(duì)Double 類型的屬性weight 的mutator方法體可能是:</p><p> public void setWeight(Double weight)<
31、/p><p> 相似的設(shè)計(jì)模式也用于訪問器方法的創(chuàng)建。Accessor 通常以小寫的get 為前綴,后跟屬性名。屬性名的第一個(gè)字母必須大寫。返回值必須匹配相應(yīng)的修改器方法的參數(shù)。簡單屬性的Accessor在其方法體中不能接受參數(shù)。同樣,訪問器accessor 也經(jīng)常稱為獲取器getter。</p><p> 屬性weight 的訪問器方法體可能是:public Double getWeig
32、ht()</p><p> 如果訪問器返回一個(gè)邏輯值,這種情況下有個(gè)變體模式。不使用小寫的 get,邏輯屬性的訪問器可以使用小寫的is 前綴,后跟屬性名。屬性名的首字母必須大寫。返回值肯定是邏輯值,不管是 boolean 還是Boolean。邏輯訪問器在其方法體中不能接受參數(shù)。On屬性的邏輯訪問器的方法體可能是:public boolean isOn()</p><p> 在使用Jav
33、aBean 時(shí),規(guī)范的方法體簽名扮演了極為重要的角色。其他組件可以使用Java 的反射API 通過查找前綴為set、is或者get的方法來發(fā)現(xiàn)JavaBean的屬性。如果一個(gè)組件在一個(gè)JavaBean 中發(fā)現(xiàn)一個(gè)這樣的方法,它就知道這個(gè)方法可以用來訪問或者改變JavaBean 的屬性。Sun引入JavaBean是為了用于GUI組件,但它們已經(jīng)用在Java開發(fā)的各個(gè)方面,包括Web應(yīng)用。Sun的工程師在開發(fā)JSP標(biāo)簽的擴(kuò)展類時(shí),也被設(shè)計(jì)來
34、可以和JavaBean一起工作。一個(gè)頁面的動(dòng)態(tài)數(shù)據(jù)可以使用一個(gè)JavaBean來傳遞,并且JSP標(biāo)記可以隨后使用bean的屬性來定制頁面的輸出。</p><p><b> Model 2:</b></p><p> Servlet/JSP規(guī)范的0.92 版描述了在一個(gè)應(yīng)用中使用servlet和JSP的架構(gòu)。在其后的規(guī)范中,Model 2 這個(gè)叫法消失了,但它已經(jīng)在
35、Java web開發(fā)人員中非常通用了。根據(jù)Model 2,servlet處理數(shù)據(jù)存取和導(dǎo)航流,JSP處理表現(xiàn)。Model 2使Java工程師和HTML設(shè)計(jì)者分別工作于它們所擅長和負(fù)責(zé)的部分。Model 2應(yīng)用的一部分發(fā)生改變并不強(qiáng)求其他部分也跟著發(fā)生改變。HTML開發(fā)人員可以改變程序的外觀和感覺,并不需要改變后端servlet的工作方式。Struts框架是基于Model 2的架構(gòu)。它提供一個(gè)控制器servlet來處理導(dǎo)航流和一些特殊類來
36、幫助數(shù)據(jù)訪問。隨框架也提供一個(gè)豐富的標(biāo)簽庫,以使Struts易于和JSP一起使用。</p><p><b> 小結(jié):</b></p><p> 在本文中,我們介紹了Struts應(yīng)用框架。并介紹了一些基本知識(shí),關(guān)于HTTP, CGI, Java servlet, JSP,以及JavaBean。我們也說明了Model 2應(yīng)用架構(gòu),以及它如何用來將servlets和J
37、SP 在結(jié)合在同一個(gè)應(yīng)用之中。現(xiàn)在你已經(jīng)有關(guān)于Strtus Web應(yīng)用程序模樣的初步印象,以后我們將更深入的討論Strtuts框架的理論和具體實(shí)踐。</p><p> From:http://www.doukuaspcomputer.com/ reference.asp</p><p> JSP application frameworks</p><p>
38、What are application frameworks:</p><p> A framework is a reusable, semi-complete application that can be specialized to</p><p> produce custom applications [Johnson]. Like people, software ap
39、plications are more alike than they are different. They run on the same computers, expect input from the same devices, output to the same displays, and save data to the same hard disks. Developers working on conventional
40、 desktop applications are accustomed to toolkits and development environments that leverage the sameness between applications. Application frameworks build on this common ground to provide developers with a reusable s<
41、;/p><p> A framework provides developers with a set of backbone components that have the following characteristics:</p><p> 1.They are known to work well in other applications.</p><p&g
42、t; 2. They are ready to use with the next project.</p><p> 3. They can also be used by other teams in the organization.</p><p> Frameworks are the classic build-versus-buy proposition. If you
43、 build it, you will understand it when you are done—but how long will it be before you can roll your own? If you buy it, you will have to climb the learning curve—and how long is that going to take? There is no right ans
44、wer here, but most observers would agree that frameworks such as Struts provide a significant return on investment compared to starting from scratch, especially for larger projects.</p><p> Other types of f
45、rameworks:</p><p> The idea of a framework applies not only to applications but to application componentsas well. Throughout this article, we introduce other types of frameworks that you can use with Struts
46、. These include the Lucene search engine, the Scaffold toolkit, the Struts validator, and the Tiles tag library. Like application frameworks, these tools provide semi-complete versions of a subsystem that can be speciali
47、zed to provide a custom component.</p><p> Some frameworks have been linked to a proprietary development environment. This is not the case with Struts or any of the other frameworks shown in this book. You
48、can use any development environment with Struts: Visual Age for Java, JBuilder, Eclipse, Emacs, and Textpad are all popular choices among Struts developers. If you can use it with Java, you can use it with Struts.</p&
49、gt;<p> Enabling technologies:</p><p> Applications developed with Struts are based on a number of enabling technologies.These components are not specific to Struts and underlie every Java web appli
50、cation. A reason that developers use frameworks like Struts is to hide the nasty details behind acronyms like HTTP, CGI, and JSP. As a Struts developer, you don’t need to be an alphabet soup guru, but a working knowledge
51、 of these base technologies can help you devise creative solutions to tricky problems.</p><p> Hypertext Transfer Protocol (HTTP):</p><p> When mediating talks between nations, diplomats often
52、 follow a formal protocol.</p><p> Diplomatic protocols are designed to avoid misunderstandings and to keep negotiations from breaking down. In a similar vein, when computers need to talk, they also follow
53、a formal protocol. The protocol defines how data is transmitted and how to decode it once it arrives. Web applications use the Hypertext Transfer Protocol (HTTP) to move data between the browser running on your computer
54、and the application running on the server.</p><p> Many server applications communicate using protocols other than HTTP. Some of these maintain an ongoing connection between the computers. The application s
55、erver knows exactly who is connected at all times and can tell when a connection is dropped. Because they know the state of each connection and the identity of each person using it, these are known as stateful protocols.
56、</p><p> By contrast, HTTP is known as a stateless protocol. An HTTP server will accept any request from any client and will always provide some type of response, even if the response is just to say no. Wit
57、hout the overhead of negotiating and retaining a connection, stateless protocols can handle a large volume of requests. This is one reason why the Internet has been able to scale to millions of computers.</p><
58、p> Another reason HTTP has become the universal standard is its simplicity. An HTTP request looks like an ordinary text document. This has made it easy for applications to make HTTP requests. You can even send an HTT
59、P request by hand using a standard utility such as Telnet. When the HTTP response comes back, it is also in plain text that developers can read.</p><p> The first line in the HTTP request contains the metho
60、d, followed by the location</p><p> of the requested resource and the version of HTTP. Zero or more HTTP request headers follow the initial line. The HTTP headers provide additional information to the serve
61、r. This can include the browser type and version, acceptable document types, and the browser’s cookies, just to name a few. Of the seven request methods, GET and POST are by far the most popular.</p><p> On
62、ce the server has received and serviced the request, it will issue an HTTP response. The first line in the response is called the status line and carries the HTTP protocol version, a numeric status, and a brief descripti
63、on of the status. Following the status line, the server will return a set of HTTP response headers that work in a way similar to the request headers.</p><p> As we mentioned, HTTP does not preserve state in
64、formation between requests.The server logs the request, sends the response, and goes blissfully on to the next request. While simple and efficient, a stateless protocol is problematic for dynamic applications that need t
65、o keep track of their users. (Ignorance is not always bliss.</p><p> Cookies and URL rewriting are two common ways to keep track of users between requests. A cookie is a special packet of information on the
66、 user’s computer. URL rewriting stores a special reference in the page address that a Java server can use to track users. Neither approach is seamless, and using either means extra work when developing a web application.
67、 On its own, a standard HTTP web server does not traffic in dynamic content. It mainly uses the request to locate a file and then returns that </p><p> Standard web servers handle static content and images
68、quite well but need a helping hand to provide users with a customized, dynamic response. </p><p> DEFINITION:Static content on the Web comes directly from text or data files, like HTML or JPEG files. These
69、files might be changed from time to time, but they are not altered automatically when requested by a web browser. Dynamic content, on the other hand, is generated on the fly, typically in response to an individualized re
70、quest from a browser.</p><p> Common Gateway Interface (CGI):</p><p> The first widely used standard for producing dynamic content was the Common Gateway Interface (CGI). CGI uses standard ope
71、rating system features, such as environment variables and standard input and output, to create a bridge, or gateway, between the web server and other applications on the host machine. The other applications can look at t
72、he request sent to them by the web server and create a customized response.</p><p> When a web server receives a request that’s intended for a CGI program, it runs that program and provides the program with
73、 information from the incoming request. The CGI program runs and sends its output back to the server. The web server then relays the response to the browser.</p><p> CGI defines a set of conventions regardi
74、ng what information it will pass as environment variables and how it expects standard input and output to be used. Like HTTP, CGI is flexible and easy to implement, and a great number of CGI-aware programs have been writ
75、ten.</p><p> The main drawback to CGI is that it must run a new copy of the CGI-aware program for each request. This is a relatively expensive process that can bog down high-volume sites where thousands of
76、requests are serviced per minute. Another drawback is that CGI programs tend to be platform dependent. A CGI program written for one operating system may not run on another.</p><p> Java servlets:</p>
77、<p> Sun’s Java Servlet platform directly addresses the two main drawbacks of CGI programs.First, servlets offer better performance and utilization of resources than conventional CGI programs. Second, the write-o
78、nce, run-anywhere nature of Java means that servlets are portable between operating systems that have a Java Virtual Machine (JVM).</p><p> A servlet looks and feels like a miniature web server. It receives
79、 a request and renders a response. But, unlike conventional web servers, the servlet application programming interface (API) is specifically designed to help Java developers create dynamic applications.</p><p&
80、gt; The servlet itself is simply a Java class that has been compiled into byte code, like any other Java object. The servlet has access to a rich API of HTTP-specific services, but it is still just another Java object r
81、unning in an application and can leverage all your other Java assets.</p><p> To give conventional web servers access to servlets, the servlets are plugged into containers. The servlet container is attached
82、 to the web server. Each servlet can declare what URL patterns it would like to handle. When a request matching a registered pattern arrives, the web server passes the request to the container, and the container invokes
83、the servlet.</p><p> But unlike CGI programs, a new servlet is not created for each request. Once the container instantiates the servlet, it will just create a new thread for each request. Java threads are
84、much less expensive than the server processes used by CGI programs. Once the servlet has been created, using it for additional requests incurs very little overhead. Servlet developers can use the init() method to hold re
85、ferences to expensive resources, such as database connections or EJB Home Interfaces, so that t</p><p> The other edge of the sword is that, since servlets are multithreaded, servlet developers must take sp
86、ecial care to be sure their servlets are thread-safe. To learn more about servlet programming, we recommend Java Servlets by Example, by Alan R. Williamson [Williamson]. The definitive source for Servlet information is t
87、he Java Servlet Specification [Sun, JST].</p><p> JavaServer Pages:</p><p> While Java servlets are a big step up from CGI programs, they are not a panacea. To generate the response, developer
88、s are still stuck with using println statements to render the HTML. Code that looks like:</p><p> out.println("<P>One line of HTML.</P>");</p><p> out.println("<P
89、>Another line of HTML.</P>");</p><p> is all too common in servlets that generate the HTTP response. There are libraries that can help you generate HTML, but as applications grow more complex,
90、 Java developers end up being cast into the role of HTML page designers.</p><p> Meanwhile, given the choice, most project managers prefer to divide development teams into specialized groups. They like HTML
91、 designers to be working on the presentation while Java engineers sweat the business logic. Using servlets alone encourages mixing markup with business logic, making it difficult for team members to specialize.</p>
92、<p> To solve this problem, Sun turned to the idea of using server pages to combine scripting and templating technologies into a single component. To build Java Server Pages, developers start by creating HTML pag
93、es in the same old way, using the same old HTML syntax. To bring dynamic content into the page, the developer can also place JSP scripting elements on the page. Scripting elements are tags that encapsulate logic that is
94、recognized by the JSP. You can easily pick out scripting elements on JSP </p><p> To be seen as a JSP page, the file just needs to be saved with an extension of .jsp.</p><p> When a client req
95、uests the JSP page, the container translates the page into a source code file for a Java servlet and compiles the source into a Java class file—just as you would do if you were writing a servlet from scratch. At runtime,
96、 the container can also check the last modified date of the JSP file against the class file. If the JSP file has changed since it was last compiled, the container will retranslate and rebuild the page all over again.<
97、/p><p> Project managers can now assign the presentation layer to HTML developers, who then pass on their work to Java developers to complete the business-logic portion. The important thing to remember is that
98、 a JSP page is really just a servlet. Anything you can do with a servlet, you can do with a JSP.</p><p> JavaBeans:</p><p> JavaBeans are Java classes which conform to a set of design patterns
99、 that make them easier to use with development tools and other components.</p><p> DEFINITION A JavaBean is a reusable software component written in Java. To qualify as a JavaBean, the class must be concret
100、e and public, and have a noargument constructor. JavaBeans expose internal fields as properties by providing public methods that follow a consistent design pattern. Knowing that the property names follow this pattern, ot
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫僅提供信息存儲(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 外文翻譯jsp 應(yīng)用框架
- jsp 應(yīng)用框架-外文翻譯
- jsp 應(yīng)用框架外文翻譯
- 外文翻譯----jsp應(yīng)用框架
- jsp 應(yīng)用框架-外文及翻譯
- jsp畢業(yè)設(shè)計(jì)外文翻譯--jsp 應(yīng)用框架
- jsp外文翻譯--jsp技術(shù)概述與應(yīng)用框架
- jsp技術(shù)概述與應(yīng)用框架外文翻譯
- 計(jì)算機(jī)外文翻譯---jsp應(yīng)用框架
- 計(jì)算機(jī)外文翻譯---jsp 應(yīng)用框架
- 計(jì)算機(jī)專業(yè)外文翻譯---jsp 應(yīng)用框架
- jsp 應(yīng)用框架外文翻譯、中英對(duì)照、英漢互譯
- JSP技術(shù)概述與應(yīng)用框架外文翻譯畢業(yè)設(shè)計(jì).doc
- jsp外文翻譯
- 外文翻譯---jsp簡介
- jsp 技術(shù)外文翻譯
- jsp技術(shù)外文翻譯
- 外文翻譯---jsp簡介
- jsp 外文翻譯--jsp及其web技術(shù)
- jsp介紹外文翻譯
評(píng)論
0/150
提交評(píng)論