1、项目需求:
图书馆管理系统,能进图书管理系统软件图书管理系统软件行图书馆管理系统能实测国民经济和企业的各种运行情况;利用过去的数据预测未来;从企业全局出发辅助企业进行管理决策;利用信息控制企业的行为;帮助企业实现其规划目标。
2.系统要求与功能设计
2.1 页面要求
(1)能够在Tomcat服务器中正确部署,并通过浏览器查看;
(2)网站页面整体风格统一;
(3)首页(登录页)要求实现不同用户登录后,进入的功能页不相同。
(4)读者功能页:有浏览图书信息、查询图书信息、借阅图书,浏览催还书目、归还图书五个功能模块。
(5)管理员功能页:有添加读者信息、添加新书信息、打印催还书目信息三个模块。
2.2功能要求:
(1)浏览图书信息:读者登录后以列表形式可以查看所有图书基本信息,包括唯一编号、书名、作者名、出版社名称信息、可借阅数量;
(2)查询图书信息:可以按照书名或作者名进行模糊检索,以列表形式查看符合条件的图书信息。
(3)借阅图书功能:读者选择查询图书相应信息,跳转到书目的详细信息界面,当可借阅数量大于零,点击借阅按钮,提示用户借阅成功,并显示归还日期(三个月),否则提示用户该书可借阅数量为0,无法借阅。
(4)浏览催还书目:读者查看个人超期的图书列表信息。
(5)归还图书功能:读者可以查看个人借阅的所有书目列表信息,选择其中一项,则跳转到书目的详细信息界面,点击归还按钮,提示用户还书成功,如果该书超期,以一天0.1元计算罚金,提示用户需要缴纳罚金。
(6)添加读者基本信息:管理员可以添加读者基本信息,读者基本信息包括学号(八位数字组成,例如20180052)、读者姓名、读者性别、所在学院组成;
(7)添加新书基本信息:管理员可以添加新书基本信息,新书基本信息包括唯一编号、书名、作者名、出版社名称,可借阅数量;
(8)打印催还书目功能:显示所有用户的超期图书信息;
(9)登陆功能:管理员、读者登陆后可以看到不同的功能页面,读者登陆后只能看到自己的相关信息,不同读者登陆后无法查看其他人的信息。(要求至少创建五个读者用户演示选课过程)
3数据库设计:
要求实现图书基本信息表、借阅基本信息表、催还基本信息表、读者基本信息表。
4、WEB发布:
要求可以实现在浏览器直接访问系统。
源代码
1 package test2; 2 3 import java.sql.*; 4 import java.text.SimpleDateFormat; 5 import java.util.Date; 6 import java.util.regex.Pattern; 7 public class Data { 8 9 //连接数据库*********************************************************************** 10 public Connection getConnection()//连接数据库 11 { 12 try{ 13 Class.forName("com.mysql.cj.jdbc.Driver"); 14 //System.out.println("加载驱动成功"); 15 }catch(ClassNotFoundException e) 16 { 17 e.printStackTrace(); 18 } 19 String user="root"; 20 String password="123456"; 21 String url = "jdbc:mysql://localhost:3306/ztest01?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf-8&autoReconnect=true"; 22 Connection con=null; 23 try{ 24 con=DriverManager.getConnection(url,user,password); 25 //System.out.println("数据库连接成功"); 26 }catch(SQLException e) 27 { 28 e.printStackTrace(); 29 } 30 return con; 31 } 32 //关闭方法********************************************************************** 33 public void close (Connection con) 34 { 35 try{ 36 if(con!=null) 37 { 38 con.close(); 39 } 40 }catch(SQLException e) 41 { 42 e.printStackTrace(); 43 } 44 } 45 public void close (PreparedStatement preparedStatement) 46 { 47 try{ 48 if(preparedStatement!=null) 49 { 50 preparedStatement.close(); 51 } 52 }catch(SQLException e) 53 { 54 e.printStackTrace(); 55 } 56 } 57 public void close(ResultSet resultSet) 58 { 59 try{ 60 if(resultSet!=null) 61 { 62 resultSet.close(); 63 } 64 }catch(SQLException e) 65 { 66 e.printStackTrace(); 67 } 68 } 69 //数据库操作******************************************************************** 70 public void addreader(String id,String name,String sex,String school,String password)//add reader 71 { 72 Connection connection = getConnection(); 73 PreparedStatement preparedStatement=null; 74 try { 75 String sql = "insert into readers (id,name,sex,school,password) values (?,?,?,?,?)"; 76 preparedStatement=connection.prepareStatement(sql); 77 preparedStatement.setString(1,id); 78 preparedStatement.setString(2,name); 79 preparedStatement.setString(3,sex); 80 preparedStatement.setString(4,school); 81 preparedStatement.setString(5,password); 82 preparedStatement.executeUpdate(); 83 } catch (SQLException e) { 84 e.printStackTrace(); 85 }finally{ 86 close(preparedStatement); 87 close(connection); 88 } 89 } 90 public void addbook(String id,String name,String author,String company,String number,String nowout)//add book 91 { 92 Connection connection = getConnection(); 93 PreparedStatement preparedStatement=null; 94 try { 95 String sql = "insert into books (id,name,author,company,number,nowout) values (?,?,?,?,?,?)"; 96 preparedStatement=connection.prepareStatement(sql); 97 preparedStatement.setString(1,id); 98 preparedStatement.setString(2,name); 99 preparedStatement.setString(3,author); 100 preparedStatement.setString(4,company); 101 preparedStatement.setString(5,number); 102 preparedStatement.setString(6,nowout); 103 preparedStatement.executeUpdate(); 104 } catch (SQLException e) { 105 e.printStackTrace(); 106 }finally{ 107 close(preparedStatement); 108 close(connection); 109 } 110 } 111 112 public void addborrow(String readerid,String bookid,String outnow) { 113 Connection connection = getConnection(); 114 PreparedStatement preparedStatement1=null; 115 PreparedStatement preparedStatement2=null; 116 try { 117 String sql1 = "insert into borrows (readerid,bookid,borrowtime) values (?,?,?)"; 118 preparedStatement1=connection.prepareStatement(sql1); 119 preparedStatement1.setString(1,readerid); 120 preparedStatement1.setString(2,bookid); 121 122 SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ); 123 Date dadate = new Date(); 124 String nowDaDate = sdf.format(dadate); 125 Timestamp daTs = Timestamp.valueOf(nowDaDate); 126 preparedStatement1.setTimestamp(3,daTs); 127 128 String sql2 = "update books set outnow=? where id=?"; 129 preparedStatement2=connection.prepareStatement(sql2); 130 preparedStatement2.setString(1,outnow); 131 preparedStatement2.setString(2,bookid); 132 133 preparedStatement1.executeUpdate(); 134 preparedStatement2.executeUpdate(); 135 } catch (SQLException e) { 136 e.printStackTrace(); 137 }finally{ 138 close(preparedStatement1); 139 close(preparedStatement2); 140 close(connection); 141 } 142 } 143 144 public void back(String readerid,String bookid,String outnow) 145 { 146 Connection connection = getConnection(); 147 PreparedStatement preparedStatement1=null; 148 PreparedStatement preparedStatement2=null; 149 try { 150 String sql = "delete from borrows where bookid= ? and readerid = ?"; 151 preparedStatement1=connection.prepareStatement(sql); 152 preparedStatement1.setString(1,bookid); 153 preparedStatement1.setString(2,readerid); 154 155 String sql2 = "update books set outnow=? where id=?"; 156 preparedStatement2=connection.prepareStatement(sql2); 157 preparedStatement2.setString(1,outnow); 158 preparedStatement2.setString(2,bookid); 159 160 preparedStatement1.executeUpdate(); 161 preparedStatement2.executeUpdate(); 162 } catch (SQLException e) { 163 e.printStackTrace(); 164 }finally{ 165 close(preparedStatement1); 166 close(preparedStatement2); 167 close(connection); 168 } 169 } 170 171 172 173 //判断****************************************************************************** 174 public boolean passwordIsRightStudents(String id,String password) { //judge password is right-Students 175 Connection connection = getConnection(); 176 PreparedStatement preparedStatement=null; 177 ResultSet rs=null; 178 try { 179 String sql = "select * from readers"; 180 preparedStatement=connection.prepareStatement(sql); 181 rs=preparedStatement.executeQuery(); 182 while(rs.next()){ 183 if( id.equals(rs.getObject(1))&&password.equals(rs.getObject(5)) ) 184 return true; 185 } 186 } catch (SQLException e) { 187 e.printStackTrace(); 188 }finally{ 189 close(rs); 190 close(preparedStatement); 191 close(connection); 192 } 193 return false; 194 } 195 196 197 public boolean useridisIdRight(String num) {//judge userid 198 int k=0; 199 if(num.length()==8) { 200 for(int i=0;i<8;i++) { 201 char c=num.charAt(i); 202 if(c=='0'||c=='1'||c=='2'||c=='3'||c=='4'||c=='5'||c=='6'||c=='7'||c=='8'||c=='9') 203 k++; 204 } 205 if(k==8) 206 return true; 207 else return false; 208 } 209 else return false; 210 } 211 212 213 public boolean studentexist(String id) { //have this student 214 Connection connection = getConnection(); 215 PreparedStatement preparedStatement=null; 216 ResultSet rs=null; 217 try { 218 String sql = "select id from readers"; 219 preparedStatement=connection.prepareStatement(sql); 220 rs=preparedStatement.executeQuery(); 221 while(rs.next()){ 222 if( id.equals(rs.getObject(1)) ) 223 return true; 224 } 225 } catch (SQLException e) { 226 e.printStackTrace(); 227 }finally{ 228 close(rs); 229 close(preparedStatement); 230 close(connection); 231 } 232 return false; 233 } 234 235 public boolean bookexist(String id) { //have this book 236 Connection connection = getConnection(); 237 PreparedStatement preparedStatement=null; 238 ResultSet rs=null; 239 try { 240 String sql = "select id from books"; 241 preparedStatement=connection.prepareStatement(sql); 242 rs=preparedStatement.executeQuery(); 243 while(rs.next()){ 244 if( id.equals(rs.getObject(1)) ) 245 return true; 246 } 247 } catch (SQLException e) { 248 e.printStackTrace(); 249 }finally{ 250 close(rs); 251 close(preparedStatement); 252 close(connection); 253 } 254 return false; 255 } 256 public boolean bookidisIdRight(String num) {//judge bookid 257 int k=0; 258 for(int i=0;i<num.length();i++) { 259 char c=num.charAt(i); 260 if(c=='0'||c=='1'||c=='2'||c=='3'||c=='4'||c=='5'||c=='6'||c=='7'||c=='8'||c=='9') 261 k++; 262 } 263 if(k==num.length()) 264 return true; 265 else return false; 266 267 } 268 public boolean isNumber(String str) {//judge int 269 Pattern pattern = Pattern.compile("^[-\+]?[\d]*$"); 270 return pattern.matcher(str).matches(); 271 } 272 273 274 public boolean readerHaveBorrow(String readerid,String bookid) { //student have chosen this book 275 Connection connection = getConnection(); 276 PreparedStatement preparedStatement=null; 277 ResultSet rs=null; 278 try { 279 String sql = "select * from borrows"; 280 preparedStatement=connection.prepareStatement(sql); 281 rs=preparedStatement.executeQuery(); 282 while(rs.next()){ 283 if( readerid.equals(rs.getObject(2))&&bookid.equals(rs.getObject(1)) ) 284 return true; 285 } 286 } catch (SQLException e) { 287 e.printStackTrace(); 288 }finally{ 289 close(rs); 290 close(preparedStatement); 291 close(connection); 292 } 293 return false; 294 } 295 296 297 public static void main(String[] args) { 298 Data a= new Data(); 299 //a.addbook("00","00","00","00","00","00"); 300 301 } 302 303 }
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>登录</title> 8 </head> 9 <body background="images .jpg" style="text-align:center;color:white;font-family:宋体; font-size:20px"> 10 <form action="loginjudge.jsp" method="get"> 11 <br> 图书管理系统 <br> 12 <br> 用户名: <input type="text" name="id" /><br> 13 <br> 密 码: <input type="password" name="password" /><br> 14 <br> 15 <br> 16 <input type="radio" name="usertype" value="reader" />读者 17 <input type="radio" name="usertype" value="op" />管理员 18 <br> 19 <br> <input type="submit" value="登录" /> 20 <input type="reset" value="重置" /> 21 <br> 22 </form> 23 </body> 24 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>管理员界面</title> 8 </head> 9 <body background="images .jpg" style="text-align:center;color:white;font-family:宋体; font-size:20px"> 10 <br> 11 <br> 12 <input type="button" value="添加读者信息" onclick="location.href='opaddreader.jsp'" /> 13 <input type="button" value="添加新书信息" onclick="location.href='opaddbook.jsp'" /> 14 <input type="button" value="催还书目信息" onclick="location.href='opback.jsp'" /> 15 <br> 16 <br> 17 <input type="button" value="退出登录" onclick="location.href='login.jsp'" /> 18 </body> 19 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>添加图书</title> 8 </head> 9 <body background="images .jpg" style="text-align:center;color:white;font-family:宋体; font-size:20px"> 10 <form action="opaddbook2.jsp" method="get"> 11 <br> 12 添加图书 13 <br> 14 <br> 图书 编号 <input type="text" name="id" /><br> 15 <br> 书 名 <input type="text" name="name" /><br> 16 <br> 作 者 <input type="text" name="author" /><br> 17 <br> 出 版 商 <input type="text" name="company" /><br> 18 <br> 可借阅数量 <input type="text" name="number" /><br> 19 <br> 20 <br> 21 <br><input type="submit" value="提交" /> 22 <input type="reset" value="重置" /> <br> 23 <br> <input type="button" value="返回菜单" onclick="location.href='op.jsp'" /> <br> 24 </form> 25 </body> 26 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 </head> 8 <body> 9 <jsp:useBean id="util" class="test2.Data" scope="page" /> 10 <% 11 String id=(String)request.getParameter("id"); 12 String name=(String)request.getParameter("name"); 13 String author=(String)request.getParameter("author"); 14 String company=(String)request.getParameter("company"); 15 String number=(String)request.getParameter("number"); 16 String nowout="0"; 17 if(id==""||name==""||author==""||company==""||number=="") 18 { 19 out.print("<script language='javaScript'> alert('输入为空');window.history.back(-1);</script>"); 20 } 21 else if(!util.bookidisIdRight(id)){ 22 out.print("<script language='javaScript'> alert('编号由数字组成');window.history.back(-1);</script>"); 23 } 24 else if(util.bookexist(id)){ 25 out.print("<script language='javaScript'> alert('已存在该图书');window.history.back(-1);</script>"); 26 } 27 else if(!util.isNumber(number)){ 28 out.print("<script language='javaScript'> alert('可借阅数量应为整数');window.history.back(-1);</script>"); 29 } 30 else{ 31 util.addbook(id, name, author, company, number, nowout); 32 out.print("<script language='javaScript'> alert('添加成功');</script>"); 33 response.setHeader("refresh", "0;url=opaddbook.jsp"); 34 } 35 36 %> 37 38 </body> 39 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>添加读者</title> 8 </head> 9 <body background="images .jpg" style="text-align:center;color:white;font-family:宋体; font-size:20px"> 10 <form action="opaddreader2.jsp" method="get"> 11 <br> 12 添加学生 13 <br> 14 <br> 学生学号 <input type="text" name="id" /><br> 15 <br> 学生姓名 <input type="text" name="name" /><br> 16 <br> 性别 <input type="radio" name="sex" value="男" />男 17 <input type="radio" name="sex" value="女" />女 18 <br> 19 <br> 学 院 <input type="text" name="school" /><br> 20 <br> 21 <br> 22 <br><input type="submit" value="提交" /> 23 <input type="reset" value="重置" /> <br> 24 <br> <input type="button" value="返回菜单" onclick="location.href='op.jsp'" /> <br> 25 </form> 26 </body> 27 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 </head> 8 <body> 9 <jsp:useBean id="util" class="test2.Data" scope="page" /> 10 <% 11 String id=(String)request.getParameter("id"); 12 String name=(String)request.getParameter("name"); 13 String sex=(String)request.getParameter("sex"); 14 String school=(String)request.getParameter("school"); 15 if(id==""||name==""||sex==null||school=="") 16 { 17 out.print("<script language='javaScript'> alert('输入为空');window.history.back(-1);</script>"); 18 } 19 else if(!util.useridisIdRight(id)){ 20 out.print("<script language='javaScript'> alert('学号由八位数字组成');window.history.back(-1);</script>"); 21 } 22 else if(util.studentexist(id)){ 23 out.print("<script language='javaScript'> alert('已存在该读者');window.history.back(-1);</script>"); 24 } 25 else{ 26 util.addreader(id, name, sex, school, id); 27 out.print("<script language='javaScript'> alert('添加成功');</script>"); 28 response.setHeader("refresh", "0;url=opaddreader.jsp"); 29 } 30 31 %> 32 33 </body> 34 </html>
1 <%@ page language="java" import="java.sql.*" import="java.util.Date" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>催还书目</title> 8 </head> 9 <body background="images .jpg" style="text-align:center;color:white;font-family:宋体; font-size:20px"> 10 <jsp:useBean id="util" class="test2.Data" scope="page" /> 11 <div style="text-align: center;"> 12 <table border="1" style="margin: auto;"> 13 <tr> 14 <td align="center" width=10%>图书编号</td> 15 <td align="center" width=10%>书籍名称</td> 16 <td align="center" width=10%>借阅日期</td> 17 <td align="center" width=10%>借阅人学号</td> 18 <td align="center" width=10%>借阅人姓名</td> 19 </tr> 20 <% 21 String id=(String)session.getAttribute("id"); 22 Connection connection = util.getConnection(); 23 PreparedStatement preparedStatement1=null; 24 PreparedStatement preparedStatement2=null; 25 PreparedStatement preparedStatement3=null; 26 ResultSet rs1=null; 27 ResultSet rs2=null; 28 ResultSet rs3=null; 29 try { 30 String sql = "select * from borrows"; 31 preparedStatement1=connection.prepareStatement(sql); 32 rs1=preparedStatement1.executeQuery(); 33 34 String sql2 = "select * from books"; 35 preparedStatement2=connection.prepareStatement(sql2); 36 rs2=preparedStatement2.executeQuery(); 37 38 String sql3 = "select * from readers"; 39 preparedStatement3=connection.prepareStatement(sql3); 40 rs3=preparedStatement3.executeQuery(); 41 42 while(rs1.next()) { 43 Date borrowtime = new Date(rs1.getDate(3).getTime()); 44 Date nowtime = new Date(); 45 long day=(nowtime.getTime()-borrowtime.getTime())/(24*60*60*1000); 46 if(day > 90){ 47 %><tr><td align="center"><%=rs1.getObject(1) %></td><% 48 while(rs2.next()) { 49 if(rs2.getObject(1).equals(rs1.getObject(1))){ 50 %><td align="center"><%=rs2.getObject(2) %></td><% 51 } 52 } 53 %> 54 <td align="center"><%=rs1.getObject(3) %></td> 55 <td align="center"><%=rs1.getObject(2) %></td> 56 <% 57 while(rs3.next()) { 58 if(rs3.getObject(1).equals(rs1.getObject(2))){ 59 %><td align="center"><%=rs3.getObject(2) %></td><% 60 } 61 } 62 %> 63 </tr> 64 <% 65 } 66 } 67 } catch (SQLException e) { 68 e.printStackTrace(); 69 }finally{ 70 util.close(rs3); 71 util.close(rs1); 72 util.close(rs2); 73 util.close(preparedStatement1); 74 util.close(preparedStatement2); 75 util.close(preparedStatement3); 76 util.close(connection); 77 } 78 %> 79 </table> 80 </div> 81 <br> <input type="button" value="返回菜单" onclick="location.href='op.jsp'" /> <br> 82 </body> 83 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>读者界面</title> 8 </head> 9 <body background="images .jpg" style="text-align:center;color:white;font-family:宋体; font-size:20px"> 10 <br> 11 <br> 12 <input type="button" value="浏览图书信息" onclick="location.href='readerlookbook.jsp'" /> 13 <input type="button" value="查询借阅图书" onclick="location.href='readersearch.jsp'" /> 14 <input type="button" value="浏览催还书目" onclick="location.href='readerneedback.jsp'" /> 15 <input type="button" value="归还图书" onclick="location.href='readerback.jsp'" /> 16 <br> 17 <br> 18 <input type="button" value="退出登录" onclick="location.href='login.jsp'" /> 19 </body> 20 </html>
1 <%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>归还图书</title> 8 </head> 9 <body background="images .jpg" style="text-align:center;color:white;font-family:宋体; font-size:20px"> 10 <jsp:useBean id="util" class="test2.Data" scope="page" /> 11 <div style="text-align: center;"> 12 <table border="1" style="margin: auto;"> 13 <tr> 14 <td align="center" width=10%>编号</td> 15 <td align="center" width=10%>书名</td> 16 <td align="center" width=10%>作者</td> 17 <td align="center" width=10%>出版商</td> 18 <td align="center" width=10%>归还</td> 19 </tr> 20 <% 21 String readerid=(String)session.getAttribute("id"); 22 Connection connection = util.getConnection(); 23 PreparedStatement preparedStatement=null; 24 ResultSet rs=null; 25 try { 26 String sql = "select * from books"; 27 preparedStatement=connection.prepareStatement(sql); 28 rs=preparedStatement.executeQuery(); 29 while(rs.next()){ 30 if(util.readerHaveBorrow(readerid, (String)rs.getObject(1))){ 31 %> 32 <tr> 33 <td align="center"><%=rs.getObject(1) %></td> 34 <td align="center"><%=rs.getObject(2) %></td> 35 <td align="center"><%=rs.getObject(3) %></td> 36 <td align="center"><%=rs.getObject(4) %></td> 37 <td align="center"> <a style="color:white" href='readerback2.jsp?id=<%=rs.getObject(1) %>&outnow=<%=rs.getObject(6) %>'>归还</a> </td> 38 </tr> 39 <% 40 } 41 } 42 } catch (SQLException e) { 43 e.printStackTrace(); 44 }finally{ 45 util.close(rs); 46 util.close(preparedStatement); 47 util.close(connection); 48 } 49 %> 50 </table> 51 </div> 52 <br> <input type="button" value="返回菜单" onclick="location.href='reader.jsp'" /> <br> 53 </body> 54 </html>
1 <%@ page language="java" import="java.sql.*" import="java.util.Date" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 </head> 8 <body> 9 <jsp:useBean id="util" class="test2.Data" scope="page" /> 10 <% 11 String readerid=(String)session.getAttribute("id"); 12 String bookid=(String)request.getParameter("id"); 13 String outnow0=(String)request.getParameter("outnow"); 14 String outnow= Integer.toString(Integer.parseInt(outnow0)-1); 15 long day=0; 16 Connection connection = util.getConnection(); 17 PreparedStatement preparedStatement=null; 18 ResultSet rs=null; 19 try { 20 String sql = "select * from borrows"; 21 preparedStatement=connection.prepareStatement(sql); 22 rs=preparedStatement.executeQuery(); 23 while(rs.next()) { 24 if(readerid.equals(rs.getObject(2))&&bookid.equals(rs.getObject(1))){ 25 Date borrowtime = new Date(rs.getDate(3).getTime()); 26 Date nowtime = new Date(); 27 day=(nowtime.getTime()-borrowtime.getTime())/(24*60*60*1000); 28 } 29 } 30 }catch (SQLException e) { 31 e.printStackTrace(); 32 }finally{ 33 util.close(rs); 34 util.close(preparedStatement); 35 util.close(connection); 36 } 37 if(day<=90){ 38 util.back(readerid, bookid, outnow); 39 out.print("<script language='javaScript'> alert('归还成功');</script>"); 40 response.setHeader("refresh", "0;url=readerback.jsp"); 41 } 42 else { 43 double money=(double)(day-90)*0.1; 44 util.back(readerid, bookid, outnow); 45 out.print("<script language='javaScript'> alert('支付成功,归还成功');</script>"); 46 response.setHeader("refresh", "0;url=readerback.jsp"); 47 } 48 %> 49 </body> 50 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>借阅图书</title> 8 </head> 9 <body background="images .jpg" style="text-align:center;color:white;font-family:宋体; font-size:20px"> 10 <jsp:useBean id="util" class="test2.Data" scope="page" /> 11 <% 12 String readerid=(String)session.getAttribute("id"); 13 String bookid=(String)request.getParameter("id"); 14 String outnow0=(String)request.getParameter("outnow"); 15 String outnow= Integer.toString(Integer.parseInt(outnow0)+1); 16 17 if(util.readerHaveBorrow(readerid, bookid)){ 18 out.print("<script language='javaScript'> alert('你已经借阅了这本书');window.history.back(-1);</script>"); 19 } 20 else{ 21 util.addborrow(readerid, bookid, outnow); 22 out.print("<script language='javaScript'> alert('借阅成功');</script>"); 23 response.setHeader("refresh", "0;url=readersearch.jsp"); 24 } 25 %> 26 </body> 27 </html>
1 <%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>浏览图书信息</title> 8 </head> 9 <body background="images .jpg" style="text-align:center;color:white;font-family:宋体; font-size:20px"> 10 <jsp:useBean id="util" class="test2.Data" scope="page" /> 11 <div style="text-align: center;"> 12 <table border="1" style="margin: auto;"> 13 <tr> 14 <td align="center" width=10%>编号</td> 15 <td align="center" width=10%>书名</td> 16 <td align="center" width=10%>作者</td> 17 <td align="center" width=10%>出版商</td> 18 <td align="center" width=10%>可借阅数量</td> 19 </tr> 20 <% 21 String userid=(String)session.getAttribute("userid"); 22 Connection connection = util.getConnection(); 23 PreparedStatement preparedStatement=null; 24 ResultSet rs=null; 25 try { 26 String sql = "select * from books"; 27 preparedStatement=connection.prepareStatement(sql); 28 rs=preparedStatement.executeQuery(); 29 while(rs.next()){ 30 %> 31 <tr> 32 <td align="center"><%=rs.getObject(1) %></td> 33 <td align="center"><%=rs.getObject(2) %></td> 34 <td align="center"><%=rs.getObject(3) %></td> 35 <td align="center"><%=rs.getObject(4) %></td> 36 <td align="center"><%=rs.getObject(5) %></td> 37 </tr> 38 <% 39 } 40 } catch (SQLException e) { 41 e.printStackTrace(); 42 }finally{ 43 util.close(rs); 44 util.close(preparedStatement); 45 util.close(connection); 46 } 47 %> 48 </table> 49 </div> 50 <br> <input type="button" value="返回菜单" onclick="location.href='reader.jsp'" /> <br> 51 </body> 52 </html>
1 <%@ page language="java" import="java.sql.*" import="java.util.Date" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>浏览催还书目</title> 8 </head> 9 <body background="images .jpg" style="text-align:center;color:white;font-family:宋体; font-size:20px"> 10 <jsp:useBean id="util" class="test2.Data" scope="page" /> 11 <div style="text-align: center;"> 12 <table border="1" style="margin: auto;"> 13 <tr> 14 <td align="center" width=10%>图书编号</td> 15 <td align="center" width=10%>书籍名称</td> 16 <td align="center" width=10%>借阅日期</td> 17 </tr> 18 <% 19 String id=(String)session.getAttribute("id"); 20 Connection connection = util.getConnection(); 21 PreparedStatement preparedStatement=null; 22 PreparedStatement preparedStatement0=null; 23 ResultSet rs1=null; 24 ResultSet rs2=null; 25 try { 26 String sql = "select * from borrows"; 27 preparedStatement=connection.prepareStatement(sql); 28 rs1=preparedStatement.executeQuery(); 29 30 String sql2 = "select * from books"; 31 preparedStatement0=connection.prepareStatement(sql2); 32 rs2=preparedStatement0.executeQuery(); 33 while(rs1.next()) { 34 if(id.equals((String)rs1.getObject(2))){ 35 Date borrowtime = new Date(rs1.getDate(3).getTime()); 36 Date nowtime = new Date(); 37 long day=(nowtime.getTime()-borrowtime.getTime())/(24*60*60*1000); 38 if(day > 90){ 39 %><tr><td align="center"><%=rs1.getObject(1) %></td><% 40 while(rs2.next()) { 41 if(rs2.getObject(1).equals(rs1.getObject(1))){ 42 %><td align="center"><%=rs2.getObject(2) %></td><% 43 } 44 } 45 %> 46 <td align="center"><%=rs1.getObject(3) %></td> 47 </tr> 48 <% 49 } 50 } 51 } 52 } catch (SQLException e) { 53 e.printStackTrace(); 54 }finally{ 55 util.close(rs1); 56 util.close(rs2); 57 util.close(preparedStatement); 58 util.close(preparedStatement0); 59 util.close(connection); 60 } 61 %> 62 </table> 63 </div> 64 <br> <input type="button" value="返回菜单" onclick="location.href='reader.jsp'" /> <br> 65 </body> 66 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>缴费</title> 8 </head> 9 <body background="images .jpg" style="text-align:center;color:white;font-family:宋体; font-size:20px"> 10 <jsp:useBean id="util" class="test2.Data" scope="page" /> 11 12 13 </body> 14 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>查询图书</title> 8 </head> 9 <body background="images .jpg" style="text-align:center;color:white;font-family:宋体; font-size:20px"> 10 <form action="readersearch2.jsp" method="get"> 11 <br> 12 输入要查询信息的书名/作者(支持模糊查询): 13 <br> <input type="text" name="data" /> <br> 14 <br><input type="submit" value="提交" /> 15 <input type="reset" value="重置" /> <br> 16 <br> <input type="button" value="返回菜单" onclick="location.href='reader.jsp'" /> <br> 17 </form> 18 </body> 19 </html>
1 <%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>查询结果</title> 8 </head> 9 <body background="images .jpg" style="text-align:center;color:white;font-family:宋体; font-size:20px"> 10 查询结果 11 <jsp:useBean id="util" class="test2.Data" scope="page" /> 12 <% 13 String data=(String)request.getParameter("data"); 14 if(data==""){ 15 out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>"); 16 } 17 else 18 { 19 %> 20 <div style="text-align: center;"> 21 <table border="1" style="margin: auto;"> 22 <tr> 23 <td align="center" width=10%>编号</td> 24 <td align="center" width=10%>书名</td> 25 <td align="center" width=10%>作者</td> 26 <td align="center" width=10%>出版商</td> 27 <td align="center" width=10%>可借阅数量</td> 28 <td align="center" width=10%>当前借出</td> 29 <td align="center" width=10%>借阅</td> 30 </tr> 31 <% 32 int i=0; 33 Connection connection = util.getConnection(); 34 PreparedStatement preparedStatement=null; 35 ResultSet rs=null; 36 try { 37 String sql= " select * from books where name like ? or author like ? "; 38 preparedStatement=connection.prepareStatement(sql); 39 preparedStatement.setString(1,"%"+data+"%"); 40 preparedStatement.setString(2,"%"+data+"%"); 41 rs=preparedStatement.executeQuery(); 42 while(rs.next()) 43 { 44 i++; 45 if((int)rs.getObject(5)>(int)rs.getObject(6)){ 46 %> 47 <tr> 48 <td align="center"><%=rs.getObject(1) %></td> 49 <td align="center"><%=rs.getObject(2) %></td> 50 <td align="center"><%=rs.getObject(3) %></td> 51 <td align="center"><%=rs.getObject(4) %></td> 52 <td align="center"><%=rs.getObject(5) %></td> 53 <td align="center"><%=rs.getObject(6) %></td> 54 <td align="center"> <a style="color:white" href='readerborrow.jsp?id=<%=rs.getObject(1) %>&outnow=<%=rs.getObject(6) %>'>借阅</a> </td> 55 </tr> 56 <% 57 } 58 else{ 59 %> 60 <tr> 61 <td align="center"><%=rs.getObject(1) %></td> 62 <td align="center"><%=rs.getObject(2) %></td> 63 <td align="center"><%=rs.getObject(3) %></td> 64 <td align="center"><%=rs.getObject(4) %></td> 65 <td align="center"><%=rs.getObject(5) %></td> 66 <td align="center"><%=rs.getObject(6) %></td> 67 <td align="center">不可借阅</td> 68 </tr> 69 <% 70 71 } 72 } 73 if(i==0){ 74 out.print("<script language='javaScript'> alert('没有查询到有关信息'); window.history.back(-1); </script>"); 75 } 76 } catch (SQLException e) { 77 e.printStackTrace(); 78 }finally{ 79 util.close(rs); 80 util.close(preparedStatement); 81 util.close(connection); 82 } 83 } 84 %> 85 </table> 86 </div> 87 <br> <input type="button" value="返回" onclick="location.href='readersearch.jsp'" /> <br> 88 </body> 89 </html>