创建bookshop数据库,储存书店系统数据
创建zhanghao表,储存账号
创建kucun表,储存图书库存信息
我的书店管理系统部分功能实现代码如下:
登录页面代码:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>登陆</title> <style type="text/css"> table { border-collapse: collapse; border: none; margin: 0px auto; width: 400px; } th, td { border: solid #333 1px; height: 20px; } div { text-align: center; } </style> </head> <body> <form action="judge.jsp" method="post"> <table> <caption>登陆</caption> <tr> <th width="30%">账号:</th> <td width="70%"><input name="name" type="text"></td> </tr> <tr> <th>密码:</th> <td><input name="pwd" type="text"></td> </tr> <tr> <th colspan="2"><input type="submit" name="submit" value="登陆"> <input type="reset" value="重置"></th> </tr> </table> </form> </body> </html> Judge.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" import="java.sql.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>登陆验证</title> </head> <body> <center> <jsp:useBean id="db" class="BookShop.JavaBean" scope="page" /> <% String s = "select * from zhanghao"; ResultSet rs = db.executeQuery(s); rs.next(); String n = rs.getString(1); String k = rs.getString(2); rs.close(); db.close(); request.setCharacterEncoding("UTF-8"); String name = request.getParameter("name"); String pwd = request.getParameter("pwd"); if (name != null && pwd != null && name.equals(n) && pwd.equals(k)) { //response.sendRedirect("guanli.jsp"); %> <jsp:forward page="guanli.jsp" /> <% } else { out.println("<font color='red'>用户名或密码错误,3秒后回到登录页面,如果不想等待请点<a href='login.jsp'>返回登录</a></font>"); response.setHeader("refresh", "3;url=login.jsp"); } %> </center> </body> </html>
判断页面代码:
<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.sql.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>登陆验证</title> </head> <body> <center> <jsp:useBean id="db" class="BookShop.JavaBean" scope="page" /> <% String s = "select * from zhanghao"; ResultSet rs = db.executeQuery(s); rs.next(); String n = rs.getString(1); String k = rs.getString(2); rs.close(); db.close(); request.setCharacterEncoding("UTF-8"); String name = request.getParameter("name"); String pwd = request.getParameter("pwd"); if (name != null && pwd != null && name.equals(n) && pwd.equals(k)) { //response.sendRedirect("main.jsp"); %> <jsp:forward page="guanli.jsp" /> <% } else { out.println("<font color='red'>用户名或密码错误,3秒后回到登录页面,如果不想等待请点<a href='login.jsp'>返回登录</a></font>"); response.setHeader("refresh", "3;url=login.jsp"); } %> </center> </body> </html>
主页面代码:(包括查询数据库,输出查询结果)
<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.sql.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>管理主页</title> </head> <style type="text/css"> table { border-collapse: collapse; border: none; margin: 0px auto; width: 500px; } th, td { border: solid #333 1px; height: 20px; } div { text-align: center; } </style> </head> <table> <tr> <td>书号</td> <td>书名</td> <td>价格</td> <td>库存数量</td> <td>库存状态</td> </tr> <jsp:useBean id="db" class="BookShop.JavaBean" scope="page" /> <% String s = "select * from kucun"; ResultSet rs = db.executeQuery(s); String zhuangtai="库存正常"; while (rs.next()) { int quantity = rs.getInt(4); if(quantity>100){ zhuangtai="库存过多"; } else if(quantity>=20&&quantity<=100){ zhuangtai="库存正常"; } else if(quantity<20){ zhuangtai="库存过少"; } out.println("<tr><td>" + rs.getString(1) + "</td><td>" + rs.getString(2) + "</td><td>" +rs.getInt(3)+ "</td><td>" + quantity + "</td><td>" + zhuangtai + "</td></tr>"); } rs.close(); db.close(); %> </table> <h4 align="center"><a href="ruku.jsp">入库</a> <a href="chushou.jsp">出售</a> <a href="guanli.jsp">返回</a> </h4> </body> </html>
运行截图
: