版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、<p> MySQL和JSP的Web應用程序</p><p> JSP開發(fā)人員構(gòu)建Web應用程序時遇到需要強大的數(shù)據(jù)庫連接的特殊問題。 MySQL和JSP的Web應用程序解決了構(gòu)建數(shù)據(jù)驅(qū)動的應用程序JavaServer頁面上的發(fā)展模式為基礎(chǔ)的挑戰(zhàn)。 MySQL和JSP的Web應用程序開始一個對JSP數(shù)據(jù)庫開發(fā) - JavaServer頁面,JDBC和數(shù)據(jù)庫模式所需的核心技術(shù)概述。該書然后概述并提出了
2、互聯(lián)網(wǎng)商業(yè)應用演示,如接收和處理用戶輸入,設計和實施業(yè)務規(guī)則,并平衡服務器上的用戶負載的概念。通過JDBC(Java數(shù)據(jù)庫連接),開發(fā)人員能夠與大多數(shù)商業(yè)數(shù)據(jù)庫如Oracle進行溝通。在MySQL和JSP的Web應用中心提交了一份關(guān)于開源工具MySQL和Tomcat的解決方案,使讀者一個經(jīng)濟實惠的方式來測試書中的例子的應用程序和試驗。</p><p> 那么JSP是怎么一回事呢?</p><
3、p> 如果您符合上述要求的,你對這個問題的答案應該已經(jīng)有一個相當不錯的理解。 JSP是所有關(guān)于做高度面向?qū)ο蟮木W(wǎng)站,可以利用所有的現(xiàn)代軟件工程最佳實踐。這些做法包括諸如SQL數(shù)據(jù)庫和基于UML設計的東西。這并不是說JSP是萬能的而且使用它會自動將您的網(wǎng)站上的工程藝術(shù)的典范。這只是盡可能地用其他任何技術(shù)用JSP設計不良網(wǎng)站。這就是為什么,當你詳細檢查文本的時候,你會看到如何合并最佳方法以及項目得到的壓力時候如何避免方便的陷阱。JS
4、P它本身就是從第一個靜態(tài)Web服務器開始的一個沿路徑循序漸進的步驟,通過CGI移動功能的服務器,最后腳本功能的服務器的第一代。 JSP是一個比Java引擎能夠熟悉網(wǎng)頁的的少了一個Java組件的Web服務器。</p><p> JSP是由Java servlet發(fā)展演變而來的。servlet允許開發(fā)人員處理傳入使用Java程序能夠訪問的所有正常的信息,一個共同的網(wǎng)關(guān)接口(CGI)程序?qū)eb請求。此外,該serv
5、let可以訪問會話持久對象。這是Java的都與一個特定的用戶會話,可用于存儲請求之間的狀態(tài)對象。 Servlet編程是一個允許開發(fā)人員編寫結(jié)構(gòu)良好的模塊化的Web應用程序使用面向?qū)ο笳Z言的重要一步。它還解決了狀態(tài)持久性的問題,用戶和應用程序執(zhí)行的一個動作或一系列動作期間讓更多的信息駐留在服務器上而且較少的反復在用戶和服務器之間傳遞。 Servlet還遭受一大問題。因為他們最終需要輸出HTML中,HTML編碼必須被嵌入在servlet代碼
6、中。導致如下所示的一段代碼片段:</p><p> Out.println("<HTML>\n<HEAD>\n<TITLE>Thank you for </p><p> Registering</TITLE></HEAD>\n"); </p><p> Out.println(&
7、quot;<IMG SRC=\"thanks.jpg\" WIDTH=200 HEIGHT=100 ALIGN=\"LEFT\”>"); </p><p> 當你編碼很多網(wǎng)頁時,這種嵌入式是非常古老非??斓?。此外,必須避免所有引號會導致的很多混亂和如果你遺漏了一個反斜杠帶來難以發(fā)現(xiàn)的錯誤。最終,一個較好的方法出現(xiàn)。假設你能結(jié)合最好的靜態(tài)HTML頁面和servl
8、et的交互能力。其結(jié)果是JavaServer頁面(在微軟方面,結(jié)果是活動服務器頁面)。JSP是非常復雜強大的。在接下來的章節(jié)中,你會通過這個細節(jié)流程,但就目前而言,這里是主要的步驟:</p><p> 1、接到請求時從使用普通的HTTP請求格式的瀏覽器。</p><p> 2、WEB服務器切換到JSP的請求,JSP著眼于找到合適的JSP文件。</p><p>
9、 3、.jsp文件轉(zhuǎn)換成.Java文件,包含Java代碼,將創(chuàng)建一個類,它的名稱是從.jsp的文件名而得。</p><p> 4、JSP然后用javac編譯.java文件產(chǎn)生一個.class文件。注意如果一個.class文件已經(jīng)存在而且比.jsp文件新則可以跳過先前的兩步。</p><p> 5、一個新創(chuàng)建的類實例被實例化,并發(fā)送_jspService消息。</p>&l
10、t;p> 6、新的實例看看是否已經(jīng)有一個被稱為user的stuff.User對象實例在當前連接的用戶會話對象的空間存在。如果沒有,一個實例被實例化。</p><p> 7、作為服務stuff.jsp的一部分,user實例將被GetUserName()方法調(diào)用。</p><p> 8、如果JSP處理需要訪問數(shù)據(jù)庫中的信息,它將使用JDBC來進行連接和處理SQL請求。</p&
11、gt;<p> 正如你可以看到,巨大的能量是在現(xiàn)有的JSP世界里。開發(fā)者可以自由編寫大多數(shù)看起來像HTML的Web頁面,除非到Java標注是要求最喜歡看的HTML。但是,在同一時間,他們可以自由地充分發(fā)展充實面向?qū)ο蟮膽贸绦蚴褂肑ava會帶來負擔的所有功能。他們也得到servlet的所有優(yōu)點,包括會話持久性。</p><p> 為什么我們需要的數(shù)據(jù)庫?</p><p>
12、 好,一個原因就是為了讓拉里埃里森想到比爾蓋茨的時候,他的Oracle有能力保持自己百憂解。更嚴重的回答是相同的原因也就是駕駛?cè)讼劝聪箩槍σ粔K濕粘泥:因為把事情記下來是好的。 Web服務器是了不起的創(chuàng)造,但他們是一個有點像白癡專家。請他們?yōu)橐粋€網(wǎng)頁或運行Java的一段,他們表演的像一個冠軍。但開始要求他們記住他們五分鐘前做了什么,和他們顯露的比一個肥皂劇里的人物失憶還快。</p><p> 第一個也是最重要的
13、原因是你使用的數(shù)據(jù)庫是有大量的數(shù)據(jù)在電子商務交易里,你必須記住并跟蹤:</p><p> ?一個用戶的姓名,地址,信用卡和其他信息以前進入了一個注冊頁面</p><p> ?帽子的用戶可能把以前留下交易放進購物車</p><p> ?哪些物品有存貨,以及它們的價格,描述等等</p><p> ?訂單需要履行,訂單已發(fā)貨,并已待補物品。
14、</p><p> 現(xiàn)在,你可以存儲所有這些信息在服務器上的硬盤平面文件中,但也有你想保存的數(shù)據(jù)的其他重要屬性:</p><p> ?如果交易部分失敗,您希望能夠收回交易。</p><p> ?您希望能夠找到Web服務器安全的地方定位數(shù)據(jù),這可能是完全在DMZ或外部的防火墻。</p><p> ?您希望能夠如用戶數(shù)據(jù)或產(chǎn)品快速訪問數(shù)據(jù)
15、,即使有數(shù)千或上百萬數(shù)據(jù)。</p><p> 當你添加這些項目的購物清單,只有一個關(guān)系數(shù)據(jù)庫才會真正的影響工作效率。</p><p><b> MySQL </b></p><p> 許多網(wǎng)站不需要Oracle的歷史優(yōu)勢(和價格標簽)。 MySQL是一個開源SQL數(shù)據(jù)庫可供任何人使用,擁有許多(盡管不是全部)的先前數(shù)據(jù)庫的功能,如Orac
16、le。</p><p> MySQL是可用于幾乎所有的電腦上有相當好的能力是相當輕量級的處理器,安裝方便(10分鐘,而不像Oracle需要多個小時)。</p><p> 所以,也許你想知道,有什么收獲?沒有得到什么,你在MySQL中,使人們把目光轉(zhuǎn)向到Oracle?那么,MySQL是一個不錯的小程序包,但它缺少一些東西,不然會是不錯的一個完美的世界。</p><p&
17、gt; 一個主要特點就是MySQL不提供數(shù)據(jù)庫一致性檢查。您可以使用您的模式外鍵的標簽,但MySQL會忽略它們。據(jù)我所知許多數(shù)據(jù)庫管理員會認為這是一個很糟糕的事情。</p><p> 外鍵約束防止你創(chuàng)建數(shù)據(jù)不一致。例如,假設你有一個像這樣的數(shù)據(jù)庫表:</p><p> CREATE TABLE USER ( </p><p> USERID INTEGER,
18、 </p><p> FIRST_NAME VARCHAR(80), </p><p> LAST_NAME VARCHAR(80)); </p><p> CREATE TABLE PURCHASE ( </p><p> USERID FOREIGN KEY USER(USERID), </p>&
19、lt;p> ITEM INTEGER, </p><p> QUANTITY INTEGER); </p><p> 在諸如Oracle的數(shù)據(jù)庫里,如果你創(chuàng)建了一個在PURCHASE 表ID為3的用戶輸入數(shù)據(jù)庫,在USER表里可能已經(jīng)有一個ID為3的用戶或錯誤會發(fā)生。同樣,如果它在PURCHASE理是作為參考,你就不能從表USER里刪除ID為3的用戶,MySQL的人們做了一個漂
20、亮慷慨激昂的論點關(guān)于在各自的文檔進行數(shù)據(jù)的完整性取決于外鍵是無論如何都是一個壞主意,但是說服你的這種哲學的DBA是很可能淪為一個宗教辯論,</p><p> 此外,其他一些功能缺失,如子查詢和SELECT INTO。但可能是其他主要功能,你會漏掉回滾/提交的功能。 MySQL不會執(zhí)行回滾和為某些特殊類型的表提交,但他們并不全是。同樣,MySQL的人提供他們自己的難題為什么MySQL是好的,但能夠回滾事務是(在我
21、看來)重要以確保您有可用。 </p><p> 回滾可以在開始做一系列交易之前在數(shù)據(jù)庫設置一個保存點,并能要么回滾到原來的狀態(tài)或提交在結(jié)束時候的改變。例如,當記錄一次購買,你需要記錄一個針對用戶的帳戶扣款,并輸入到shipping表記錄,讓你知道后來ship的項目。比方說,第二部分失敗。你不會要收取用戶,但沒有ship的項目。因此,你要回滾到事務開始之前的狀態(tài)。 </p><p> 因
22、此,MySQL不是一個成熟的數(shù)據(jù)庫產(chǎn)品,至少,還不是。它對于世界上90% 的電子商務網(wǎng)仍然是相當好的,但是,4.0版本在撰寫本文時最初的版本,解決了這些問題,包括行級鎖定和事務控制數(shù)量。</p><p> 把Tomcat和MySQL的結(jié)合</p><p> Tomcat和MySQL的結(jié)合為你用它來學習、開發(fā)和部署JSP應用程序提供了一個強大的、可靠的和免費的平臺。而且,最好的是,您開發(fā)
23、的代碼將使用這個平臺很好地運行使用iPlanet和Oracle或WebSphere和SQL Server。</p><p> 作為一個學習工具,兩者的結(jié)合幾乎是“參考實現(xiàn)“他們(JSP和SQL)各自的協(xié)議。因此,當你熟悉了解項目的詳細情況時,你不會接到任何惡劣的廠商專有的壞習慣。</p><p> 此外,你可以享受你正在支持開源軟件活動的知識。開放源碼軟件是根據(jù)多個公共許可證的編碼,往
24、往是GNU通用公共許可證(GPL)的人免費提供。</p><p> 為什么支持這項活動是很好的?對于這個問題的答案有兩點:一個是技術(shù)的和一個政治的。從技術(shù)上講,這是一件好事,因為開源軟件往往鼓勵如JSP和JDBC開放標準的開發(fā),讓您從一個更大的群體里去選擇你的工具,而不是被鎖定成為一個廠商的專有解決方案。從政治上來說這是一個積極的事,因為它保持政治上的大公司的誠實。 WebLogic和iPlanet必須保持競爭
25、力的和響應,因為他們知道,有一個免費的解決方案在那里,如果他們不這樣。而當你使用開源軟件,你發(fā)送一條消息,你的首要問題是他們的特點和可靠性,如果出現(xiàn)錯誤,沒有一個大公司提起訴訟。</p><p> 原文出處《MySQL and JSP Web applications 》作者:James Turner</p><p> MySQL and JSP Web applications<
26、;/p><p> JSP developers encounter unique problems when building web applications that require intense database connectivity. MySQL and JSP Web Applications addresses the challenges of building data-driven appl
27、ications based on the JavaServer Pages development model. MySQL and JSP Web Applications begins with an overview of the core technologies required for JSP database development--JavaServer Pages, JDBC, and the database sc
28、hema. The book then outlines and presents an Internet commerce application that </p><p> So What Is JSP All About? </p><p> If you meet the requirements mentioned, you should already have a pr
29、etty good idea what the answer to this question is. JSP is all about doing highly object-oriented Web sites that can leverage all the best practices of modern software engineering. These practices include things such as
30、SQL databases and UML-based design. This isn't to say that JSP is a cure-all and that using it will automatically make your Web site a paragon of engineering art. It's just as possible to design bad Web sites in
31、</p><p> JSP grew out of Java servlets. Servlets allow the developer to handle the incoming Web requests using a Java program that has access to all the normal information that a Common Gateway Interface (C
32、GI) program would. In addition, the servlet has access to session-persistent objects. These are Java objects that are associated with a specific user session and can be used to store state between requests. Servlet progr
33、amming was a major step forward in allowing developers to write well-structured mod</p><p> Out.println("<HTML>\n<HEAD>\n<TITLE>Thank you for </p><p> Registering</TI
34、TLE></HEAD>\n"); </p><p> Out.println("<IMG SRC=\"thanks.jpg\" WIDTH=200 HEIGHT=100 ALIGN=\"LEFT\”>"); </p><p> This kind of embedding gets very ol
35、d very fast when you have to code a lot of pages. In addition, having to escape all of the quotation marks can lead to a lot of confusing and hard-to-find errors if you leave out a backslash. Eventually, a still-better i
36、dea emerged. Suppose that you could combine the best of static HTML pages and with the interactive capabilities of servlets. The result was JavaServer Pages (on the Microsoft side, the result was Active Server Pages). As
37、 Figure I.1 shows, JSP is</p><p> 1. A request comes in from a browser using the normal HTTP request format. </p><p> 2. The Web server hands off the request to JSP. JSP looks at the filename
38、and finds the appropriate JSP file. </p><p> 3. The .jsp file is converted into a .java file, containing Java code that will create a class whose name is derived from the .jsp filename. </p><p>
39、; 4. JSP then compiles the .java file using javac to produce a .class file. Note that the two previous steps are skipped if a .class file already exists and is newer than the .jsp file. </p><p> 5. An inst
40、ance of the newly created class is instantiated and sent the _jspService message. </p><p> 6. The new instance looks to see if there is already an instance of the stuff.User object called user existing in t
41、he session object space for the currently connected user. If not, one is instantiated.</p><p> 7. As part of servicing stuff.jsp, the user instance is called with the getUserName() method. </p><p
42、> 8. If the JSP processing requires access to information in a database, it uses JDBC to make the connection and handle the SQL requests.</p><p> As you can see, a tremendous amount of power is availabl
43、e in the JSP world. Developers are free to write Web pages that look mostly like HTML, except where callouts to Java are required. But, at the same time, they are free to develop fully fleshed-out object-oriented applica
44、tions using all the features that Java can bring to bear. They also get all the benefits of servlets, including session persistence.</p><p> Why Do We Need Databases?</p><p> Well, one reason
45、is so that Larry Ellison of Oracle can afford to keep himself on Prozac when he thinks about Bill Gates. A more serious answer is the same reason that drove man to first press a stick against a piece of wet mud: because
46、it's good to write things down. Web servers are marvelous creatures, but they're a bit like idiot savants. Ask them to serve a Web page or run a piece of Java, and they perform like a champ. But start asking them
47、 to remember what they did five minutes ago, and th</p><p> The first and most important reason that you use databases is that there's a lot in an e-commerce transaction that you need to remember and tr
48、ack: </p><p> ?A user's name, address, credit card, and other information previously entered on a registration page </p><p> ?hat the user might have put into a shopping cart and left from
49、 a previous transaction </p><p> ?What items are in stock, along with their price, description, and so on </p><p> ?Orders that need to be fulfilled, orders that have been shipped, and items t
50、hat have been backordered .</p><p> Now, you could store all this information in a flat file on the server's hard disk, but there are other important properties that you want to have for this data: <
51、/p><p> ?You want to be able to back out a transaction if part of it fails. </p><p> ?You want to be able to locate the data somewhere more secure than the Web server, which could be in a DMZ or
52、outside the firewall altogether. </p><p> ?You want to be able to access data such as user data or products quickly, even if there are thousands or millions of them.</p><p> When you add these
53、 items to the shopping list, only a relational database will really do the job effectively.</p><p><b> MySQL </b></p><p> Many sites don't need the battleship strength (and pri
54、ce tag) of Oracle. MySQL is an open-source SQL database available for anyone to use, with many (although not all) of the features of its big brothers, such as Oracle. </p><p> MySQL is available for just ab
55、out any computer that has decent power—it is fairly lightweight on the processor and easy to install (10 minutes, as opposed to multiple hours for Oracle). </p><p> So, perhaps you are wondering, what's
56、 the catch? What are you not getting in MySQL that makes people turn to Oracle? Well, MySQL is a neat little package, but it is missing some things that would be nice to have in a perfect world. </p><p> A
57、major feature that MySQL does not offer is database consistency checking. You can use foreign key tags in your schema, but MySQL cheerfully ignores them. A lot of DB As I know would consider this a very bad thing.</p&
58、gt;<p> A foreign key constraint prevents you from creating inconsistent data. For example, let's suppose that you had a scheme that looked like this: </p><p> CREATE TABLE USER ( </p>&l
59、t;p> USERID INTEGER, </p><p> FIRST_NAME VARCHAR(80), </p><p> LAST_NAME VARCHAR(80)); </p><p> CREATE TABLE PURCHASE ( </p><p> USERID FOREIGN KEY USE
60、R(USERID), </p><p> ITEM INTEGER, </p><p> QUANTITY INTEGER); </p><p> In a database such as Oracle's, if you created an entry in the PURCHASE table with a user ID of 3, ther
61、e would have to already be a user ID of 3 in the USER table or an error would occur. Similarly, you couldn't delete user 3 from USER if it was referenced in PURCHASE.The MySQL folks make a pretty impassioned argument
62、 in their documentation that depending on foreign keys for data integrity is a bad idea anyway, but convincing your DBA of this philosophy is likely to degrade into a religious deba</p><p> In addition, som
63、e other features are missing, such as subselects and select into. But probably the other major piece that you will miss is the rollback/commit functionality. MySQL does implement rollback and commit for certain types of
64、tables, but not all of them. Again, the MySQL folks offer their own spin on why this is okay, but being able to roll back transactions is (in my opinion) important enough to make sure that you have it available. </p&g
65、t;<p> Rollback allows you to set a savepoint on the database before starting to do a series of transactions with it, and be able to either roll back to the original state or commit the changes at the end. For ex
66、ample, when recording a purchase, you need to record a debit against the user's account and enter a record into the shipping table so that you'll know later to ship the item. Let's say that the second part fa
67、ils. You wouldn't want to charge the user but not ship the item. Thus, you'd want to ro</p><p> So, MySQL isn't a full-blown production database—at least, not yet. It's still good enough for
68、 probably 90% of the e-commerce sites in the world, however. And version 4.0, which is in alpha as of this writing, addresses a number of these concerns, including row-level locking and transaction control.</p>&l
69、t;p> Putting Tomcat and MySQL Together</p><p> Combining Tomcat and MySQL provides a powerful, reliable, and free platform that you can use to learn, develop, and deploy JSP applications. And, best of a
70、ll, the code that you develop using this platform will run nicely using iPlanet and Oracle or WebSphere and SQL Server.</p><p> As a learning tool the two together are almost "reference implementations
71、" of their respective protocols (JSP and SQL). As a result, you won't pick up any nasty vendor-proprietary bad habits while you're getting up to speed. </p><p> In addition, you can enjoy the k
72、nowledge that you are supporting the open-source software movement. Open-source software is code that is made freely available under one of several public licenses, frequently the GNU General Public License (GPL).</p&
73、gt;<p> Why is it good to support this movement? There are two sides to this answer: one technical and one political. Technically, it's a good thing because open-source software tends to encourage the develop
74、ment of open standards such as JSP and JDBC, allowing you to choose your tools from among a larger group rather than being locked into one vendor's proprietary solution. It's a positive thing politically because
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 畢業(yè)論文外文翻譯-mysql和jsp的web應用程序
- 基于asp的web應用程序開發(fā)外文翻譯
- 外文翻譯---web 應用程序的基本安全做法
- 外文文獻翻譯---web 應用程序的基本安全做法
- 外文翻譯-基于s2sh 的web應用程序框架的設計和實現(xiàn)
- 外文翻譯---應用程序基礎(chǔ)android developers
- jsp 外文翻譯--jsp及其web技術(shù)
- 計算機畢業(yè)設計外文翻譯--面向 java web 應用程序的 openid
- Web應用程序安全框架研究和實現(xiàn).pdf
- web應用程序設計(aspnet)
- web應用程序完全測試指南
- web應用程序設計專業(yè)
- 外文翻譯--jsp及其web技術(shù)
- 外文翻譯--jsp及其web技術(shù)
- [雙語翻譯]計算機類外文翻譯:ajax和php:構(gòu)建響應式web應用程序-第1章:ajax和web應用程序的未來(節(jié)選國外作者9138中文字中英文對照)
- 外文翻譯--高速磨削與cbn砂輪-應用程序和未來的技術(shù)
- 開發(fā)xml應用程序-畢業(yè)論文外文翻譯
- Web應用程序測試技術(shù)的研究.pdf
- 基于UML和設計模式的Web應用程序開發(fā).pdf
- android手機外文翻譯---應用程序基礎(chǔ)android developers
評論
0/150
提交評論