【正文】
45 編寫業(yè)務(wù)邏輯 ........................................................................................................... 45 設(shè)置服務(wù) 器監(jiān)聽端口 ...................................................................................... 45 實(shí)現(xiàn) Hello FastJsonWeb ............................................................................... 46 用戶登錄功能 ................................................................................................ 48 .................................................................................................................. 52 第六 章 不足與發(fā)展 ................................................................................................................ 53 框架的不足 .............................................................................................................. 53 框架的發(fā)展 .............................................................................................................. 55 本章小結(jié) .................................................................................................................. 56 參考文獻(xiàn) ......................................................................................................................... 57 謝 辭 ..................................................................................................................................... 58 第 1 頁 共 62 頁 基于 的小型框架設(shè)計(jì)與實(shí)現(xiàn) 摘要: 是一種新的軟件開發(fā)平臺(tái),它不僅是一門獨(dú)立的語言,也與Python、 Ruby 一樣,既是語言也是平臺(tái)。 將 javascript 從瀏覽器移植到了普通服務(wù)器上。使得 javascript 也能實(shí)現(xiàn)了諸如文件系統(tǒng)、操作系統(tǒng)、網(wǎng)絡(luò)通信等功能。 Node 運(yùn)行在 Chorme 的 V8 引擎上,采用異 步 I/O 與事件驅(qū)動(dòng)的架構(gòu)設(shè)計(jì)和單線程模型,并且內(nèi)置了 HTTP 服務(wù)器,主要用于構(gòu)建高性能,高并發(fā),高擴(kuò)展的服務(wù)器。 具有高性能的同時(shí),對(duì)于底層的封裝比較低,如一般的請(qǐng)求數(shù)據(jù)等都需要分析 Http協(xié)議并將所需的數(shù)據(jù)從 request數(shù)據(jù)流中解析出來,沒有提供如 java web般豐富的 API,這既是優(yōu)點(diǎn)也是缺點(diǎn),優(yōu)點(diǎn)在于為開發(fā)者提供了非常大的自由性,可以利用底層接口完成各種各樣的功能,缺點(diǎn)在于直接使用底層接口做系統(tǒng)應(yīng)用開發(fā),效率非常低下,因?yàn)樾枰治龊吞幚砀鞣N數(shù)據(jù)。 剛推廣不久,國(guó)內(nèi)還比較缺少 使用 做應(yīng)用開發(fā)的框架,如果直接使用 底層 API 進(jìn)行應(yīng)用開發(fā)有較大的困難,基于此點(diǎn),本論文開發(fā)設(shè)計(jì)一個(gè)簡(jiǎn)單小型的 MVC框架,簡(jiǎn)化 的使用的同時(shí)提高開發(fā)效率。 目前 web 應(yīng)用中,普遍使用了 MVC 模式(即 ModelViewController,模型,視圖,控制器)。如基于 JAVA EE 的 Struts2 + Spring3 + jsp MVC 模式等 。借鑒這些其他平臺(tái)上現(xiàn)有的框架結(jié)構(gòu)和功能,設(shè)計(jì)開發(fā) FastJsonWeb 框架。本框架將封裝 的底層接口,對(duì) 請(qǐng)求數(shù)據(jù)等提供統(tǒng)一簡(jiǎn)潔的方式,從而較大幅度的提升開發(fā)效率?;趯?duì)不同平臺(tái)現(xiàn)有框架分析提取出本框架的功能點(diǎn)。這些功能點(diǎn)包括 路由轉(zhuǎn)發(fā)與映射,屬性注入, Cookie 實(shí)現(xiàn), Sesison 實(shí)現(xiàn)等。 關(guān)鍵詞: 。javascript。 第 2 頁 共 62 頁 ABSTRACT is not only a separate language,but a new software development platform. Just like the Python and the Ruby, they are both language and transplant the javascript from your browser to a mon server. That makes JavaScript can achieve as file systems, operating systems, work munications, and other is always running in Chorme V8 engine, with asynchronous I / O and eventdriven architecture design and singlethreaded model, and builtin HTTP server, mainly for building highperformance, highconcurrency, highly scalable really get a high performance ,while the package of bottom part is low example, the mon data requested need analysis of HTTP and analyze the required data from the request data stream,without providing a rich java web style offered an advantage and a disadvantage. The advantage is that it provided the developers with a lot of freedom so that the developers can use the lowlevel interface to plete a variety of functions, while the disadvantage is that the direct use of the lowlevel interface for system application development got very low efficiency, because of the analyzing and processing for the various kinds of data need a lot of is just carried our, in our country, the framework used the in doing application development is still lacking. A directly use of the underlying to work on an application development may be much more difficult. In order to deal with this kind of situation, this article will describe a design of a simple and small MVC framework to simplified the use of , and to improve the development efficiency at the same time. Nowadays, Web applications get a wide use of the MVC pattern (ModelViewController, Model, View, Controller). Such as the Struts2 + Spring3 + jsp MVC model based JAVA EE . Learning from the structure and function of these existing framework, this article try to describe the design and development of FastJsonWeb framework. This framework will pack the underlying interface, and provide a unified and concise manner to the request data, which will improve the development efficiency a lot. This article will extract the framework function points according to the analysis of the existing framework of different platforms. These function points include the route forwarding and mapping, property injection, cookie achievement and Sesison achievement and something more. 第 3 頁 共 62 頁 第一章 緒論 介紹 隨著網(wǎng)絡(luò)技術(shù)的發(fā)展和網(wǎng)絡(luò)平臺(tái)的推廣,越來越多的應(yīng)用是基于網(wǎng)頁形式來提供。其中 javascript 是網(wǎng)頁應(yīng)用技術(shù)中不可缺少的一部分。 Javascript 跟隨網(wǎng)絡(luò)技術(shù)的發(fā)展得到了也得到了大幅的提升。越來越多的人使用 javascript。由于javascript 在瀏覽器端具有極高的執(zhí)行效率,并且兼容多種流浪器,這促使其中一部分人思考是否可以把 javascript 放在服務(wù)端運(yùn)行,能夠像其他 web 語言一樣提供業(yè)務(wù)邏輯處理。于是不久 便誕生了。 是一種 新的軟件開發(fā)平臺(tái),它的特殊性決定了它不僅可以作為一門開發(fā)編程語言,也可以像 Ruby 、 Pythond 等語言一樣作為一個(gè)開發(fā)者平臺(tái)。 將 javascript 從瀏覽器移植到了普通服務(wù)器上 ,它運(yùn)行在 Chrome 的 V8 高速引擎上,實(shí)現(xiàn)了操作系統(tǒng)訪問、網(wǎng)絡(luò)通信、文件讀寫等功能。 目前 web 應(yīng)用普遍采用 Tomcat,Apache Server,IIS等做 HTTP 服務(wù)器, HTML,CSS javascript 做前端展示,以 瀏覽器 服務(wù)器 后臺(tái) 容器 模式來進(jìn)行請(qǐng)求應(yīng)答。該模式下請(qǐng)求通過了一層 或多層轉(zhuǎn)發(fā),使得通信效率較低。而在 Node 中,后臺(tái)容器 用 C++語言設(shè)計(jì)把服務(wù)器和容器本身融合在一起,采用 瀏覽器 后臺(tái)容器 模式進(jìn)行請(qǐng)求應(yīng)答,大大提高了通信的效率。不同于其他的語言的線性執(zhí)行, Node 采用事件驅(qū)動(dòng)機(jī)制,充分利用了 CPU 的時(shí)間片輪轉(zhuǎn)機(jī)制,很大程度上降低了 CPU 的空閑率,同時(shí)它異步 I/O 與事件驅(qū)動(dòng)的架構(gòu)設(shè)計(jì)和單線程模型對(duì)于構(gòu)建高性能,高并發(fā),高擴(kuò)展的服務(wù)器具有相當(dāng)大的優(yōu)勢(shì)。因此,采用 web應(yīng)用或者企業(yè)應(yīng)用能夠較大程度的降低硬件成本和提高應(yīng)用處理業(yè)務(wù)的效率。新的開 發(fā)平臺(tái),需要新的發(fā)展。 平臺(tái)的優(yōu)勢(shì)領(lǐng)域 自身融合入 HTTP 服務(wù)器,這對(duì)于組合網(wǎng)站和服務(wù)器是非常簡(jiǎn)單方便的。這是它和其他 web 語言如 PHP、 Perl 的不同所在。比如,在使用 PHP 進(jìn)行業(yè)務(wù)系統(tǒng)開發(fā),首先必須搭建一個(gè) HTTP 服務(wù)器如 Apache, IIS 之類。然后通過 該 第 4 頁 共 62 頁 Http 服務(wù)器的模塊加載或 CGI 調(diào)用,將腳本的執(zhí)行結(jié)果反饋顯示在用戶端。使用 平臺(tái)好處之一在于不用額外搭建 HTTP 服務(wù)器, 本身融合的 Http服務(wù)器既可 以作為開發(fā)階段的調(diào)試環(huán)境也可以直接作為產(chǎn)品提供給客戶使用。除此之外,自帶的服務(wù)器性能足以滿足生產(chǎn)環(huán)境的要求。 既可以在網(wǎng)絡(luò)環(huán)境下運(yùn)行也可以非網(wǎng)絡(luò)的環(huán)境下運(yùn)行,如即時(shí)編譯終端。 雖然使用 javascript 語言,但是它同樣可以調(diào)用 C或者 C++ 的函數(shù)庫(kù),完成對(duì)性能要求非常高的功能的實(shí)現(xiàn)。