资源描述
一、实验目的1) 理解并掌握编码与测试相关理论与方法;2) 进一步熟悉利用编程语言实现系统;3) 要求学生理解测试在软件开发中的重要地位;4) 学生了解测试用例与测试报告的相关书写规范。二、实验内容与要求1) 根据系统的特点,选取 javaWeb MVC 开发模型实现该系统;2) 系统的编码结构:边界类: 1 个 html (项目首页), 13 个 jsp (中间跳转的页面),一个css(界面美化功能),一个javascript (控制输入合法性)。控制类:一个 servlet 类(连接边界类和实体类)实体类:一个 datebase类(连接数据库),一个bookinfo类(书本的增删检查操作)服务器采用 tomcat 。如下图展示:3) 对系统进行测试分析,并对系统功能实施测试,编写测试用例,系统已经实现可以让手机电脑一起访问并做操作;4) 撰写实验报告,同时需要了解测试报告相应的规范与写法。1. 下面是一些界面的 展示(没有全部展示):登录页面顾客首页购买页面订单页面查询页面查询结果管理员页面添加图书页面添加图书信息不完整页面三、完整开发代码 (按照上面截图部署即可实现)Table.css:bodybackground: #ffffff;margin: 15;body,table,th,td,input,select,textareafont-family: Tahoma,Verdana,Arial,Helvetica,sans-serif;font-size: 12px;table.defaultborder: 1px solid #3366CC;border-collapse: collapse;width: 80%;table.default tdpadding: 2 5 2 5;height: 26px;text-align: center;border: 1px solid #ffffff;background-color: #f0f0f0;table.default tr.title tdfont-weight: bold;text-align: center;background: #99CCFF;color: red;border: 1px solid #ffffff;white-space: nowrap;height: 26px;table.default th.itemfont-weight: bold;color: #333333;text-align: center;vertical-align: top;padding: 10px;font-size: 14px;xyh.css:body font-family: Arial, Helvetica, sans-serif;font-size:12px;color:#666666;background:#fff;text-align:center;* margin:0;padding:0;a color:#1E7ACE;text-decoration:none; a:hover color:#000;text-decoration:underline;h3 font-size:14px;font-weight:bold;pre,p color:#1E7ACE;margin:4px;input, select,textarea padding:1px;margin:2px;font-size:11px;.buttompadding:1px 10px;font-size:12px;border:1px #1E7ACE solid;background:#D0F0FF;#formwrapper width:450px;margin:15px auto; padding:20px;text-align:left;border:1px solid #A4CDF2;fieldset padding:10px;margin-top:5px;border:1px solid #A4CDF2;background:#fff;fieldset legend color:#1E7ACE;font-weight:bold; padding:3px 20px 3px 20px;border:1px solid #A4CDF2; background:#fff;fieldset label float:left;width:120px;text-align:right;padding:4px;margin:1px;fieldset div clear:left;margin-bottom:2px;.input width:120px;.enter text-align:center;.clear clear:both;Common.js:function isNum(num)for(i=0;i9|c0)return false;return true;function check()alert (no id!);return false;alert(no name!);return false;alert(no author!);return false;alert(no press!);return false;alert(no date!)return false;if(!isNum(form1.price)alert(price is wrong!)return false;if(!isNum(form1.account)alert(account is wring!)return false;Bookinfo.java:package bean;public class bookinfoprivate String id;private String name;private String author;private String press;private String date;private int price;private int account;public void setName(String name) this.name = name;public String getName() return name;public void setAuthor(String author) this.author = author;public String getAuthor() return author;public void setDate(String date) this.date = date;public String getDate() return date;public void setPress(String press) this.press = press;public String getPress() return press;public void setId(String id) this.id = id;public String getId() return id;public void setAccount(int acount) this.account = acount;public int getAccount() return account;public void setPrice(int price) this.price = price;public int getPrice() return price;public static ArrayList getbooklist() ArrayList list=new ArrayList(); String sql=select * from book.bookshop; dbbean jdbc=new dbbean();ResultSet rs=jdbc.executeQuery(sql);trywhile(rs.next()bookinfo bi=new bookinfo();bi.setId(rs.getString(id);bi.setName(rs.getString(name);bi.setAuthor(rs.getString(author);bi.setPress(rs.getString(press);bi.setDate(rs.getString(date);bi.setPrice(rs.getInt(price);bi.setAccount(rs.getInt(account);list.add(bi);rs.close();catch(SQLException e)e.printStackTrace();jdbc.close();return list;/通过编号书名作者来搜索public static ArrayList getbookbyway(String id,String name,String author) ArrayList list=new ArrayList();String sql=null;int way=0;if (!id.equals()way=way+1;if (!name.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 name like %+name+%;if (way=100)sql=select * from bookshop where author like %+author+%;if (way=110)sql=select * from bookshop where name like %+name+% and author like %+author+%;dbbean jdbc=new dbbean();ResultSet rs=jdbc.executeQuery(sql);trywhile(rs.next()bookinfo bi=new bookinfo();bi.setDate(rs.getString(date);bi.setPress(rs.getString(press);bi.setAuthor(rs.getString(author);bi.setName(rs.getString(name);bi.setId(rs.getString(id);bi.setPrice(rs.getInt(price);bi.setAccount(rs.getInt(account);list.add(bi);rs.close();catch(SQLException e)jdbc.close();return list;public static bookinfo getbookbyid(String id)String sql=select * from book.bookshop where id=+id+; dbbean jdbc=new dbbean();ResultSet rs=jdbc.executeQuery(sql);bookinfo bi = new bookinfo();tryif(rs.next()bi.setDate(rs.getString(date);bi.setPress(rs.getString(press);bi.setAuthor(rs.getString(author);bi.setName(rs.getString(name);bi.setId(rs.getString(id);bi.setPrice(rs.getInt(price);bi.setAccount(rs.getInt(account);rs.close();catch(SQLException e)jdbc.close();return bi;public static int updatebook(String id,String name,String author,String press,String date,int price,int account)int result=0;String sql=update book.bookshop setname=+name+,author=+author+,press=+press+,date=+date+,price=+price+,account=+account+ where id=+id+;dbbean jdbc=new dbbean();result=jdbc.executeUpdate(sql);return result;public static int deletebook(String id)int result=0;String sql=delete from book.bookshop where id=+id+;dbbean jdbc=new dbbean();result=jdbc.executeUpdate(sql);return result;public static int addbook(String id,String name,String author,String press,String date,int price,int account)int result=0;String sql=insert into book.bookshop(id,name,author,press,date,price,account) values(+id+,+name+,+author+,+press+,+date+,+price+,+account+);dbbean jdbc=new dbbean();result=jdbc.executeUpdate(sql);return result;Dbbean.java:package bean;import java.lang.*;import java.sql.*;public class dbbeanprivate String name=root;private String password=xyh201268;private Connection conn=null;private Statement stmt=null;public dbbean()tryClass.forName(driverStr);conn=DriverManager.getConnection(connStr,name,password);stmt=conn.createStatement();catch(Exception ex)public int executeUpdate(String s)int result=0;tryresult=stmt.executeUpdate(s);catch(Exception ex)return result;public ResultSet executeQuery(String s)ResultSet rs=null;tryrs=stmt.executeQuery(s);catch(Exception ex)return rs;public void close()trystmt.close();conn.close();catch(Exception ex)Servlet.java:package servlets;import java.lang.*;/* Created by Administrator on 14-5-31.*/public class Servlet extends HttpServlet protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doPost(request, response);protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException request.setCharacterEncoding(utf-8);String action=request.getServletPath();if(action.equals(/servlets/depend.do)String value=request.getParameter(password);if(value.equals(123)request.setAttribute(list, list);request.getRequestDispatcher(/manager.jsp).forward(request,response);elserequest.setAttribute(list, list);request.getRequestDispatcher(/reader.jsp).forward(request,response);else if (action.equals(/servlets/list_m.do)request.setAttribute(list, list);request.getRequestDispatcher(/manager.jsp).forward(request,response);else if (action.equals(/servlets/list_r.do)request.setAttribute(list, list);request.getRequestDispatcher(/reader.jsp).forward(request,response);else if(action.equals(/servlets/edit.do)String id =request.getParameter(id);request.setAttribute(bi,bi);request.getRequestDispatcher(/edit.jsp).forward(request,response);else if(action.equals(/servlets/update.do)String id=request.getParameter(id);String name=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_account=request.getParameter(account); int price=Integer.parseInt(s_price);int account=Integer.parseInt(s_account);if (r=1)request.getRequestDispatcher(/success_m.jsp).forward(request,response);elserequest.getRequestDispatcher(/failure_m.jsp).forward(request,response);else if (action.equals(/servlets/delete.do)String id=request.getParameter(id);if (r=1)request.getRequestDispatcher(/success_m.jsp).forward(request,response);elserequest.getRequestDispatcher(/failure_m.jsp).forward(request,response);else if (action.equals(/servlets/add.do)String id=request.getParameter(id);String name=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_account=request.getParameter(account);int price=Integer.parseInt(s_price);int account=Integer.parseInt(s_account);if (r=1)request.getRequestDispatcher(/success_m.jsp).forward(request,response);elserequest.getRequestDispatcher(/failure_m.jsp).forward(request,response);else if (action.equals(/servlets/buy.do)String buy=request.getParameter(buy);request.setAttribute(bi,bi);request.getRequestDispatcher(/buy.jsp).forward(request,response);else if (action.equals(/servlets/search_r.do)String id=request.getParameter(id);String name=request.getParameter(name);String author=request.getParameter(author);String user=request.getParameter(user);request.setAttribute(list, list);if (user.equals(reader)request.getRequestDispatcher(/sear_result_r.jsp).forward(request,response);if (user.equals(manager)request.getRequestDispatcher(/sear_result_m.jsp).forward(request,response);else if (action.equals(/servlets/check_buy.do)String id=request.getParameter(id);String s_num_buy=request.getParameter(num_buy); int num_buy=Integer.parseInt(s_num_buy); if(bi.getAccount()=num_buy)request.setAttribute(bi,bi);request.setAttribute(s_num_buy,s_num_buy);request.getRequestDispatcher(/success_buy.jsp).forward(request,response); elserequest.getRequestDispatcher(/failure_r.jsp).forward(request,response);else if (action.equals(/servlets/print_order.do)String id=request.getParameter(id);String s_num_buy=request.getParameter(s_num_buy); int num_buy=Integer.parseInt(s_num_buy); request.getRequestDispatcher(/print_order.jsp).forward(request,response);Add_book.jsp: 图书信息 编号 *( 不能为空) 书名 *( 不能为空 ) 作者 *( 不能为空 ) 出版社 *( 不能为空 ) 出版日期 *(不能为空 ) 价格 *( 只能数字 ) 库存 *(只能数字 ) buy.jsp: 订单信息 编号 input type=text value= name=name 书名 input type=text value= name=name 作者 input type=text value= name=author 出版社 input type=text value= name=press 出版日期 input type=text value= name=date 价格 input type=text value= name=price 库存 input type=text value= name=account 购买数量 edit.jsp: 修改信息 编号 input type=text value= name=id 书名 input type=text value= name=name 作者 input type=text value= name=author 出版社 input type=text value= name=press 出版日期 input type=text value= name=date 价格 input type=text value= name=price 库存 input type=text value= name=account failure_m.jsp: 操作失败 点击返回 failure_r.jsp: 购买信息错误 点击返回 index.html:图书商店用户登录 顾客 /管理员登录 用户名 *( 顾客不用输入 ) 密码 *( 顾客不用输入 ) 记住我 您忘记密码 ? 友请 连接 sina Copyright 2014-2015NETWORK. 席燚海邓匀翔袁野 manager.jsp: 添加图书 a href=/bookshop/search_r.jsp?user= 点击查询 编号 书名 作者 出版社 出版日期 价格 库存 管理 %request.setCharacterEncoding(utf-8);ArrayList list=(ArrayList)request.getAttribute(list); for(bookinfo bi:list)String id=bi.getId();%= bi.getD
展开阅读全文