jsp图书管理系统.doc
目录一、任务书3二、实验目的4三、需求分析4四、系统流程图5五、详细设计61、数据库设计 62、核心代码93、程序实现使用流程10六、实验总结19七、参考文献19二、实验目的:1、培养运用JSP语句制作网页的能力;2、活用所学的JSP知识制作简单的循环网页;3、实现NetBeans到数据库的链接;三、需求分析:图书借阅管理系统在各个图书馆、学校都有着至关重要的作用。在制作图书借阅管理系统之前,首先要知道所要做的系统可以实现哪些功能,要清楚不同级别的用户具有什么样的功能,实现什么样的界面。当明确了这些,项目开发的思路就清晰了,然后再对校园图书馆的系统进行考察、分析,从中吸取经验,并结合本系统的要求以及实际情况,设计出一个合理的系统。本图书借阅管理系统旨在构建此类平台,实现不同模块的功能设计。用户注册后登录,进入图书借阅,对图书的查看及借阅,以完成相应需求。本系统功能模块大致分为:用户登录借阅和管理员对图书及用户的管理。本系统是用netbeans、sqlserver、dreamweaver等WEB开发技术或网络工具完成一个的基本的图书借阅管理系统。四、系统流程图:注册登录管理员普通用户用户管理图书管理图书借阅图书查询借阅查看浏览所有用户查询用户查询修改载入查询五、详细设计:1、数据库设计:经过对图书借阅管理系统的需求分析,设计出该系统所需的数据库,名称为“test”。在数据库中共包括四个数据表:表users表book表guanli表jieyue12、过程代码:1、 在在netbeans中新建一个名为sherry的web应用程序:2、 将数据库驱动加入netbeans下的文件夹中,加入驱动程序:com.microsoft.sqlserver.jdbc.SQLServerDriverjdbc:sqlserver:/localhost:1433;DatabaseName=test","sa","kira"3、核心代码:首页:<head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>登陆首页</title><style type="text/css"><!-.STYLE1 font-size: 24px.STYLE2 font-size: 36px-></style></head><body bgcolor="#AEEEEE"><p align="center"><span class="STYLE2">魔力书城 登陆首页</span></p><form action="denglu1.jsp" method="post"><table width="529" height="218" border="1" align="center"><tr><td width="129"><span class="STYLE1"> 用户名:</span></td><td width="384"><label><input name="id" type="text" class="STYLE1" /><span class="STYLE1"><a href="zhuce1.jsp">注册</a></span></label></td></tr><tr><td><span class="STYLE1"> 密码:</span></td><td><label> <input name="pass" type="password" class="STYLE1" /></label></td></tr><tr><td height="63" colspan="2"><div align="center"><label><select name="select" class="STYLE1"><option value="user" selected>普通用户</option><option value="guanli">管理员</option></select></label> <input name="Submit" type="submit" class="STYLE1" value="登录" /> </div></td></tr></table></form></body></html>(1) 登录:<%page import="java.sql.*" %><%String susername=request.getParameter("id"); String isusername=new String(susername.getBytes("gb2312");String spassword=request.getParameter("pass"); String ispassword=new String(spassword.getBytes("gb2312");String sselect=request.getParameter("select"); Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");Connection con=DriverManager.getConnection("jdbc:sqlserver:/localhost:1433;DatabaseName=test","sa","kira");Statement sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);ResultSet rs;if(sselect.equals("user")rs=sql.executeQuery("select * from users where userID='"+susername+"' and upass='"+spassword+"'");if(rs.next()response.sendRedirect("huanying.jsp");elseresponse.sendRedirect("cuowu1.jsp");elsers=sql.executeQuery("select * from guanli where guanliID='"+susername+"' and gpass='"+spassword+"'");if(rs.next()response.sendRedirect("huanying1.jsp");elseresponse.sendRedirect("cuowu1.jsp");con.close();%></body></html><%/获取登录时输入的用户名并储存起来session.setAttribute("id",susername);%>登陆错误:<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>登录错误</title><style type="text/css"><!-.STYLE1 font-size: 36px.STYLE2 font-size: 24px-></style></head>(2)注册:<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>注册</title><style type="text/css"><!-.STYLE1 font-size: 36px.STYLE2 font-size: 24px-></style></head><body bgcolor="#AEEEEE"><div align="center"> <p class="STYLE1">普通用户注册</p></div> <form action="zhuce2.jsp" method="post"><table width="568" height="237" border="1" align="center"> <tr> <td width="129" height="70"><span class="STYLE2">用户名:</span></td> <td width="384"><label> <input name="ming" type="text" class="STYLE2" /> <span class="STYLE2"><a href="index.jsp">退出</a></span></label></td> </tr> <tr> <td height="63"><span class="STYLE2">密码:</span></td> <td height="63"><input name="pass" type="password" class="STYLE2" /></td> </tr> <tr> <td height="63" colspan="2"><label></label> <div align="center"> <input name="Submit" type="submit" class="STYLE2" value="提交" /> <input name="Submit2" type="reset" class="STYLE2" value="重置" /></div></td> </tr></table> </form><p> </p></body><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>注册成功</title><style type="text/css"><!-.STYLE1 font-size: 36px.STYLE2 font-size: 24px-></style></head><body bgcolor="#AEEEEE"><%page import="java.sql.*" %><%String sming=request.getParameter("ming");String ming=new String(sming.getBytes("gb2312");String spassword=request.getParameter("pass");String password=new String(spassword.getBytes("gb2312"); Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");Connection con=DriverManager.getConnection("jdbc:sqlserver:/localhost:1433;DatabaseName=test","sa","kira");Statement sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);ResultSet rs=sql.executeQuery("select * from users where userID='"+ming+"'");if(rs.next()response.sendRedirect("cuowu2.jsp");elsesql.executeUpdate("insert into users(userID,upass) values('"+ming+"','"+password+"')"); out.print("<p align="+"center"+"><span class="+"STYLE1>"+ming+" 普通用户注册成功,请记好您的ID号!"+"</span></p>");con.close();%></body></html>(3)借阅:<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>魔力书城图书借阅</title><style type="text/css"><!-.STYLE1 font-size: 36px.STYLE2 font-size: 24px-></style></head><body bgcolor="#AEEEEE"><div align="center"><span class="STYLE1">图书借阅</span></div><p> </p><table width="350" height="274" border="1" align="center"> <tr> <td><div align="center" class="STYLE1"><a href="jieyue3.jsp">借阅查看</a></div></td> </tr> <tr> <td><div align="center" class="STYLE1"><a href="jieyue2.jsp">图书查询</a></div></td> </tr> <tr> <td><div align="center" class="STYLE1"><a href="jieyue4.jsp">图书借阅</a></div></td> </tr> <tr> <td><div align="center" class="STYLE1"><a href="index.jsp">退出</a></div></td> </tr></table></body></html>查询图书:<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>查看所有图书信息</title><style type="text/css"><!-.STYLE1 font-size: 36px.STYLE2 font-size: 24px-></style></head><body bgcolor="#AEEEEE"><p align="center"><span class="STYLE1">图书借阅</span></p><table width="973" height="58" border="1" align="center"> <tr> <td class="STYLE2"><div align="center"><a href="jieyue3.jsp">借阅查看</a></div></td> <td><div align="center" class="STYLE2"><a href="jieyue2.jsp">图书查询</a></div></td> <td><div align="center" class="STYLE2"><a href="jieyue4.jsp">图书借阅</a></div></td> <td><div align="center" class="STYLE2"><a href="index.jsp">退出</a></div></td> </tr></table><p> </p><%page import="java.sql.*" %><%Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");Connection con=DriverManager.getConnection("jdbc:sqlserver:/localhost:1433;DatabaseName=test","sa","kira");Statement sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);response.getContentType(); request.getCharacterEncoding(); response.setContentType("text/html;charset=gb2312"); request.setCharacterEncoding("gb2312"); ResultSet rs=sql.executeQuery("select * from book"); out.print("<p align="+"center"+"><span class="+"STYLE2"+">数据库中的书目如下: </span></p>"); out.print("<table border align="+"center"+">");out.print("<tr>");out.print("<th width=120>书号</td>");out.print("<th width=120>书名</td>");out.print("<th width=120>作者</td>"); out.print("<th width=120>出版社</td>"); out.print("<th width=120>库存量</td>"); out.print("<tr>");while(rs.next()String a,b,c,d,e;a=rs.getString(1);out.print("<td>"+a+"</td>");b=rs.getString(2);out.print("<td>"+b+"</td>");c=rs.getString(3);out.print("<td>"+c+"</td>");d=rs.getString(4);out.print("<td>"+d+"</td>");e=rs.getString(5);out.print("<td>"+e+"</td>");out.print("<tr>"); con.close();%></body></html><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>借阅图书查询</title><style type="text/css"><!-.STYLE1 font-size: 36px.STYLE2 font-size: 24px-></style></head><body bgcolor="#AEEEEE"><p align="center"><span class="STYLE1">图书借阅</span></p><table width="973" height="58" border="1" align="center"> <tr> <td class="STYLE2"><div align="center"><a href="jieyue3.jsp">借阅查看</a></div></td> <td><div align="center" class="STYLE2">图书查询</div></td> <td><div align="center" class="STYLE2"><a href="jieyue4.jsp">图书借阅</a></div></td> <td><div align="center" class="STYLE2"><a href="index.jsp">退出</a></div></td> </tr></table><p> </p><form action="jy1.jsp" method="post"><p align="center"> <input name="Submit2" type="submit" class="STYLE2" value="查看所有图书信息" /></p></form><form action="jy2.jsp" method="post"><table width="595" height="84" border="1" align="center"> <tr> <td><div align="center" class="STYLE2">书号: <input name="shuhao" type="text" class="STYLE2" /> <input name="Submit" type="submit" class="STYLE2" value="查询" /> </div></td> </tr></table></form></body></html><html> <head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>查询图书信息</title><style type="text/css"><!-.STYLE1 font-size: 36px.STYLE2 font-size: 24px-></style></head><body bgcolor="#AEEEEE"><p align="center"><span class="STYLE1">图书借阅</span></p><table width="973" height="58" border="1" align="center"> <tr> <td class="STYLE2"><div align="center"><a href="jieyue3.jsp">借阅查看</a></div></td> <td><div align="center" class="STYLE2"><a href="jieyue2.jsp">图书查询</a></div></td> <td><div align="center" class="STYLE2"><a href="jieyue4.jsp">图书借阅</a></div></td> <td><div align="center" class="STYLE2"><a href="index.jsp">退出</a></div></td> </tr></table><p> </p><%page import="java.sql.*" %><%String sbook=request.getParameter("shuhao"); String isbook=new String(sbook.getBytes("gb2312"); Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");Connection con=DriverManager.getConnection("jdbc:sqlserver:/localhost:1433;DatabaseName=test","sa","kira");Statement sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);response.getContentType(); request.getCharacterEncoding(); response.setContentType("text/html;charset=gb2312"); request.setCharacterEncoding("gb2312"); ResultSet rs; rs=sql.executeQuery("select * from book where bookno='"+isbook+"'"); if(rs.next()rs.previous(); out.print("<p align="+"center"+"><span class="+"STYLE2"+">查询成功: </span></p>"); out.print("<table border align="+"center"+">");out.print("<tr>");out.print("<th width=120>书号</td>");out.print("<th width=120>书名</td>");out.print("<th width=120>作者</td>"); out.print("<th width=120>出版社</td>"); out.print("<th width=120>库存量</td>"); out.print("<tr>");while(rs.next()String a,b,c,d,e;a=rs.getString(1);out.print("<td>"+a+"</td>");b=rs.getString(2);out.print("<td>"+b+"</td>");c=rs.getString(3);out.print("<td>"+c+"</td>");d=rs.getString(4);out.print("<td>"+d+"</td>");e=rs.getString(5);out.print("<td>"+e+"</td>");out.print("<tr>"); else out.print("无此书(图书编号:"+isbook+"')!"); rs=sql.executeQuery("select * from book "); out.print("<p align="+"center"+"><span class="+"STYLE2"+">数据库中的书目如下: </span></p>"); out.print("<table border align="+"center"+">");out.print("<tr>");out.print("<th width=120>书号</td>");out.print("<th width=120>书名</td>");out.print("<th width=120>作者</td>"); out.print("<th width=120>出版社</td>"); out.print("<th width=120>库存量</td>"); out.print("<tr>");while(rs.next()String a,b,c,d,e;a=rs.getString(1);out.print("<td>"+a+"</td>");b=rs.getString(2);out.print("<td>"+b+"</td>");c=rs.getString(3);out.print("<td>"+c+"</td>");d=rs.getString(4);out.print("<td>"+d+"</td>");e=rs.getString(5);out.print("<td>"+e+"</td>");out.print("<tr>"); con.close();%></body></html>查看:<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>用户借阅查看</title><style type="text/css"><!-.STYLE1 font-size: 36px.STYLE2 font-size: 24px-></style></head><body bgcolor="#AEEEEE"><p align="center"><span class="STYLE1">图书借阅</span></p><table width="973" height="58" border="1" align="center"> <tr> <td class="STYLE2"><div align="center">借阅查看</div></td> <td><div align="center" class="STYLE2"><a href="jieyue2.jsp">图书查询</a></div></td> <td><div align="center" class="STYLE2"><a href="jieyue4.jsp">图书借阅</a></div></td> <td><div align="center" class="STYLE2"><a href="index.jsp">退出</a></div></td> </tr></table><p align="center" class="STYLE2"><%=session.getAttribute("id")%>用户的借阅信息:</p><p> </p><form action="jy3.jsp" method="post"><p class="STYLE2">确认用户名: <input name="id" type="text" class="STYLE2" /> <input name="Submit" type="submit" class="STYLE2" value="确定" /></p></form></body></html><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>用户借阅查看</title><style type="text/css"><!-.STYLE1 font-size: 36px.STYLE2 font-size: 24px-></style></head><body bgcolor="#AEEEEE"><p align="center"><span class="STYLE1">图书借阅</span></p><table width="973" height="58" border="1" align="center"> <tr> <td class="STYLE2"><div align="center">借阅查看</div></td> <td><div align="center" class="STYLE2"><a href="jieyue2.jsp">