




已閱讀5頁,還剩29頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
JavaWeb課程設(shè)計(jì)實(shí)驗(yàn)報(bào)告班級(jí):計(jì)算機(jī)09-2實(shí)驗(yàn)內(nèi)容:圖書館管理系統(tǒng)成員:趙伯濤 44號(hào)(組長)張寶紅 42號(hào)黃海清 22號(hào)實(shí)驗(yàn)時(shí)間:從 2011年12月3日至 2011年12月9日指導(dǎo)老師:李啟銳一、實(shí)驗(yàn)?zāi)康摹?、在實(shí)踐中鞏固本學(xué)習(xí)所學(xué)的JavaWeb技術(shù)。2、在實(shí)踐中初步使用設(shè)計(jì)模式(GoF),體驗(yàn)設(shè)計(jì)模式帶來的好處。3、配合數(shù)據(jù)庫的使用,實(shí)現(xiàn)一個(gè)功能完善的小型系統(tǒng)。二、實(shí)驗(yàn)內(nèi)容。開發(fā)一個(gè)圖書管理系統(tǒng),實(shí)現(xiàn)圖書館的各種管理操作。如圖書入庫、作廢,借書證提供、掛失處理,圖書的借出、歸還、續(xù)借、丟失以及超期處理。s三、業(yè)務(wù)邏輯。四、數(shù)據(jù)庫設(shè)計(jì)。根據(jù)業(yè)務(wù)邏輯設(shè)計(jì)出數(shù)據(jù)庫。表結(jié)構(gòu)及關(guān)系如下圖:數(shù)據(jù)庫導(dǎo)入文本保存在DataBaseSQL.txt文檔中,數(shù)據(jù)庫數(shù)據(jù)保存在Data.txt文檔中。五、框架結(jié)構(gòu)。采用了類似與MVC框架的框架結(jié)構(gòu),頁面端使用了ExtJS技術(shù)(包含AJAX),增加了業(yè)務(wù)層和,數(shù)據(jù)庫操作層??刂破鲗诱{(diào)用業(yè)務(wù)層,業(yè)務(wù)層調(diào)用數(shù)據(jù)庫操作層。將控制,業(yè)務(wù),數(shù)據(jù)庫操作分別分層。六、技術(shù)性代碼。(本實(shí)驗(yàn)的代碼在Library.zip中)1、tomcat數(shù)據(jù)庫連接池技術(shù)。在tomcat中的配置文件server.xml文件中配置項(xiàng)目Context標(biāo)簽,再加入Resource標(biāo)簽:以上代碼配置了數(shù)據(jù)庫驅(qū)動(dòng),數(shù)據(jù)庫地址,數(shù)據(jù)庫用戶名、密碼,默認(rèn)提供的連接數(shù),最大提供的連接數(shù),最長等待時(shí)間等參數(shù)。2、Java中從連接池獲取連接的類,使用了單例模式(來自GoF提出的設(shè)計(jì)模式):/ DataBaseConnectionPond.javapackage library.util;import java.sql.Connection;import javax.sql.DataSource;/作者:趙伯濤public class DataBaseConnectionPond private static DataBaseConnectionPond dbcp = null;private DataSource ds = null;private DataBaseConnectionPond() throws Exception javax.naming.Context ctx = new javax.naming.InitialContext();ds = (DataSource) ctx.lookup(java:/comp/env/jdbc/webdb);public Connection GetConnettion() throws Exception return ds.getConnection();public static Connection getConnection() throws Exception Connection conn = null;if (dbcp = null) Thread.sleep(long) (Math.random() * 200);synchronized (DataBaseConnectionPond.class) if (dbcp = null) dbcp = new DataBaseConnectionPond();try conn = dbcp.GetConnettion(); catch (Exception e) return conn;該類在整個(gè)項(xiàng)目部署的過程中只實(shí)例化了一個(gè)對(duì)象,故稱單例。可以通過該類的static函數(shù)getConnection()獲取連接。3、Dao(Data Access Object)的模板化實(shí)現(xiàn),使用了模板方法模式(來自GoF提出的設(shè)計(jì)模式):/SqlExecute.javapackage library.execute;import java.sql.Connection;import library.util.*;/作者:趙伯濤public abstract class SqlExecute public Connection conn;public Object result;public abstract void setExecute() throws Exception;public Object execute() try conn = DataBaseConnectionPond.getConnection();conn.setAutoCommit(false);setExecute();mit(); catch (Exception e) try conn.rollback(); catch (Exception ee) e.printStackTrace(); finally try conn.close(); catch (Exception e) return result;該類是一個(gè)抽象類,必須通過繼承該類來實(shí)現(xiàn)具體的功能,其中的execute()函數(shù)是一個(gè)模板方法,將try-catch-finaly、獲取connection及connection的事務(wù)處理提取出來,具體Dao的功能應(yīng)該寫在setExecute()函數(shù)中,在具體實(shí)現(xiàn)Dao的功能的時(shí)候可以不用重復(fù)這些代碼,方便程序員編碼,也方便程序員維護(hù)程序。下面舉例使用這個(gè)模板類:/ReaderChangePasswordDao.javapackage library.dao;import java.sql.PreparedStatement;import library.execute.SqlExecute;import library.model.ReaderModel;/作者:趙伯濤public class ReaderChangePasswordDao extends SqlExecute private ReaderModel rm;/ 傳入 readerID, password, password2(舊密碼)/ 返回 影響行數(shù)public ReaderChangePasswordDao(ReaderModel rm) this.rm = rm;Overridepublic void setExecute() throws Exception String sql = update Readers set password = ? where readerID = ? and password = ?;PreparedStatement ps = conn.prepareStatement(sql);ps.setString(1, rm.getPassword();ps.setInt(2, rm.getReaderID();ps.setString(3, rm.getPassword2();this.result = ps.executeUpdate();上面的類繼承了SqlExecute類,重寫了它的setExecute()函數(shù),通過構(gòu)造函數(shù)傳入操作時(shí)需要的參數(shù),在寫代碼的時(shí)候可以更加專注于數(shù)據(jù)庫的操作,因?yàn)槠渌僮饔赡0孱愖龊昧?。這對(duì)寫一個(gè)數(shù)據(jù)庫操作或許沒什么大不了的,但是一個(gè)項(xiàng)目里邊數(shù)據(jù)庫操作肯定是幾十個(gè),幾百個(gè),甚至幾千個(gè),使用模板類減少的編碼量是非常客觀的。下面舉例使用ReaderChangePasswordDao類:/來自UserCommonService.java的部分代碼/ 讀者修改密碼public boolean readerChangePassword(int readerID, String newPassword,String oldPassword) ReaderModel rm = new ReaderModel();rm.setReaderID(readerID);rm.setPassword(newPassword);rm.setPassword2(oldPassword);ReaderChangePasswordDao rcpd = new ReaderChangePasswordDao(rm);int count = (Integer) rcpd.execute();if (count 0) return true; else return false;注意:使用Dao的時(shí)候調(diào)用的應(yīng)該是它的execute()方法(在抽象類中)。4、時(shí)間顯示var cTime=new Date();/初始化日期var myYear=cTime.getFullYear();/年var myMonth=cTime.getMonth()+1;/月var myDate=cTime.getDate();/日/獲得時(shí)分秒var myHour=cTime.getHours();/時(shí)var myMinute=cTime.getMinutes();/分var mySecond=cTime.getSeconds();/秒if(myHour 10)/判斷如果時(shí)鐘小于10就顯示兩位,前一位用0代替myHour = 0 + myHour;if(myMinute 10)/判斷如果分鐘小于10就顯示兩位,前一位用0代替myMinute = 0 + myMinute;if(mySecond 10)/判斷如果分秒鐘小于10就顯示兩位,前一位用0代替mySecond = 0 + mySecond;var time=time= myYear+/+myMonth+/+myDate+ +myHour+:+myMinute+:+mySecond;/格式化時(shí)間var timer = setInterval(function() /定義一個(gè)時(shí)鐘,周期為1秒var cTime=new Date();var myYear=cTime.getFullYear();/支持火狐var myMonth=cTime.getMonth()+1;/外國都是以0開頭為一月var myDate=cTime.getDate();/獲得時(shí)分秒var myHour=cTime.getHours();var myMinute=cTime.getMinutes();var mySecond=cTime.getSeconds();if(myHour 10)myHour = 0 + myHour;if(myMinute 10)myMinute = 0 + myMinute;if(mySecond 10)mySecond = 0 + mySecond; var cmp = Ext.getCmp(timer); time= myYear+/+myMonth+/+myDate+ +myHour+:+myMinute+:+mySecond; cmp.setValue(time); , 1000);5、登錄控制/登錄界面Ext.onReady(function()Ext.QuickTips.init();var form = new Ext.Panel( /登錄驗(yàn)證的form autoTabs:true, activeTab:0, deferredRender:false, border:false, bodyStyle : background-color:RGB(193,223,232);padding:0px 0px 0px 0px;, items: xtype:box, width:385, height:80, autoEl: tag:img, src:icons/borrowbooks.jpg , xtype:panel, bodyStyle:background-color:RGB(193,223,232);, layout:hbox, items: xtype:panel, bodyStyle:background-color:RGB(193,223,232);, border:false, width:120, height:150, items: xtype:panel, layout:hbox, border:false, bodyStyle:background-color:RGB(193,223,232);padding: 10px 0px 0px 10px, items:xtype:box,width:30,height:30,autoEl:tag:img,src:icons/0.png,xtype:panel,border:false,bodyStyle:background-color:RGB(193,223,232);padding: 5px 0px 0px 0px,items:xtype:displayfield,value:查閱書目 , xtype:panel, layout:hbox, border:false, bodyStyle:background-color:RGB(193,223,232);padding: 10px 0px 0px 10px, items:xtype:box,width:30,height:30,autoEl:tag:img,src:icons/6.png,xtype:panel,border:false,bodyStyle:background-color:RGB(193,223,232);padding: 5px 0px 0px 0px,items:xtype:displayfield,value:找回密碼 , xtype:panel, border:false, width:320, height:150, bodyStyle:background-color:RGB(193,223,232);, items: xtype:panel, layout:form, border:false, items: xtype:form, layout:form, id:loginno, labelWidth:30, bodyStyle:background-color:RGB(193,223,232);padding: 15px 0px 0px 0px, border:false, defaults: width:200 , items: xtype:textfield, fieldLabel:編號(hào), allowBlank:false , xtype:form, layout:form, id:loginpassword, labelWidth:30, bodyStyle:background-color:RGB(193,223,232);padding: 10px 0px 0px 0px, border:false, defaults: width:200 , items: xtype:textfield, fieldLabel:密碼, inputType:password, allowBlank:false );function login() /登錄驗(yàn)證函數(shù)var formNo = Ext.getCmp(loginno); var formPassword = Ext.getCmp(loginpassword); var username = formNo.items.items0;var password = formPassword.items.items0;if(username.getValue().trim() != & password.getValue().trim() != )Ext.Ajax.request(url:servlet/LoginServlet,success: function(response)var result = Ext.decode(response.responseText);if(result.success)location.href = index.html;loginWindow.close();elseExt.Msg.alert(提示,result.msg,function()formPassword.getForm().reset(););,params: cmd:login,username:username.getValue().trim(),password:password.getValue().trim(),scope:this); else Ext.Msg.alert(提示,編號(hào)和密碼都不能為空!);var loginWindow = new Ext.Window(/登錄
溫馨提示
- 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. 人人文庫網(wǎng)僅提供信息存儲(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 完整版健美操教學(xué)教案
- 【橙汁濃縮汁加工生產(chǎn)工藝的設(shè)計(jì)計(jì)算案例4000字】
- 班主任德育工作心得體會(huì)
- XXX智能指揮中心建設(shè)方案機(jī)房
- 紹興國企考試題庫及答案
- 三月三考試題目及答案
- 北京通州流管員考試題及答案
- matlab中format-short的用法文檔
- 氨基化工藝考試題及答案
- bim考試題庫及答案2025年
- 2025年廣西中考語文試題卷(含答案)
- 江蘇省南通市2024-2025學(xué)年高二下學(xué)期6月期末質(zhì)量監(jiān)測(cè)政治試題(含答案)
- 2025年南京市中考數(shù)學(xué)真題試卷
- 2024年深圳市中考?xì)v史試卷真題(含答案解析)
- 四川省地質(zhì)災(zāi)害治理工程常用資料表格
- 管道工字鋼支護(hù)施工方案
- CA6140車床杠桿工藝設(shè)計(jì)說明書完全版
- T_CHES 17-2018 水井報(bào)廢與處理技術(shù)導(dǎo)則
- 酒店住宿賬單模板
- 餐飲服務(wù)員必備六大技能課程
- 開展打擊生豬私屠濫宰和市場“白板肉”整治專項(xiàng)行動(dòng)方案
評(píng)論
0/150
提交評(píng)論