数据库简单的登陆查询

创建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>&nbsp;&nbsp;<a href="chushou.jsp">出售</a>&nbsp;&nbsp;<a href="guanli.jsp">返回</a>    </h4>
</body>
</html>

运行截图

 

 

转载于:https://www.cnblogs.com/liulitianxia/p/6909312.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值