javaWeb書店管理系統(tǒng)系統(tǒng)
《javaWeb書店管理系統(tǒng)系統(tǒng)》由會員分享,可在線閱讀,更多相關(guān)《javaWeb書店管理系統(tǒng)系統(tǒng)(57頁珍藏版)》請在裝配圖網(wǎng)上搜索。
1、、實驗?zāi)康? 1) 理解并掌握編碼與測試相關(guān)理論與方法; 2) 進(jìn)一步熟悉利用編程語言實現(xiàn)系統(tǒng); 3) 要求學(xué)生理解測試在軟件開發(fā)中的重要地位; 4) 學(xué)生了解測試用例與測試報告的相關(guān)書寫規(guī)范 、實驗內(nèi)容與要求 1) 根據(jù)系統(tǒng)的特點,選取javaWeb MVC開發(fā)模型實現(xiàn)該系統(tǒng); 2) 系統(tǒng)的編碼結(jié)構(gòu): 邊界類:1個html (項目首頁),13個jsp (中間跳轉(zhuǎn)的頁面),一個css (界面美化功能),一個javascript (控制輸入合法性)。 控制類:一個servlet類(連接邊界類和實體類) 實體類:一個datebase類(連接數(shù)據(jù)庫),一個book info 類(書
2、本的 增刪檢查操作) 服務(wù)器采用tomcat 。 如下圖展示: ..C5S 2015/1/1 20:27 I ? .■戶 2015/1/1 20:27 WEB-IWF 2015/1/1 20:23 ,_ add.bcekj&p 201S/1/1 21:21 2 KE 0 buyj年 2015/1/1 21:21 2
3、59 1 KB indesnhtrnl 2015/1/120:34 2 KB msnager.j^p 2015/1/^ 14:;S 2
4、5/1/2 15:55 2 KB s_mjsp 2015/1/1 20:32 1 KB 3) 對系統(tǒng)進(jìn)行測試分析,并對系統(tǒng)功能實施測試,編寫測試用例,系統(tǒng)已 經(jīng)實現(xiàn)可以讓手機電腦一起訪問并做操作; 4) 撰寫實驗報告,同時需要了解測試報告相應(yīng)的規(guī)范與寫法。 1.下面是一些界面的 展示(沒有全部展示): 登錄頁面 ■'幀客不莊輸入】 sina sohu CQpyigrt? 2014-201 ^NETWORK.席犠誨 鄧勻翔袁野 監(jiān)一甩一 ?茶膨s OIT霧 S a 3 3- 0 -O1 W1 E> ni £ 3
5、 a 1 O a 需 ITv Fl 8 m i/i O FM ■M 1 E S w 聲K S K S lll| HP- 4H 管 s K* 密 X ¥ §第 s .13 ■■ 耳 Ud X A. tx § 京 乂歸丼匪粧棒 K*s 訂單信息已審檢亮
6、卑 2012011] 90 血日制 32 U 2 KISi 正在打印訂單『請稍候■… 查詢頁面 圖書宿息査詢 *笛輸入則需芫整) 水目認(rèn)關(guān)濯寧即可) 咒輸入矣鍵宇即可) 查詢結(jié)果 躺號 書色 出匸牡 3 2012011307 卩唔it 學(xué)阿 51華檸 2011^^16 65 貼 2nL2DL]2La 亦y梅b 5K5 畤4卒斗蔚;| 20K-1-]? 旳 1D 2ni2DL12[4 旳衛(wèi) 手冃 中05科斗'社嗣
7、t 3300-12-16 55 B 血 管理員頁面 編耳 書若 ttft 出am 出丹曰期 怕略 1 ■itrr^ry#iit W-1!-* 科 0 ttik HA 20329I11CK1 jiWIKE 3DH-34 ie M^. 初】MILW1 匚啊 tlR 亂蘿丸黃倆t 30II4-K IQ 1<0 HI保 20】7加說幹 imEU ?Ri 科燈出*吐 3011-14^ 0 Hl怩 2012曲1204 tmis > 昌
8、 gflj amnoii ?Z i#土丈利!KS牡 35 遜 3tl2kll3U 囚迴t ISE 番k攀如t 如WK 越 amoiim Jfl?12-16 0 ffit 201201西丹 4如扯Ft 20OD-2-19 tttt 添加圖書頁面 添加圖書信息不完整頁面 圖書佶總 nc narr?L 三、完整開發(fā)代碼(按照上面截圖部
9、署即可實現(xiàn)) Table.css: body{ backgro und: margi n: 15; } body,table,th,td,i nput,select,textarea{ fon t-family: T ahoma,Verda na,Arial,Helvetica,sa ns-serif; fon t-size: 12px; } table.default{ border: 1px solid #3366CC; border-collapse: collapse; width: 80%; } table.default td{ paddi ng:
10、2 5 2 5; height: 26px; text-alig n: cen ter; border: 1px solid #ffffff; backgrou nd-color: #fOfOfO; } table.default tr.title td{ fon t-weight: bold; text-alig n: cen ter; backgrou nd: #99CCFF; color: red; border: 1px solid #ffffff; white-space: no wrap; height: 26px; } table.default th.
11、item{ fon t-weight: bold; color: #333333; text-alig n: cen ter; vertical-alig n: top; paddi ng: 10px; fon t-size: 14px; } xyh.css: body {fon t-family: Arial, Helvetica, san s-serif; fon t-size:12px;color:#666666;backgrou nd:#fff; text-alig n:cen ter;} * {margi n:0;paddi ng:0;} a {color:#
12、1E7ACE;text-decorati on:non e; } a:hover {color:#000;text-decoratio n:un derl in e;} h3 {fon t-size:14px;fo nt-weight:bold;} pre,p {color:#1E7ACE;margi n:4px;} in put, select,textarea {paddi ng:1px; margi n:2p x;fon t-size:11p x;} .buttom{padd in g:1px 10px;fo nt-size:12px; border:1px #1E7ACE
13、 solid;backgro un d:#D0F0FF;} #formwrapper {width:450p x;m argi n:15px auto; paddi ng:20px;text-alig n:left;border:1px solid #A4CDF2;} fieldset {paddi ng:10px;marg in-top:5px; border:1px solid #A4CDF2;backgrou nd:#fff;} fieldset lege nd {color:#1E7ACE;fo nt-weight:bold; paddi ng:3px 20px 3px 20p
14、x;border:1px solid #A4CDF2; backgro un d:#fff;} fieldset label {float:left;width:120px; text-alig n:right;paddi ng:4px;marg in :1px;} fieldset div {clear:left;marg in-bottom:2px;} .in put { width:120px;} .en ter{ text-alig n:ce nter;} .clear {clear:both;} Common.js: fun ctio n isNum( nu m){
15、 for(i=0;i< num.len gth;i++) { c=nu m.charAt(i); if(c>'9'||c<'0'){ return false; } } return true; } function check(){ if(form1.id.value=="”) {alert (" no id!"); form1.id.focus(); return false;} if(form1. name.value=="") {alert(” no n ame!"); form1. name.focus(); return false;} if(form1.autho
16、r.value=="") { alert("no author!"); form1.author.focus(); return false; if(form1.press.value=="”) { alert(" no press!"); form1.press.focus(); return false; } if(form1.date.value==""){ alert("no date!") form1.date.focus(); return false; } if(!isNum(form1.price)){ alert("price is wron g!") f
17、orm1.price.focus(); return false; } if(!isNum(form1.acco un t)){ alert("acco unt is wring!") form1.acco un t.focus(); return false; } Bookinfo.java: package bea n; import java .Ian g.Stri ng; import java .Ian g.System; import java.sql.ResultSet; import java.sql.SQLExcepti on; import java.u
18、til.ArrayList; public class book info{ private String id; private String name; private String author; private String press; private String date; private int price; private int acco unt; public void setName(Stri ng n ame) { this. name = n ame; } public String getName() { return n ame; }
19、 public void setAuthor(Stri ng author) { this.author = author; public Stri ng getAuthor() { return author; } public void setDate(Stri ng date) { this.date = date; } public Stri ng getDate() { return date; public void setPress(Stri ng press) { this.press = press; public String getPress() { r
20、etur n press; } public void setld(Stri ng id) { this.id = id; } public Stri ng getId() { return id; public void setAcco un t(i nt aco unt) { this.acco unt = aco unt; public int getAcco un t() { retur n acco unt; } public void setPrice(int price) { this.price = price; public int getPrice()
21、{
retur n price;
}
public static ArrayList
22、etld(rs.getStri ng("id")); bi.setName(rs.getStri ng(" name")); bi.setAuthor(rs.getStri ng("author")); bi.setPress(rs.getStri ng("press")); bi.setDate(rs.getStri ng("date")); bi.setPrice(rs.get In t("price")); bi.setAcco un t(rs.get In t("acco un t")); list.add(bi); } rs.close(); } catch(SQ
23、LExceptio n e){
e.pri ntStackTrace();
}
jdbc.close();
return list;
}
//通過編號書名作者來搜索
n ame,Stri ng
public static ArrayList
24、 if (!n ame.equals("")){way=way+10;} if (!author.equals("")){way=way+100;} if (way==1||way==11||way==101){ sql="select * from book.bookshop where id='"+id+""'; } if (way==10){ sql="select * from book.bookshop where n ame like '%"+name+"%": } if (way==100){ sql="select * from bookshop where
25、 author like '%"+author+"%"‘; } and if (way==110){ sql="select * from bookshop where name like '%"+name+"%' author like '%"+author+"%'"; } dbbea n jdbc=new dbbea n(); ResultSet rs=jdbc.executeQuery(sql); try{ while(rs. next()){ book info bi=new book info(); bi.setDate(rs.getStri ng("date"
26、)); bi.setPress(rs.getStri ng("press")); bi.setAuthor(rs.getStri ng("author")); bi.setName(rs.getStri ng(" name")); bi.setld(rs.getStri ng("id")); bi.setPrice(rs.get In t("price")); bi.setAcco un t(rs.get In t("acco un t")); list.add(bi); } rs.close(); } catch(SQLExceptio n e){ System.ou
27、t.pri ntl n(” no fin d"); } jdbc.close(); return list; } public static book info getbookbyid(Stri ng id){ String sql="select * from book.bookshop where id='"+id+""'; dbbea n jdbc=new dbbea n(); ResultSet rs=jdbc.executeQuery(sql); book info bi = new book in fo(); try{ if(rs. next()){ bi.
28、setDate(rs.getStri ng("date")); bi.setPress(rs.getStri ng("press")); bi.setAuthor(rs.getStri ng("author")); bi.setName(rs.getStri ng(" name")); bi.setld(rs.getStri ng("id")); bi.setPrice(rs.get In t("price")); bi.setAcco un t(rs.get In t("acco un t")); } rs.close(); } catch(SQLExceptio n
29、e){ System.out.println("no find"); } jdbc.close(); return bi; } author,Stri ng set public static int updatebook(Stri ng id,Stri ng n ame,Stri ng press,String date,int price,int account){ int result=0; String sql="update book.bookshop n ame='"+name+"',author="'+author+"',press="'+press+"'
30、,date="'+date+"',price= "+price+",acco un t="+acco un t+" where id='"+id+""'; dbbea n jdbc=new dbbea n(); result=jdbc.executeUpdate(sql); return result; } public static int deletebook(String id){ int result=O; String sql="delete from book.bookshop where id='"+id+""'; dbbea n jdbc=new dbbea
31、n(); result=jdbc.executeUpdate(sql); return result; } public static int addbook(String id,String name,String author,String press,String date,i nt price,i nt acco un t){ into int result=0; String sql="i nsert book.bookshop(id ,n ame,author,press,date,price,acco unt) values(”'+id+"',”'+name+"
32、',”'+author+"',”'+press+"',”'+date+"',"+price+","+accou n t+")"; dbbea n jdbc=new dbbea n(); result=jdbc.executeUpdate(sql); return result; } } Dbbean.java: package bea n; import java .Ian g.*; import java.sql.*; public class dbbea n{ private String driverStr="com.mysql.jdbc.Driver"; S
33、tri ng private conn Str="jdbc:mysql://localhost:3306/book?characterE ncodi ng=utf-8"; private String name="root"; private Stri ng password="xyh201268"; private Connection conn=n ull; private Stateme nt stmt=n ull; public dbbea n(){ try{ Class.forName(driverStr); conn=DriverMa nager.getC on
34、n ecti on(conn Str, name,password); stmt=c onn .createStateme nt(); } catch(Excepti on ex){ System.out.pri ntln ("conn ect to database is worry!"); } } public int executeUpdate(Stri ng s){ int result=0; try{ result=stmt.executeUpdate(s); } catch(Excepti on ex){ System.out.pri ntl n("upd
35、ate wrong!"); } return result; } public ResultSet executeQuery(Stri ng s){ ResultSet rs=n ull; try{ rs=stmt.executeQuery(s); } catch(Excepti on ex){ System.out.pri ntl n("search wrong!"); } return rs; } public void close(){ try{stmt.close();c onn .close(); } catch(Excepti on ex){ S
36、ystem.out.println("can not close the database!"); } } } Servlet.java: package servlets; import javax.servlet.ServletExceptio n; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResp on se; import java.i o.I OExcepti o
37、n; import java.util.ArrayList; import java .Ian g.*; /** * Created by Admi nistrator on 14-5-31. */ public class Servlet exte nds HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResp onse resp on se) throws ServletExcepti on, I OExcepti on { doPost(request, resp on
38、 se); } protected void doPost(HttpServletRequest request, HttpServletResp onse resp on se) throws ServletExcepti on, I OExcepti on { request.setCharacterE ncodi ng("utf-8"); String action=request.getServletPath(); if(act ion. equals("/servlets/depe nd.do")){ String value=request.getParameter(
39、"password");
if(value.equals("123")){
ArrayList
40、etAttribute("list", list);
request.getRequestDispatcher("/reader.jsp").forward(request,resp on se);
}
}
else if (act ion. equals("/servlets/list_m.do")){
ArrayList
41、).forward(request,resp on se);
}
else if (act ion. equals("/servlets/list_r.do")){
ArrayList
42、do")){ String id =request.getParameter("id"); bea n. book info bi= bea n.book in fo.getbookbyid(id); request.setAttribute("bi",bi); request.getRequestDispatcher("/edit.jsp").forward(request,resp on se); } else if(act ion. equals("/servlets/update.do")){ String id=request.getParameter("id");
43、 String n ame=request.getParameter(" name"); String author=request.getParameter("author"); String press=request.getParameter("press"); String date=request.getParameter("date"); String s_price=request.getParameter("price"); String s_acco un t=request.getParameter("acco un t"); int price=ln tege
44、r.parse In t(s_price); int acco unt=ln teger.parse In t(s_acco un t); r= int bea n. book in fo.updatebook(id, name,author,press,date,price,acco un t); if (r==1){ request.getRequestDispatcher("/success_m.jsp").forward(request,resp on se); } else{request.getRequestDispatcher("/failure_m.jsp").
45、forward(request,resp on se); } } else if (actio n.equals("/servlets/delete.do")){ String id=request.getParameter("id"); int r= bea n. book in fo.deletebook(id); if (r==1){ request.getRequestDispatcher("/success_m.jsp").forward(request,resp on se); } else{request.getRequestDispatcher("/failu
46、re_m.jsp").forward(request,resp on se); } } else if (act ion. equals("/servlets/add.do")){ String id=request.getParameter("id"); String n ame=request.getParameter(" name"); String author=request.getParameter("author"); String press=request.getParameter("press"); String date=request.getParame
47、ter("date"); String s_price=request.getParameter("price"); String s_acco un t=request.getParameter("acco un t"); int price=ln teger.parse In t(s_price); int acco unt=ln teger.parse In t(s_acco un t); press, int r= bea n. book in fo.addbook(id, n ame, author, date,price,acco un t); if (r==1)
48、{ request.getRequestDispatcher("/success_m.jsp").forward(request,resp on se); } else{ request.getRequestDispatcher("/failure_m.jsp").forward(request,resp on se); } } else if (act ion. equals("/servlets/buy.do")){ String buy=request.getParameter("buy"); bea n. book info bi=bea n. book in fo.
49、getbookbyid(buy); request.setAttribute("bi",bi); request.getRequestDispatcher("/buy.jsp").forward(request,resp on se); } else if (act ion. equals("/servlets/search_r.do")){ String id=request.getParameter("id"); String n ame=request.getParameter(" name"); String author=request.getParameter("aut
50、hor");
String user=request.getParameter("user");
list=
ArrayList
51、als("ma nager")) { request.getRequestDispatcher("/sear_result_m.jsp").forward(request,resp on se); } } else if (act ion. equals("/servlets/check_buy.do")){ String id=request.getParameter("id"); String s_nu m_buy=request.getParameter(" nu m_buy"); int nu m_buy =ln teger.parse In t(s_ nu m_buy
52、); bea n. book info bi= bea n.book in fo.getbookbyid(id); if(bi.getAcco un t() >=nu m_buy){ request.setAttribute("bi",bi); request.setAttribute("s_ nu m_buy",s_ nu m_buy); request.getRequestDispatcher("/success_buy.jsp").forward(request,resp on se); }else{ request.getRequestDispatcher("/failur
53、e_r.jsp").forward(request,resp on se); } } else if (act ion. equals("/servlets/pri nt_order.do")){ String id=request.getParameter("id"); String s_nu m_buy=request.getParameter("s_ nu m_buy"); bea n. book info bi= bea n.book in fo.getbookbyid(id); int nu m_buy =ln teger.parse In t(s_ nu m_buy)
54、; bea n. book in fo.updatebook(id,bi.getName(),bi.getAuthor(),bi.getPress(),bi.getDate( ),bi.getPrice(),(bi.getAcco un t()-nu m_buy)); request.getRequestDispatcher("/pri nt_order.jsp").forward(request,resp on se); } } } Add_book.jsp: <%@ page conten tType="text/html;charset=UTF-8" Ian guage="
55、java" %>
56、do" method="post">
編 號 | *(不能為空) |
---|---|
書 名 | *( 不能為空) |
*( 不能為空) | |
出版日期 | *( 不能為空) |
價 格 | 58、td> |
庫 存 | |
59、"text/html;charset=UTF-8" Ian guage="java" import="bean.bookinfo" %>
60、ce nter>
edit.jsp: <%@ page con te ntType="text/html;charset=UTF-8" import="bean.book64、info" %>