JSP图书管理系统【完整代码】.doc
Login.jsp代码:<% page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPEhtmlPUBLIC"-/W3C/DTDHTML4.01Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>登录图书管理系统 </title><style type="text/css"><!-.STYLE1 font-size: 36px; font-weight: bold;-></style></head><body><form name="form1" method="post"action="valid.jsp"><table width="400" height="120" border="1" align="center"><caption><span class="STYLE1">登录图书管理系统</span></caption><tr><td width="166">用户名:</td><td width="318"><input name="username" type="text" id="username"></td></tr><tr><td>密码:</td><td><input name="password" type="password" id="password"></td></tr><tr><tdcolspan="2"align="center"><inputtype="submit"name="Submit"value="登录"><input type="reset" name="Submit2" value="取消"></td></tr></table></form></body></html>Valid.jsp 代码:<% page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><% page import="java.sql.*" %><!DOCTYPEhtmlPUBLIC"-/W3C/DTDHTML4.01Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>判断登录</title></head><body><%String user=request.getParameter("username"); String pass=request.getParameter("password"); Class.forName("com.mysql.jdbc.Driver");Connectioncon=DriverManager.getConnection("jdbc:mysql:/localhost:3306/bk","root","12345 6");PreparedStatement ps =con.prepareStatement("select * from t_account where username=? and password=?");ps.setString(1,user); ps.setString(2,pass);ResultSet rs = ps.executeQuery(); if(rs.next()response.sendRedirect("bookList.jsp"); else response.sendRedirect("login.jsp");%></body></html>BookAdd.jsp 代码:<% page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPEhtmlPUBLIC"-/W3C/DTDHTML4.01Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>添加图书信息</title><style type="text/css"><!-.STYLE1 font-size: 36px; font-weight: bold;-></style></head><body><form name="form1" method="post" action="bookSaveAdd.jsp"><div align="center" class="STYLE1">添加图书信息</div><table width="300" height="120" border="1" align="center"><tr><td width="74">书名:</td><td width="210"><input name="name" type="text" id="name"></td></tr><tr><td>出版社:</td><td><input name="publish" type="text" id="publish"></td></tr><tr><td>价格:</td><td><input name="price" type="text" id="price"></td></tr><tr><tdcolspan="2"align="center"><inputtype="submit"name="Submit"value="确定添加"><input type="reset" name="Submit2" value="重置"></td></tr></table></form></body></html>BookDel.jsp 代码:<% page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%page import="java.sql.*"%><!DOCTYPEhtmlPUBLIC"-/W3C/DTDHTML4.01Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="refresh" content="3;URL=bookList.jsp"><title>删除图书</title></head><body><%/"3","4","6"String ids = request.getParameterValues("ids"); Class.forName("com.mysql.jdbc.Driver");Connectioncon= DriverManager.getConnection("jdbc:mysql:/localhost:3306/bk","root","12345 6");id=?");PreparedStatement ps = con.prepareStatement("delete from t_book wherefor(int i = 0;i<ids.length;i+) ps.setInt(1,Integer.parseInt(idsi); ps.execute();con.close();%>正在删除图书,3秒后自动跳转.</body></html>bookEdit.jsp 代码:<% page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><% page import="java.sql.*" %><!DOCTYPEhtmlPUBLIC"-/W3C/DTDHTML4.01Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>编辑图书信息</title><style type="text/css"><!-.STYLE1 font-size: 36px; font-weight: bold;-></style></head><body><%String strId = request.getParameter("id");/获取传过来的参数(网络上传输的只能是字符串)Class.forName("com.mysql.jdbc.Driver");/java的反射Connectioncon= DriverManager.getConnection("jdbc:mysql:/localhost:3306/bk","root","12345 6");PreparedStatement ps =con.prepareStatement("select * from t_book where id=?");ps.setInt(1,Integer.parseInt(strId);ResultSet rs=ps.executeQuery();if(rs.next()%><form name="form1" method="post" action="bookSaveEdit.jsp"><!- 关键语句 -><input type="hidden" name="id" value="<%=rs.getInt("id") %>"><div align="center" class="STYLE1">编辑图书信息</div><table width="300" height="120" border="1" align="center"><tr><td width="74">书名:</td><tdwidth="210"><inputname="name"type="text"id="name" value="<%=rs.getString("name") %>"></td></tr><tr><td>出版社:</td><td><inputname="publish"type="text"id="publish" value="<%=rs.getString("publish") %>"></td></tr><tr><td>价格:</td><td><inputname="price"type="text"id="price" value="<%=rs.getInt("price") %>"></td></tr><tr><tdcolspan="2"align="center"><inputtype="submit"name="Submit"value="确定修改"><input type="reset" name="Submit2" value="取消"></td></tr></table></form><%con.close();%></body></html>bookList.jsp 代码:<% page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><% page import="java.sql.*" %><!DOCTYPEhtmlPUBLIC"-/W3C/DTDHTML4.01Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>编辑图书信息</title><style type="text/css"><!-.STYLE1 font-size: 36px; font-weight: bold;-></style></head><body><%String strId = request.getParameter("id");/获取传过来的参数(网络上传输的只能是字符串)Class.forName("com.mysql.jdbc.Driver");/java的反射Connectioncon= DriverManager.getConnection("jdbc:mysql:/localhost:3306/bk","root","12345 6");PreparedStatement ps =con.prepareStatement("select * from t_book where id=?");ps.setInt(1,Integer.parseInt(strId);ResultSet rs=ps.executeQuery();if(rs.next()%><form name="form1" method="post" action="bookSaveEdit.jsp"><!- 关键语句 -><input type="hidden" name="id" value="<%=rs.getInt("id") %>"><div align="center" class="STYLE1">编辑图书信息</div><table width="300" height="120" border="1" align="center"><tr><td width="74">书名:</td><tdwidth="210"><inputname="name"type="text"id="name" value="<%=rs.getString("name") %>"></td></tr><tr><td>出版社:</td><td><inputname="publish"type="text"id="publish" value="<%=rs.getString("publish") %>"></td></tr><tr><td>价格:</td><td><inputname="price"type="text"id="price" value="<%=rs.getInt("price") %>"></td></tr><tr><tdcolspan="2"align="center"><inputtype="submit"name="Submit"value="确定修改"><input type="reset" name="Submit2" value="取消"></td></tr></table></form><%con.close();%></body></html>bookSaveAdd.jsp 代码:<% page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><% page import="java.sql.*" %><!DOCTYPEhtmlPUBLIC"-/W3C/DTDHTML4.01Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>保存添加</title></head><body><%/获取提交参数String name=request.getParameter("name"); String pub=request.getParameter("publish"); String strPr=request.getParameter("price");int price=Integer.parseInt(strPr);/数据转换:字符串(数字)转整型/利用jdbc完成数据库插入操作Class.forName("com.mysql.jdbc.Driver");/java的反射Connectioncon= DriverManager.getConnection("jdbc:mysql:/localhost:3306/bk","root","12345 6");PreparedStatementps=con.prepareStatement("insertinto t_book(name,publish,price) values(?,?,?)");ps.setString(1,name); ps.setString(2,pub); ps.setInt(3,price);ps.execute();con.close(); response.sendRedirect("bookList.jsp");%></body></html>bookSaveEdit.jsp 代码:<% page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><% page import="java.sql.*" %><!DOCTYPEhtmlPUBLIC"-/W3C/DTDHTML4.01Transitional/EN" "http:/www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>保存编辑</title></head><body><%String strId = request.getParameter("id"); String name=request.getParameter("name"); String pub=request.getParameter("publish"); String strPr=request.getParameter("price");int price=Integer.parseInt(strPr);/数据转换:字符串(数字)转整型int id=Integer.parseInt(strId);/利用jdbc完成数据库插入操作Class.forName("com.mysql.jdbc.Driver");/java的反射Connectioncon= DriverManager.getConnection("jdbc:mysql:/localhost:3306/bk","root","12345 6");PreparedStatementps=con.prepareStatement("updatet_bookset name=?,publish=?,price=? where id=?");ps.setString(1,name); ps.setString(2,pub); ps.setInt(3,price); ps.setInt(4,id);ps.execute();con.close(); response.sendRedirect("bookList.jsp");%></body></html>