【正文】
而這個引擎本身也是一個Servlet。JSP的運行過程如下所示:(1)JSP引擎先把該JSP文件轉(zhuǎn)換成一個Java源文件(Servlet),在轉(zhuǎn)換時如果發(fā)現(xiàn)JSP文件有任何語法錯誤,轉(zhuǎn)換過程將中斷,并向服務(wù)端和客戶端輸出出錯信息。(2)如果轉(zhuǎn)換成功,JSP引擎用javac把該Java源文件編譯成相應的class文件。(3)創(chuàng)建一個該Servlet(JSP頁面的轉(zhuǎn)換結(jié)果)的實例,該Servlet的jspInit()方法被執(zhí)行,jspInit()方法在Servlet的生命周期中只被執(zhí)行一次。(4)jspService()方法被調(diào)用來處理客戶端的請求。對每一個請求,JSP引擎創(chuàng)建一個新的線程來處理該請求。如果有多個客戶端同時請求該JSP文件,則JSP引擎會創(chuàng)建多個線程。每個客戶端請求對應一個線程。以多線程方式執(zhí)行可以大大降低對系統(tǒng)的資源需求,提高系統(tǒng)的并發(fā)量及響應時間。但不過也應該注意多線程的編程限制,由于該Servlet始終駐于內(nèi)存,所以響應是非常快的。(5),服務(wù)器將根據(jù)設(shè)置決定是否對該文件重新編譯,如果需要重新編譯,則將編譯結(jié)果取代內(nèi)存中的Servlet,并繼續(xù)上述處理過程。(6)雖然JSP效率很高,但在第一次調(diào)用時由于需要轉(zhuǎn)換和編譯而有一些輕微的延 遲。此外,在任何時候如果由于系統(tǒng)資源不足的原因,JSP引擎將以某種不確定的方式將Servlet從內(nèi)存中移去。當這種情況發(fā)生時jspDestroy()方法首先被調(diào)用。(7)然后Servlet實例便被標記加入“垃圾收集”處理??稍趈spInit()中進行一些初始化工作,如建立與數(shù)據(jù)庫的連接,或建立網(wǎng)絡(luò)連接,從配置文件中取一些參數(shù)等,在jspDestory()中釋放相應的資源。基于Java語言的JSP技術(shù)具有很多其他動態(tài)網(wǎng)頁技術(shù)所沒有的特點,具體表現(xiàn)在如下方面: 1.簡便性和有效性 JSP動態(tài)網(wǎng)頁的編寫與一般的靜態(tài)HTML的網(wǎng)頁編寫是十分相似的。只是在原來的HTML網(wǎng)頁中加入一些JSP專有的標簽,或是一些腳本程序(此項不是必需的)。這樣,一個熟悉HTML網(wǎng)頁編寫的設(shè)計人員可以很容易進行JSP網(wǎng)頁的開發(fā)。而且開發(fā)人員完全可以不自己編寫腳本程序,而只是通過JSP獨有的標簽使用別人已寫好的部件來實現(xiàn)動態(tài)網(wǎng)頁的編寫。這樣,一個不熟悉腳本語言的網(wǎng)頁開發(fā)者,完全可以利用JSP做出漂亮的動態(tài)網(wǎng)頁。而這在其他的動態(tài)網(wǎng)頁開發(fā)中是不可實現(xiàn)的。2.程序的獨立性JSP是Java API家族的一部分,它擁有一般的Java程序的跨平臺的特性。換句話說,就是擁有程序的對平臺的獨立性,即Write once,Run anywhere!。3.程序的兼容性 JSP中的動態(tài)內(nèi)容可以各種形式進行顯示,所以它可以為各種客戶提供服務(wù),即從使用HTML/DHTML的瀏覽器,到使用WML的各種手提無線設(shè)備(例如,移動電話和個人數(shù)字設(shè)備PDA),再到使用XML的B2B應用,都可以使用JSP的動態(tài)頁面。4.程序的可重用性 在JSP頁面中可以不直接將腳本程序嵌入,而只是將動態(tài)的交互部分作為一個部件加以引用。這樣,一旦這樣的一個部件寫好,它可以為多個程序重復引用,實現(xiàn)了程序的可重用性。現(xiàn)在,大量的標準JavaBeans程序庫就是一個很好的例證。欲從導入文件的上下文之外導入JSP代碼段。使用c:import JSTL核心標記。原文JSP Technology Conspectus And SpecialtiesThe JSP (Java Server mix) technology is used by the Sun microsystem issued by the pany to develop dynamic Web application technology. With its easy, crossplatform, in many dynamic Web application programming languages, in a short span of a few years, has formed a plete set of standards, and widely used in electronic merce, etc. In China, the JSP now also got more extensive attention, get a good development, more and more dynamic website to JSP technology. The related technologies of JSP are briefly introduced.The JSP a simple technology can quickly and with the method of generating Web pages. Use the JSP technology Web page can be easily display dynamic content. The JSP technology are designed to make the construction based on Web applications easier and efficient, and these applications and various Web server, application server, the browser and development tools work together.The JSP technology isn39。t the only dynamic web technology, also not the first one, in the JSP technology existed before the emergence of several excellent dynamic web technology, such as CGI, ASP, etc. With the introduction of these technologies under dynamic web technology, the development and the JSP. TechnicalJSP the development background and development historyIn web brief history, from a world wide web that most of the network information static on stock transactions evolution to acquisition of an operation and infrastructure. In a variety of applications, may be used for based on Web client, look no restrictions.Based on the browser client applications than traditional based on client/server applications has several advantages. These benefits include almost no limit client access and extremely simplified application deployment and management (to update an application, management personnel only need to change the program on a server, not thousands of installation in client applications). So, the software industry is rapidly to build on the client browser multilayer application.The rapid growth of exquisite based Web application requirements development of technical improvements. Static HTML to show relatively static content is right choice, The new challenge is to create the interaction based on Web applications, in these procedures, the content of a Web page is based on the user39。s request or the state of the system, and are not predefined characters.For the problem of an early solution is to use a CGI BIN interface. Developers write to interface with the relevant procedures and separate based on Web applications, the latter through the Web server to invoke the former. This plan has serious problem each new extensible CGI requirements in a new process on the server. If multiple concurrent users access to this procedure, these processes will use the Web server of all available resources, and the performance of the system will be reduced to extremely low.Some Web server providers have to provide for their server by plugins and the API to simplify the Web application development. These solutions are associated with certain Web server, cannot solve the span multiple suppliers solutions. For example, Microsoft39。s Active Server mix (ASP) technology in the Web page to create dynamic content more easily, but also can work in Microsoft on Personal Web Server and IIS.There are other solutions, but cannot make an ordinary page designers can easily master. For example, such as the Servlet Java technologies can use Java language interaction application server code easier. Developers to write such Servlet to receive signals from the Web browser to generate an HTTP request, a dynamic response (may be inquires the database to finish the request), then send contain HTML or XML documents to the response of the browser.note: one is based on a Java Servlet Java technical operation in the server program (with different, the latter operating in the Applet browser end). In this book the Servlet chapter 4.Using this method, the entire page must have made in Java Servlet. If developers or Web managers want to adjust page, you39。ll have to edit and repile the Servlet Java, even in logic has been able to run. Using this method, the dynamic content with the application of the page still need to develop skills.Obviously, what is needed is a industry to create dynamic content within the scope of the pages of the solution. This program will solve the current scheme are limited. As follows:q can on any Web server or applications.q will application page displays and