javaWeb书店管理系统系统_第1页
javaWeb书店管理系统系统_第2页
javaWeb书店管理系统系统_第3页
已阅读5页,还剩52页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、、实验目的1)理解并掌握编码与测试相关理论与方法;2)进一步熟悉利用编程语言实现系统;3)要求学生理解测试在软件开发中的重要地位;4)学生了解测试用例与测试报告的相关书写规范、实验内容与要求1)根据系统的特点,选取javaWeb MVC开发模型实现该系统;2)系统的编码结构:边界类:1个html (项目首页),13个jsp (中间跳转的页面),一个css (界面美化功能),一个javascript (控制输入合法性)。控制类:一个servlet类(连接边界类和实体类)实体类:一个datebase类(连接数据库),一个book info 类(书本的 增删检查操作)服务器采用tomcat 。如下图

2、展示:.C5S2015/1/1 20:27I ».戶2015/1/1 20:27WEB-IWF2015/1/1 20:23,_ add.bcekj&p201S/1/1 21:212KE0 buyj年2015/1/1 21:212<Bi gditjsp2015/1/1 21.212KBfailure_iTi.j5p2014/12/29 12:591KB.failure_r.jsp2014/12/2 12:591KBindesnhtrnl2015/1/120:342KBmsnager.jp2015/1/ 14:;S2<B圖 print_orderjsp2015/1/1

3、 20:351KBreader,jp2015/1/2 14192 KBsear_resultm.2015/1/ 16:3O2KB,_ ser resutrjsp2015/1/1 20:322KB,.search_r.j5p201S/1/2 14; 221KB,sutcessbuyjsp2015/1/2 15:552KBs_mjsp2015/1/1 20:321KB3)对系统进行测试分析,并对系统功能实施测试,编写测试用例,系统已经实现可以让手机电脑一起访问并做操作;4)撰写实验报告,同时需要了解测试报告相应的规范与写法。1.下面是一些界面的 展示(没有全部展示):登录页面'帧客不庄输入

4、】sina sohuCQpyigrt© 2014-201 NETWORK.席犠诲 邓匀翔袁野监一甩一»茶膨sOIT雾Sa33-0-O1W1E>ni£3a1 Oa需ITvFl8m i/iOFM M1ES w聲KSKSlll|HP-4H管sK*密X¥§第s.13耳UdXA.tx§ 京乂归丼匪粧棒K*s订单信息已审檢亮卑2012011 90血日制32U2KISi正在打印订单请稍候查询页面图书宿息査询*笛输入则需芫整)水目认关濯寧即可)咒输入矣键宇即可)查询结果躺号书色出匸牡32012011307卩唔it学阿51华柠20111665貼2

5、nL2DL2La亦y梅b5K5畤4卒斗蔚;|20K-1-®旳1D2ni2DL124旳卫手冃中05科斗'社嗣t3300-12-1655B血管理员页面编耳书若ttft出am出丹曰期怕略1itrrry#iitW-1!-*科0ttikHA20329I11CK1jiWIKE3DH-34ieM.初】MILW1匚啊tlR亂蘿丸黄倆t30II4-KIQ1<0HI保20】7加说幹imEU?Ri科灯出*吐3011-140Hl怩2012曲1204tmis>昌gfljamnoii«Zi#土丈利!KS牡35逊3tl2kll3U囚迴tISE番k攀如t如WK越amoiimJfl

6、87;12-160ffit201201西丹4如扯Ft20OD-2-19tttt添加图书页面添加图书信息不完整页面图书佶总nc narr?L三、完整开发代码(按照上面截图部署即可实现)Table.css:bodybackgro und:margi n: 15;body,table,th,td,i nput,select,textareafon t-family: T ahoma,Verda na,Arial,Helvetica,sa ns-serif;fon t-size: 12px;table.defaultborder: 1px solid #3366CC;border-collapse:

7、collapse;width: 80%;table.default tdpaddi ng: 2 5 2 5;height: 26px;text-alig n: cen ter;border: 1px solid #ffffff; backgrou nd-color: #fOfOfO;table.default tr.title tdfon t-weight: bold;text-alig n: cen ter;backgrou nd: #99CCFF;color: red;border: 1px solid #ffffff; white-space: no wrap;height: 26px;

8、table.default th.itemfon 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:#1E7ACE;text-de

9、corati 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;.buttompadd in g:1px 10px;fo nt-size:12px;border:1px #1E7ACE solid;backgro un d:#D0F0FF; #formwrap

10、per 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 20px;border:1px solid #A4CDF2;backgro un d:#fff;fieldse

11、t 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) for(i=0;i< num.len gth;i+) c=nu m.charAt(i); if(c>'9'|c<'0

12、9;) 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.author.value="") alert("no author!");form1.

13、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!") form1.price.focus(); ret

14、urn 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.util.ArrayList;public class book infop

15、rivate 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;public void setAuthor(Stri ng author) this.author = author;public Stri

16、 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() retur n press;public void setld(Stri ng id) this.id = id; public Stri ng getId() return id;public voi

