【正文】
過 tags和 scriptlets訪問存在于服務(wù)端的資源的應(yīng) 用邏輯。 Web服務(wù)器在遇到訪問 JSP網(wǎng)頁的請(qǐng)求時(shí),首先執(zhí)行其中的程序段,然后將執(zhí)行結(jié)果連同 JSP文件中的 HTML代碼一起返回給客戶。 JSP與 Java Servlet 一樣,是在服務(wù)器端執(zhí)行的,通常返回該客戶端的就是一個(gè)HTML文本,因此客戶端只要有瀏覽器就能瀏覽。目前較新的是 , 。服務(wù)器在頁面被客戶端請(qǐng)求以后對(duì)這些 Java代碼進(jìn)行處理,然后將生成的 HTML頁面返回給客戶端的瀏覽器。 JSP具備了 Java技術(shù)的簡單易用,完全的面向?qū)ο?,具有平臺(tái)無關(guān)性且安全可靠,主要面向因特網(wǎng)的所有特點(diǎn)。在這一點(diǎn)上 Java比 PHP更出色,除了系統(tǒng)之外,代碼不用做任何更改 。基本上可以在所有平臺(tái)上的任意環(huán)境中開發(fā),在任意環(huán)境中進(jìn)行系統(tǒng)部署,在任意環(huán)境中擴(kuò)展。 ( 3)強(qiáng)大的可伸縮性。 ( 4)多樣化和功能強(qiáng)大的開發(fā)工具支持。 JSP技術(shù)的弱勢 ( 1) 與 ASP一樣, Java的一些優(yōu)勢正是它致命的問題所在。 ( 2) Java的運(yùn)行速度是用 class常駐內(nèi)存來完成的,所以它在一些情況下所使用的內(nèi)存比起用戶數(shù)量來說確實(shí)是 “最低性能價(jià)格比 ”了。 JSP六種內(nèi)置對(duì)象: request, response, out, session, application, config, pagecontext, page, exception. 一 .request 對(duì)象: 該對(duì)象封裝了用戶提交的信息,通過調(diào)用該對(duì)象相應(yīng)的方法可以獲取封裝的信息,即使用該對(duì)象可以獲取用戶提交信息。 三. session對(duì)象 session: session對(duì)象是一個(gè) JSP內(nèi)置對(duì)象,它在第一個(gè) JSP頁面被裝載時(shí)自動(dòng)創(chuàng)建,完成會(huì)話期 管理。當(dāng)一個(gè)客戶訪問一個(gè)服務(wù)器時(shí),可能會(huì)在這個(gè)服務(wù)器的幾個(gè)頁面之間反復(fù)連接,反復(fù)刷新一個(gè)頁面,服務(wù)器應(yīng)當(dāng)通過某種辦法知道這是同一個(gè)客戶,這就需要 session對(duì)象。當(dāng)客戶再訪問連接該服務(wù)器的其他頁面時(shí),不再分配給客戶新的 session對(duì)象,直到客戶關(guān)閉瀏覽器后,服務(wù)器端該客戶的 session對(duì)象才取消,并且和客戶的會(huì)話對(duì)應(yīng)關(guān)系消失。 四. aplication對(duì)象 1.什么是 application: 服務(wù)器啟動(dòng)后就產(chǎn)生了這個(gè) application對(duì)象,當(dāng)客戶再所訪問的網(wǎng)站的各個(gè)頁面之間瀏覽時(shí),這個(gè) application對(duì)象都是同一個(gè),直到服務(wù)器關(guān)閉。 2. application對(duì)象常用方法 : (1)public void setAttribute(String key,Object obj): 將參數(shù) Object 指定的對(duì)象obj添加到 application對(duì)象中,并為添加的對(duì)象指定一個(gè)索引關(guān)鍵字。 五. out 對(duì)象 out 對(duì)象是一個(gè)輸出流,用來向客戶端輸出數(shù)據(jù)。 六. Cookie Cookie: Cookie是 Web服務(wù)器保存在用戶硬盤上的一段文本。 舉例來說,一個(gè) Web站點(diǎn)可能會(huì)為每一個(gè)訪問者產(chǎn)生一個(gè)唯一的 ID,然后以Cookie文件的形式保存在每個(gè)用戶的機(jī)器上。它們最常 存放的地方是: c:\windows\cookies(在 Window2021中則是C:\Documents and Settings\您的用戶名 \Cookies ) Cookie是以 “關(guān)鍵字 key=值 value“的格式來保存紀(jì)錄的 . 2.創(chuàng)建一個(gè) Cookie對(duì)象,調(diào)用 Cookie對(duì)象的構(gòu)造函數(shù)可以創(chuàng)建 Cookie。 Cookie c=new Cookie(“username”,”john”)。 格式: (c) 4.讀取保存到客戶端的 Cookie,使用 request 對(duì)象的 getCookies()方法,執(zhí)行時(shí)將所有客戶端傳來的 Cookie對(duì)象以數(shù)組的形式排列,如果要取出符合需要的Cookie對(duì)象,就需要循環(huán)比較數(shù)組內(nèi)每個(gè)對(duì)象的關(guān)鍵字。s speed is class to plete the permanent memory, so in some cases by the use of memory pared to the number of users is indeed a minimum cost performance. On the other hand, it also needs disk space to store a series of. Java documents and. Class, as well as the corresponding versions of documents. JSP six builtin objects: request, response, out, session, application, config, pagecontext, page, exception. 1. Request for: The object of the package of information submitted by users, by calling the object corresponding way to access the information package, namely the use of the target users can access the information. 2. Response object: The customer39。s first visit to a server on the JSP pages, JSP engines produce a session object, and assigned a String type of ID number, JSP engine at the same time, the ID number sent to the client, stored in Cookie, this session objects, and customers on the establishment of a onetoone relationship. When a customer to connect to the server of the other pages, customers no longer allocated to the new session object, until, close your browser, the clientserver object to cancel the session, and the conversation, and customer relationship disappeared. When a customer reopen the browser to connect to the server, the server for the customer to create a new session object. 四 . aplication target 1. What is the application: Servers have launched after the application object, when a customer to visit the site between the various pages here, this application objects are the same, until the server is down. But with the session difference is that all customers of the application objects are the same, that is, all customers share this builtin application objects. 2. application objects monly used methods: (1) public void setAttribute (String key, Object obj): Object specified parameters will be the object obj added to the application object, and to add the subject of the designation of a keyword index. (2) public Object getAttribute (String key): access to application objects containing keywords for. 五 . out targets out as a target output flow, used to client output data. out targets for the output data. 六 . Cookie 1. What is Cookie: Cookie is stored in Web server on the user39。s puter to store information on and then get back to it. For example, a Web site may be generated for each visitor a unique ID, and then to Cookie in the form of documents stored in each user39。 3. If the JSP in the package good Cookie object to send to the client, the use of the response addCookie () method. Format: (c) 4. Save to read the client39