javaWeb书店管理系统.docx
《javaWeb书店管理系统.docx》由会员分享,可在线阅读,更多相关《javaWeb书店管理系统.docx(42页珍藏版)》请在冰点文库上搜索。
javaWeb书店管理系统
一、实验目的
1)理解并掌握编码与测试相关理论与方法;
2)进一步熟悉利用编程语言实现系统;
3)要求学生理解测试在软件开发中的重要地位;
4)学生了解测试用例与测试报告的相关书写规范。
二、实验内容与要求
1)根据系统的特点,选取javaWebMVC开发模型实现该系统;
2)系统的编码结构:
边界类:
1个html(项目首页),13个jsp(中间跳转的页面),一个css(界面美化功能),一个javascript(控制输入合法性)。
控制类:
一个servlet类(连接边界类和实体类)
实体类:
一个datebase类(连接数据库),一个bookinfo类(书本的增删检查操作)
服务器采用tomcat。
如下图展示:
3)对系统进行测试分析,并对系统功能实施测试,编写测试用例,系统已经实现可以让手机电脑一起访问并做操作;
4)撰写实验报告,同时需要了解测试报告相应的规范与写法。
1.下面是一些界面的展示(没有全部展示):
登录页面
顾客首页
购买页面
订单页面
查询页面
查询结果
管理员页面
添加图书页面
添加图书信息不完整页面
三、完整开发代码(按照上面截图部署即可实现)
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:
1pxsolid#3366CC;
border-collapse:
collapse;
width:
80%;
table.defaulttd{
padding:
2525;
height:
26px;
text-align:
center;
1pxsolid#ffffff;
background-color:
#f0f0f0;
table.defaulttr.titletd{
font-weight:
bold;
#99CCFF;
color:
red;
white-space:
nowrap;
table.defaultth.item{
#333333;
vertical-align:
top;
10px;
14px;
xyh.css:
body{font-family:
Arial,Helvetica,sans-serif;
12px;color:
#666666;background:
#fff;
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;
2px;font-size:
11px;}
.buttom{padding:
1px10px;font-size:
1px#1E7ACEsolid;background:
#D0F0FF;}
#formwrapper{width:
450px;margin:
15pxauto;
20px;text-align:
left;border:
1pxsolid#A4CDF2;}
fieldset{padding:
10px;margin-top:
5px;
1pxsolid#A4CDF2;background:
#fff;}
fieldsetlegend{color:
#1E7ACE;font-weight:
3px20px3px20px;border:
1pxsolid#A4CDF2;
fieldsetlabel{float:
left;width:
120px;
right;padding:
4px;margin:
1px;}
fieldsetdiv{clear:
left;margin-bottom:
2px;}
.input{width:
120px;}
.enter{text-align:
.clear{clear:
both;}
Common.js:
functionisNum(num){
for(i=0;i{c=num.charAt(i);if(c>'9'||c<'0'){returnfalse;}}returntrue;}functioncheck(){if(form1.id.value==""){alert("noid!");form1.id.focus();returnfalse;}if(form1.name.value==""){alert("noname!");form1.name.focus();returnfalse;}if(form1.author.value==""){alert("noauthor!");form1.author.focus();returnfalse;}if(form1.press.value==""){alert("nopress!");form1.press.focus();returnfalse;}if(form1.date.value==""){alert("nodate!")form1.date.focus();returnfalse;}if(!isNum(form1.price)){alert("priceiswrong!")form1.price.focus();returnfalse;}if(!isNum(form1.account)){alert("accountiswring!")form1.account.focus();returnfalse;}Bookinfo.java:packagebean;importjava.lang.String;importjava.lang.System;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.util.ArrayList;publicclassbookinfo{privateStringid;privateStringname;privateStringauthor;privateStringpress;privateStringdate;privateintprice;privateintaccount;publicvoidsetName(Stringname){this.name=name;}publicStringgetName(){returnname;}publicvoidsetAuthor(Stringauthor){this.author=author;}publicStringgetAuthor(){returnauthor;}publicvoidsetDate(Stringdate){this.date=date;}publicStringgetDate(){returndate;}publicvoidsetPress(Stringpress){this.press=press;}publicStringgetPress(){returnpress;}publicvoidsetId(Stringid){this.id=id;}publicStringgetId(){returnid;}publicvoidsetAccount(intacount){this.account=acount;}publicintgetAccount(){returnaccount;}publicvoidsetPrice(intprice){this.price=price;}publicintgetPrice(){returnprice;}publicstaticArrayListgetbooklist(){ArrayListlist=newArrayList();Stringsql="select*frombook.bookshop";dbbeanjdbc=newdbbean();ResultSetrs=jdbc.executeQuery(sql);try{while(rs.next()){bookinfobi=newbookinfo();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(SQLExceptione){e.printStackTrace();}jdbc.close();returnlist;}//通过编号书名作者来搜索publicstaticArrayListgetbookbyway(Stringid,Stringname,Stringauthor){ArrayListlist=newArrayList();Stringsql=null;intway=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*frombook.bookshopwhereid='"+id+"'";}if(way==10){sql="select*frombook.bookshopwherenamelike'%"+name+"%'";}if(way==100){sql="select*frombookshopwhereauthorlike'%"+author+"%'";}if(way==110){sql="select*frombookshopwherenamelike'%"+name+"%'andauthorlike'%"+author+"%'";}dbbeanjdbc=newdbbean();ResultSetrs=jdbc.executeQuery(sql);try{while(rs.next()){bookinfobi=newbookinfo();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(SQLExceptione){System.out.println("nofind");}jdbc.close();returnlist;}publicstaticbookinfogetbookbyid(Stringid){Stringsql="select*frombook.bookshopwhereid='"+id+"'";dbbeanjdbc=newdbbean();ResultSetrs=jdbc.executeQuery(sql);bookinfobi=newbookinfo();try{if(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(SQLExceptione){System.out.println("nofind");}jdbc.close();returnbi;}publicstaticintupdatebook(Stringid,Stringname,Stringauthor,Stringpress,Stringdate,intprice,intaccount){intresult=0;Stringsql="updatebook.bookshopsetname='"+name+"',author='"+author+"',press='"+press+"',date='"+date+"',price="+price+",account="+account+"whereid='"+id+"'";dbbeanjdbc=newdbbean();result=jdbc.executeUpdate(sql);returnresult;}publicstaticintdeletebook(Stringid){intresult=0;Stringsql="deletefrombook.bookshopwhereid='"+id+"'";dbbeanjdbc=newdbbean();result=jdbc.executeUpdate(sql);returnresult;}publicstaticintaddbook(Stringid,Stringname,Stringauthor,Stringpress,Stringdate,intprice,intaccount){intresult=0;Stringsql="insertintobook.bookshop(id,name,author,press,date,price,account)values('"+id+"','"+name+"','"+author+"','"+press+"','"+date+"',"+price+","+account+")";dbbeanjdbc=newdbbean();result=jdbc.executeUpdate(sql);returnresult;}}}Dbbean.java:packagebean;importjava.lang.*;importjava.sql.*;publicclassdbbean{privateStringdriverStr="com.mysql.jdbc.Driver";privateStringconnStr="jdbc:mysql://localhost:3306/book?characterEncoding=utf-8";privateStringname="root";privateStringpassword="xyh201268";privateConnectionconn=null;privateStatementstmt=null;publicdbbean(){try{Class.forName(driverStr);conn=DriverManager.getConnection(connStr,name,password);stmt=conn.createStatement();}catch(Exceptionex){System.out.println("connecttodatabaseisworry!");}}publicintexecuteUpdate(Strings){intresult=0;try{result=stmt.executeUpdate(s);}catch(Exceptionex){System.out.println("updatewrong!");}returnresult;}publicResultSetexecuteQuery(Strings){ResultSetrs=null;try{rs=stmt.executeQuery(s);}catch(Exceptionex){System.out.println("searchwrong!");}returnrs;}publicvoidclose(){try{stmt.close();conn.close();}catch(Exceptionex){System.out.println("cannotclosethedatabase!");}}}Servlet.java:packageservlets;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjava.io.IOException;importjava.util.ArrayList;importjava.lang.*;/***CreatedbyAdministratoron14-5-31.*/publicclassServletextendsHttpServlet{protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doPost(request,response);}protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{request.setCharacterEncoding("utf-8");Stringaction=request.getServletPath();if(action.equals("/servlets/depend.do")){Stringvalue=request.getParameter("password");if(value.equals("123")){ArrayListlist=bean.bookinfo.getbooklist();request.setAttribute("list",list);request.getRequestDispatcher("/manager.jsp").forward(request,response);}else{ArrayListlist=bean.bookinfo.getbooklist();request.setAttribute("list",list);request.getRequestDispatcher("/reader.jsp").fo
{
c=num.charAt(i);
if(c>'9'||c<'0'){
returnfalse;
returntrue;
functioncheck(){
if(form1.id.value=="")
{alert("noid!
");
form1.id.focus();
returnfalse;}
if(form1.name.value=="")
{alert("noname!
form1.name.focus();
if(form1.author.value=="")
alert("noauthor!
form1.author.focus();
if(form1.press.value=="")
alert("nopress!
form1.press.focus();
if(form1.date.value==""){
alert("nodate!
")
form1.date.focus();
if(!
isNum(form1.price)){
alert("priceiswrong!
form1.price.focus();
isNum(form1.account)){
alert("accountiswring!
form1.account.focus();
Bookinfo.java:
packagebean;
importjava.lang.String;
importjava.lang.System;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.util.ArrayList;
publicclassbookinfo{
privateStringid;
privateStringname;
privateStringauthor;
privateStringpress;
privateStringdate;
privateintprice;
privateintaccount;
publicvoidsetName(Stringname){
this.name=name;
publicStringgetName(){
returnname;
publicvoidsetAuthor(Stringauthor){
this.author=author;
publicStringgetAuthor(){
returnauthor;
publicvoidsetDate(Stringdate){
this.date=date;
publicStringgetDate(){
returndate;
publicvoidsetPress(Stringpress){
this.press=press;
publicStringgetPress(){
returnpress;
publicvoidsetId(Stringid){
this.id=id;
publicStringgetId(){
returnid;
publicvoidsetAccount(intacount){
this.account=acount;
publicintgetAccount(){
returnaccount;
publicvoidsetPrice(intprice){
this.price=price;
publicintgetPrice(){
returnprice;
publicstaticArrayListgetbooklist(){
ArrayListlist=newArrayList();
Stringsql="select*frombook.bookshop";
dbbeanjdbc=newdbbean();
ResultSetrs=jdbc.executeQuery(sql);
try{
while(rs.next()){
bookinfobi=newbookinfo();
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(SQLExceptione){
e.printStackTrace();
jdbc.close();
returnlist;
//通过编号书名作者来搜索
publicstaticArrayListgetbookbyway(Stringid,Stringname,Stringauthor){
Stringsql=null;
intway=0;
id.equals("")){way=way+1;}
name.equals("")){way=way+10;}
author.equals("")){way=way+100;}
if(way==1||way==11||way==101){
sql="select*frombook.bookshopwhereid='"+id+"'";
if(way==10){
sql="select*frombook.bookshopwherenamelike'%"+name+"%'";
if(way==100){
sql="select*frombookshopwhereauthorlike'%"+author+"%'";
if(way==110){
sql="select*frombookshopwherenamelike'%"+name+"%'andauthorlike'%"+author+"%'";
System.out.println("nofind");
publicstaticbookinfogetbookbyid(Stringid){
Stringsql="select*frombook.bookshopwhereid='"+id+"'";
if(rs.next()){
returnbi;
publicstaticintupdatebook(Stringid,Stringname,Stringauthor,Stringpress,Stringdate,intprice,intaccount){
intresult=0;
Stringsql="updatebook.bookshopsetname='"+name+"',author='"+author+"',press='"+press+"',date='"+date+"',price="+price+",account="+account+"whereid='"+id+"'";
result=jdbc.executeUpdate(sql);
returnresult;
publicstaticintdeletebook(Stringid){
Stringsql="deletefrombook.bookshopwhereid='"+id+"'";
publicstaticintaddbook(Stringid,Stringname,Stringauthor,Stringpress,Stringdate,intprice,intaccount){
Stringsql="insertintobook.bookshop(id,name,author,press,date,price,account)values('"+id+"','"+name+"','"+author+"','"+press+"','"+date+"',"+price+","+account+")";
Dbbean.java:
importjava.lang.*;
importjava.sql.*;
publicclassdbbean{
privateStringdriverStr="com.mysql.jdbc.Driver";
privateStringconnStr="jdbc:
mysql:
//localhost:
3306/book?
characterEncoding=utf-8";
privateStringname="root";
privateStringpassword="xyh201268";
privateConnectionconn=null;
privateStatementstmt=null;
publicdbbean(){
Class.forName(driverStr);
conn=DriverManager.getConnection(connStr,name,password);
stmt=conn.createStatement();
catch(Exceptionex){
System.out.println("connecttodatabaseisworry!
publicintexecuteUpdate(Strings){
result=stmt.executeUpdate(s);
System.out.println("updatewrong!
publicResultSetexecuteQuery(Strings){
ResultSetrs=null;
rs=stmt.executeQuery(s);
System.out.println("searchwrong!
returnrs;
publicvoidclose(){
try{stmt.close();conn.close();
System.out.println("cannotclosethedatabase!
Servlet.java:
packageservlets;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importjava.io.IOException;
/**
*CreatedbyAdministratoron14-5-31.
*/
publicclassServletextendsHttpServlet{
protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{
doPost(request,response);
protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{
request.setCharacterEncoding("utf-8");
Stringaction=request.getServletPath();
if(action.equals("/servlets/depend.do")){
Stringvalue=request.getParameter("password");
if(value.equals("123")){
ArrayListlist=bean.bookinfo.getbooklist();
request.setAttribute("list",list);
request.getRequestDispatcher("/manager.jsp").forward(request,response);
else
{ArrayListlist=bean.bookinfo.getbooklist();
request.getRequestDispatcher("/reader.jsp").fo
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2