javaWeb書店管理系統(tǒng)
《javaWeb書店管理系統(tǒng)》由會員分享,可在線閱讀,更多相關(guān)《javaWeb書店管理系統(tǒng)(21頁珍藏版)》請在裝配圖網(wǎng)上搜索。
1、 一、實驗?zāi)康? 1) 理解并掌握編碼與測試相關(guān)理論與方法; 2) 進一步熟悉利用編程語言實現(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
2、 類(連接邊界類和實體類) 實體類:一個 datebase 類(連接數(shù)據(jù)庫),一個 bookinfo 類(書本的增刪檢 查操作) 服務(wù)器采用 tomcat 。 如下圖展示: 3) 對系統(tǒng)進行測試分析,并對系統(tǒng)功能實施測試,編寫測試用例,系統(tǒng)已經(jīng)實現(xiàn)可以讓手機電腦一起訪問并做操作; 4) 撰寫實驗報告,同時需要了解測試報告相應(yīng)的規(guī)范與寫法。 1. 下面是一些界面的 展示(沒有全部展示):登錄頁面 顧客首頁 購買頁面 訂單頁面 查詢頁面 查詢結(jié)果 管理員頁
3、面 添加圖書頁面 添加圖書信息不完整頁面 三、完整開發(fā)代碼 (按照上面截圖部署即可實現(xiàn) ) Table.css: body{ background: #ffffff; margin: 15; } body,table,th,td,input,select,textarea{ font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; font-size: 12px; } table.default{ border: 1px soli
4、d #3366CC; border-collapse: collapse; width: 80%; } table.default td{ padding: 2 5 2 5; height: 26px; text-align: center; border: 1px solid #ffffff; background-color: #f0f0f0; } table.default tr.title td{ font-weight: bold; text-align: center; background: #9
5、9CCFF; color: red; border: 1px solid #ffffff; white-space: nowrap; height: 26px; } table.default th.item{ font-weight: bold; color: #333333; text-align: center; vertical-align: top; padding: 10px; font-size: 14px; } xyh.css: body {font-family: Arial
6、, 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;}
7、input, select,textarea {padding:1px; margin:2px;font-size:11px;} .buttom{padding: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
8、: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-bot
9、tom:2px;}
.input { width:120px;}
.enter{ text-align:center;}
.clear {clear:both;}
Common.js:
function isNum(num){
for(i=0;i
10、turn 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
11、.account)){ alert("account is wring!") return false; } Bookinfo.java: package bean; public class bookinfo{ private String id; private String name; private String author; private String press; private String date; private int price; private int account; publi
12、c 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; } p
13、ublic 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(
14、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
15、st
16、.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; } //通過編號 書名
17、 作者來搜索
public static ArrayList
18、 (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="selec
19、t * from bookshop where name like '%"+name+"%' and author like '%"+author+"%'"; } dbbean jdbc=new dbbean(); ResultSet rs=jdbc.executeQuery(sql); try{ while(rs.next()){ bookinfo bi=new bookinfo(); bi.setDate(rs.getString("date")); bi.setPress(rs.getString("press")); bi.setA
20、uthor(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 st
21、atic 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(); try{ if(rs.next()){ bi.setDate(rs.getString("date")); bi.setPress(rs.getString("pr
22、ess")); 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 sta
23、tic int updatebook(String id,String name,String author,String press,String date,int price,int account){ int result=0; String sql="update book.bookshop set name='"+name+"',author='"+author+"',press='"+press+"',date='"+date+"',price="+price+",acco unt="+account+" where id='"+id+"'"; dbb
24、ean 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
25、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
26、 jdbc=new dbbean(); result=jdbc.executeUpdate(sql); return result; } } } Dbbean.java: package bean; import java.lang.*; import java.sql.*; public class dbbean{ private String name="root"; private String password="xyh201268"; private Connection conn=null;
27、 private Statement stmt=null; public dbbean(){ try{ Class.forName(driverStr); conn=DriverManager.getConnection(connStr,name,password); stmt=conn.createStatement(); } catch(Exception ex){ } } public int executeUpdate(String s){ int result=0; try{ result=stmt.e
28、xecuteUpdate(s); } catch(Exception ex){ } return result; } public ResultSet executeQuery(String s){ ResultSet rs=null; try{ rs=stmt.executeQuery(s); } catch(Exception ex){ } return rs; } public void close(){ try{stmt.close();conn.close(); } catch
29、(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 ServletExcep
30、tion, 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.
31、do")){ String value=request.getParameter("password"); if(value.equals("123")){ request.setAttribute("list", list); request.getRequestDispatcher("/manager.jsp").forward(request,response); } else request.setAttribute("list", list); request.getRequestDispatcher("/reader.jsp").fo
32、rward(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); re
33、quest.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(
34、"/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");
35、 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); } else{request.getRequestDispatcher("/failure_m.jsp").forward(request
36、,response); } } else if (action.equals("/servlets/delete.do")){ String id=request.getParameter("id"); if (r==1){ request.getRequestDispatcher("/success_m.jsp").forward(request,response); } else{request.getRequestDispatcher("/failure_m.jsp").forward(request,response); }
37、 } 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=r
38、equest.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); } else{ request.getRequestDispa
39、tcher("/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("/serv
40、lets/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.getRequestDispat
41、cher("/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_b
42、uy=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); }else{ request.getRequestDi
43、spatcher("/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.
44、jsp").forward(request,response); } } } Add_book.jsp: <%@ page contentType="text/html;charset=UTF-8" language="java" %>
54、
操作失敗
59、f="javascript:history.back()">點擊返回
購買信息錯誤
點擊返回60、body> index.html:
圖書商店用戶登錄
64、>
友請 連接
sinaCopyright @ 2014-2015NETWORK. 席燚海 鄧勻翔 袁野
65、="manager"; %>
添加圖書
點擊查詢 | ||||||||
編號 | 書名
66、h> | 作者 | 出版社 | 出版日期 | 價格 | 庫存 | 管理 | |
---|---|---|---|---|---|---|---|---|
<%= bi.getId()%> | <%= bi.getName()%> | <%= bi.getAuthor()%> | <%= bi.getPress()%> | <%= bi.getD
展開閱讀全文
最新文檔
copyright@ 2023-2025 zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有 聯(lián)系電話:18123376007 備案號:蜀ICP備2024067431號-1 川公網(wǎng)安備51140202000466號 本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng),我們立即給予刪除!
|