![北信科JavaWeb基于MVC的簡單數(shù)據(jù)庫管理系統(tǒng)_第1頁](http://file2.renrendoc.com/fileroot_temp3/2021-11/1/22901dc2-f09d-401c-8fac-55e18bbc7721/22901dc2-f09d-401c-8fac-55e18bbc77211.gif)
![北信科JavaWeb基于MVC的簡單數(shù)據(jù)庫管理系統(tǒng)_第2頁](http://file2.renrendoc.com/fileroot_temp3/2021-11/1/22901dc2-f09d-401c-8fac-55e18bbc7721/22901dc2-f09d-401c-8fac-55e18bbc77212.gif)
![北信科JavaWeb基于MVC的簡單數(shù)據(jù)庫管理系統(tǒng)_第3頁](http://file2.renrendoc.com/fileroot_temp3/2021-11/1/22901dc2-f09d-401c-8fac-55e18bbc7721/22901dc2-f09d-401c-8fac-55e18bbc77213.gif)
![北信科JavaWeb基于MVC的簡單數(shù)據(jù)庫管理系統(tǒng)_第4頁](http://file2.renrendoc.com/fileroot_temp3/2021-11/1/22901dc2-f09d-401c-8fac-55e18bbc7721/22901dc2-f09d-401c-8fac-55e18bbc77214.gif)
![北信科JavaWeb基于MVC的簡單數(shù)據(jù)庫管理系統(tǒng)_第5頁](http://file2.renrendoc.com/fileroot_temp3/2021-11/1/22901dc2-f09d-401c-8fac-55e18bbc7721/22901dc2-f09d-401c-8fac-55e18bbc77215.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、實 驗 報 告課程名稱: web程序設計 實驗題目: 實驗四 基于mvc的簡單數(shù)據(jù)庫管理系統(tǒng) 學 院: 計算機學院 專 業(yè): 網(wǎng)絡工程 指導教師: 施 運 梅 日 期: 2013年 6 月 19日 實驗四 基于mvc的簡單數(shù)據(jù)庫管理系統(tǒng)1、 實驗目的1、理解mvc設計思想。2、掌握基于mvc的編程技術(shù),掌握視圖層、模型層和控制層的設計方法。2、 實驗內(nèi)容及要求用mvc思想,編寫根據(jù)姓名查找學生記錄的應用。三、實驗步驟(1)創(chuàng)建數(shù)據(jù)庫用mysql創(chuàng)建一個名為student的數(shù)據(jù)庫、設置xuehao幾項并填入數(shù)據(jù) (2)設計模型層和視圖層模型層兩個類:studentbean.java:存放學生信息
2、(實體類)。studentdao.java:查詢數(shù)據(jù)庫。視圖層三個文件: queryform.jsp:為用戶提供輸入查詢條件的表單。 queryresult.jsp:如果查詢到記錄,則顯示響應的結(jié)果。noresult.jsp:如果沒有查詢到記錄,顯示提示信息。(3) queryform.jsp頁面 queryresult.jsp頁面noresult.jsp頁面 studentbean.java代碼public class studentbean private string num;private string name;private string sex;private string bi
3、rth;private string add;public string getxuehao() return num;public void setxuehao(string xuehao) this.num = num;public string getname() return name;public void setname(string name) = name;public string getsex() return sex;public void setsex(string sex) this.sex = sex;public string getbirth
4、() return birth;public void setbirth(string birth) this.birth = birth;public string getadd() return add;public void setadd(string add) this.add = add; studentdao.java代碼package student;import java.sql.connection;import java.sql.drivermanager;import java.sql.resultset;import java.sql.sqlexception;impo
5、rt java.util.arraylist;import student.studentbean;public class studentdao /*此dao用于連接數(shù)據(jù)庫*/先定義一個connection,方便在以后的各個方法當中進行調(diào)用private connection conn = null;/采用構(gòu)造函數(shù)進行數(shù)據(jù)庫連接的初始化public studentdao() try class.forname("com.mysql.jdbc.driver");/加載驅(qū)動conn = drivermanager.getconnection("jdbc:mysql:
6、/localhost:3306/test","root","000120"); catch (classnotfoundexception e) e.printstacktrace(); catch (sqlexception e) e.printstacktrace();public arraylist querylike(string sname) arraylist al = new arraylist();/先實例化一個容器string sql = "select * from student where name ='
7、;" + sname + "'"try resultset rs = conn.createstatement().executequery(sql);while(rs.next() studentbean st = new studentbean();/實例化一個實體類/將結(jié)果集當前記錄當中的id設置給st對象當中,完成數(shù)據(jù)的封裝,以下類同st.setnum(rs.getstring("num");st.setname(rs.getstring("name");st.setsex(rs.getstring(&quo
8、t;sex");st.setbirth(rs.getstring("birth");st.setadd(rs.getstring("add");al.add(st);/將結(jié)果保存在list當中 catch (sqlexception e) e.printstacktrace();finally this.closeconn();/最后關(guān)閉連接return al;/將數(shù)據(jù)返回/關(guān)閉connpublic void closeconn() try if(conn !=null) conn.close();conn = null; catch (sql
9、exception e) e.printstacktrace();queryservlet.java代碼queryservlet.java功能:接收用戶的查詢請求,并根據(jù)用戶輸入的姓名調(diào)用studentdao類查詢數(shù)據(jù)庫。根據(jù)查詢結(jié)果轉(zhuǎn)至不同的頁面。package servlet;import java.io.ioexception;import java.io.printwriter;import java.util.arraylist;import javax.servlet.servletexception;import javax.servlet.http.httpservlet;im
10、port javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;import student.studentbean;import student.studentdao;public class queryservlet extends httpservlet /* * constructor of the object. */public queryservlet() super();/* * destruction of the servlet. <br> */pu
11、blic void destroy() super.destroy(); /* * the dopost method of the servlet. <br> * * this method is called when a form has its tag value method equals to post. * * param request the request send by the client to the server * param response the response send by the server to the client * throws
12、 servletexception if an error occurred * throws ioexception if an error occurred */public void dopost(httpservletrequest request, httpservletresponse response)throws servletexception, ioexception request.setcharacterencoding("gb2312");response.setcharacterencoding("gb2312");strin
13、g sname = request.getparameter("sname");/實例化dao,并調(diào)用dao的查詢方法,將sname做為參數(shù)傳入進去studentdao qd = new studentdao();arraylist al = qd.querylike(sname);/調(diào)用查詢方法request.setattribute("al", al);/將結(jié)果保存在request當中,方便jsp調(diào)用/頁面跳轉(zhuǎn)if(al.isempty()request.getrequestdispatcher("/noresult.jsp").forward(request, response);elserequest.getrequestdispatcher("/queryresult.jsp").forward(request, response);/* * initialization of the servlet. <br> *
溫馨提示
- 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. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 路邊廣告位轉(zhuǎn)讓合同
- 美國自費出國留學咨詢服務合同年
- 居間合同傭金承諾書
- 事故車買賣合同協(xié)議
- 連車帶人租賃合同
- 荒山承包合同范本
- 叉車租賃合同協(xié)議書范本大全
- 工地材料運輸合同
- 借款合同答辯狀范本范本
- 個人工作總結(jié)范文20篇
- 2024-2030年中國香菇行業(yè)銷售狀況及供需前景預測報告
- 2024年廣東省公務員錄用考試《行測》真題及解析
- 高中英語必背3500單詞表(完整版)
- 2024年版《輸變電工程標準工藝應用圖冊》
- 2024年高考數(shù)學試卷(北京)(空白卷)
- 2024從洞見到生意:阿里健康特色人群消費趨勢報告-阿里健康x一財商學院
- 人教版2024年新教材七年級上冊英語starter unit 1 -unit7重點短語句型清單
- 護理服務在產(chǎn)科中的應用課件
- 2024年小升初語文入學分班測試卷四(統(tǒng)編版)
- 流行文化對青少年價值觀的影響研究
- 中國保險行業(yè)協(xié)會官方-2023年度商業(yè)健康保險經(jīng)營數(shù)據(jù)分析報告-2024年3月
評論
0/150
提交評論