17、d 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() retur n price;public static ArrayList<book info> getbooklist()ArrayList<book info> list=new ArrayList<book in fo>

18、;();String sql="select * from book.bookshop"dbbea n jdbc=new dbbea n();ResultSet rs=jdbc.executeQuery(sql);trywhile(rs. next()book info bi=new book info();bi.setld(rs.getStri ng("id");bi.setName(rs.getStri ng(" name");bi.setAuthor(rs.getStri ng("author");bi.se

19、tPress(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(SQLExceptio n e)e.pri ntStackTrace();jdbc.close();return list;/通过编号书名作者来搜索n ame,Stri ngpubli

20、c static ArrayList<bookinfo>getbookbyway(Stringid,Stringauthor)ArrayList<book info> list=new ArrayList<book in fo>();String sql=n ull;int way=0;if (!id.equals("")way=way+1;if (!n ame.equals("")way=way+10;if (!author.equals("")way=way+100;if (way=1|way=

21、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 author like '%"+author+"%";andif (way=110)

22、sql="select * from bookshop where name like '%"+name+"%' author like '%"+author+"%'"dbbea n jdbc=new dbbea n();ResultSet rs=jdbc.executeQuery(sql);trywhile(rs. next()book info bi=new book info();bi.setDate(rs.getStri ng("date");bi.setPress(rs.g

23、etStri 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)S

24、ystem.out.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();tryif(rs.

25、 next()bi.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(&quo

26、t;acco un t");rs.close();catch(SQLExceptio n e)System.out.println("no find");jdbc.close();return bi;author,Stri ngsetpublic static intupdatebook(Stri ngid,Stri ngn ame,Stri ngpress,String date,int price,int account)int result=0;Stringsql="updatebook.bookshopn ame='"+name

27、+"',author="'+author+"',press="'+press+"',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;publi

28、c static int deletebook(String id)int result=O;String sql="delete from book.bookshop where id='"+id+""'dbbea n jdbc=new dbbea n();result=jdbc.executeUpdate(sql);return result;public static int addbook(String id,String name,String author,String press,String date,i nt price

29、,i nt acco un t)intoint result=0;Stringsql="i nsertbook.bookshop(id ,n ame,author,press,date,price,acco unt)values(”'+id+"',”'+name+"',”'+author+"',”'+press+"',”'+date+"',"+price+","+accoun t+")"dbbea n jd

30、bc=new dbbea n();result=jdbc.executeUpdate(sql);return result;Dbbean.java:package bea n;import java .Ian g.*;import java.sql.*;public class dbbea nprivate String driverStr="com.mysql.jdbc.Driver"Stri ngprivateconn Str="jdbc:mysql:/localhost:3306/book?characterE ncodi ng=utf-8"pri

31、vate String name="root"private Stri ng password="xyh201268"private Connection conn=n ull;private Stateme nt stmt=n ull;public dbbea n()tryClass.forName(driverStr);conn=DriverMa nager.getC onn ecti on(conn Str, name,password);stmt=c onn .createStateme nt();catch(Excepti on ex)Syst

32、em.out.pri ntln ("conn ect to database is worry!");public int executeUpdate(Stri ng s)int result=0;tryresult=stmt.executeUpdate(s);catch(Excepti on ex)System.out.pri ntl n("update wrong!");return result;public ResultSet executeQuery(Stri ng s)ResultSet rs=n ull;tryrs=stmt.execute

33、Query(s);catch(Excepti on ex)System.out.pri ntl n("search wrong!");return rs;public void close()trystmt.close();c onn .close();catch(Excepti on ex)System.out.println("can not close the database!");Servlet.java:package servlets;import javax.servlet.ServletExceptio n;import javax.s

34、ervlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResp on se;import java.i o.I OExcepti on;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(

35、HttpServletRequestrequest, HttpServletResp onseresp on se) throws ServletExcepti on, I OExcepti on doPost(request, resp on se);protected void doPost(HttpServletRequestrequest, HttpServletResp onseresp on se) throws ServletExcepti on, I OExcepti on request.setCharacterE ncodi ng("utf-8");St

36、ring action=request.getServletPath();if(act ion. equals("/servlets/depe nd.do")String value=request.getParameter("password");if(value.equals("123")ArrayList<bean.bookinfo> list= bean.bookinfo.getbooklist(); request.setAttribute("list", list);request.getR

37、equestDispatcher("/ma nager.jsp").forward(request,resp on se);elseArrayList<bea n. book info> list= bea n.book in fo.getbooklist();request.setAttribute("list", list);request.getRequestDispatcher("/reader.jsp").forward(request,resp on se);else if (act ion. equals(&

38、quot;/servlets/list_m.do")ArrayList<bean.bookinfo> list= bean.bookinfo.getbooklist(); request.setAttribute("list", list);request.getRequestDispatcher("/ma nager.jsp").forward(request,resp on se);else if (act ion. equals("/servlets/list_r.do")ArrayList<bean

39、.bookinfo> list= bean.bookinfo.getbooklist(); request.setAttribute("list", list);request.getRequestDispatcher("/reader.jsp").forward(request,resp on se);else if(act ion. equals("/servlets/edit.do")String id =request.getParameter("id");bea n. book info bi= b

40、ea 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");String n ame=request.getParameter(" name

41、");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 te

42、ger.parse In t(s_price);int acco unt=ln teger.parse In t(s_acco un t);r=intbea 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);elserequest.getRequestDispatcher("/failure_m.jsp"

43、).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);elserequest.getRequestDispatcher(&

44、quot;/failure_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(&q

45、uot;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 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

46、.addbook(id,n ame,author,date,price,acco un t);if (r=1)request.getRequestDispatcher("/success_m.jsp").forward(request,resp on se);elserequest.getRequestDispatcher("/failure_m.jsp").forward(request,resp on se);else if (act ion. equals("/servlets/buy.do")String buy=reques

47、t.getParameter("buy");bea n. book info bi=bea n. book in fo.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(&qu

48、ot;id");String n ame=request.getParameter(" name");String author=request.getParameter("author");String user=request.getParameter("user");list=ArrayList<bea n. book info>bea n. book in fo.getbookbyway(id, name,author);request.setAttribute("list", lis

49、t);if (user.equals("reader")request.getRequestDispatcher("/sear_result_r.jsp").forward(request,resp on se);if (user.equals("ma nager")request.getRequestDispatcher("/sear_result_m.jsp").forward(request,resp on se);else if (act ion. equals("/servlets/check_

50、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);bea n. book info bi= bea n.book in fo.getbookbyid(id);if(bi.getAcco un t() >=nu m_buy)request.setAttribute("bi",bi);re

51、quest.setAttribute("s_ nu m_buy",s_ nu m_buy); request.getRequestDispatcher("/success_buy.jsp").forward(request,resp on se);elserequest.getRequestDispatcher("/failure_r.jsp").forward(request,resp on se);else if (act ion. equals("/servlets/pri nt_order.do")Stri

52、ng 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);bea n. book in fo.updatebook(id,bi.getName(),bi.getAuthor(),bi.getPress(),bi.getDate( ),bi.g

53、etPrice(),(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="java" %> <html><head><li nk rel="stylesheet" href=&

54、quot;/bookshop/css/table.css" type="text/css"><title></title></head><script Ian guage="JavaScript" src="/bookshop/js/com mon .js"></script> <body><ce nter>vformn ame="form1"on submit="retur ncheck()"a

55、ction="/bookshop/servlets/add.do" method="post"><table class="default" alig n="cen ter" border="1"><center><h2>图书信息 </h2></center><tr><thclass="item">编 号</th><td><i nputtype="

56、text"name="id">*(不能为空)</td></tr><tr><th class="item">书 名</th><td><i nputtype="text"name="name">*(不能为空)</td></tr><tr><thclass="item">作 者</th><td> <inputtype="

57、;text"name="author">*( 不能为空)</td></tr>name="press">*(不能为空)</td></tr><tr><thclass="item">出版日期 </th><td><inputtype="text"name="date">*( 不能为空)</td></tr><tr><thclass=&q

58、uot;item">价 格</th><td> <in puttype="text"name="price">*(只能数字)</td></tr><tr><thclass="item">库 存</th><td> <in puttype="text"name="account">*(只能数字)</td></tr><tr><td

59、 colspan="2" align="center"><input type="submit" value=" 加"><input type="reset" value="重置"></td></tr></table></form></ce nter></body></html>buy.jsp:<%page conten tType="text/h

60、tml;charset=UTF-8"Ian guage="java"import="bean.bookinfo" %> <html><head><li nk rel="stylesheet" href="/bookshop/css/table.css" type="text/css"> <title></title></head><body><% request.setCharacterE

61、ncodi ng("utf-8");book info bi=(book info) request.getAttribute("bi");%><ce nter><form action="/bookshop/servlets/check_buy.do" method="post"><in put type="hidde n" n ame="id" value=$bi.id><pxh2>订单信息</h2><

62、;table class="default"><tr><th class="item"> 编 号</th><td> <in putvalue="<%= bi.getld()%>" n ame="n ame"> </td></tr><tr><thclass="item">书名</th><td> <in putvalue="<%=

63、 bi.getName()%>" n ame="n ame"> </td></tr><tr><thclass="item">作者</th><td> <in putvalue="<%= bi.getAuthor()%>" name="author"> </td></tr><tr><th class="item"> 出版社 </t

64、h><td><i nputvalue="<%= bi.getPress()%>" n ame="press"> </td></tr><tr><th class="item"> 出版日期 </th><td><inputtype="text"type="text"type="text"type="text"type="text&qu

65、ot;value="<%= bi.getDate()%>" name="date"> </td></tr>value="<%= bi.getPrice()%>" n ame="price"> </td></tr><tr><th class="item"> 库 存</th><td> <in putvalue="<%= bi.getAcco un t()%>" n ame="acco un t"> </td></tr><tr><th class="item"> 购买数量 </th><td><inputn

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论