Java+JSP+Mysql+Tomcat实现Web图书管理系统(下)

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: Java+JSP+Mysql+Tomcat实现Web图书管理系统

BookShelfDao

package com.sjsq.dao;
import com.sjsq.po.BookShelf;
import java.util.List;
/**
 * @author shuijianshiqing
 * @date 2021/5/22 12:23
 */
public interface BookShelfDao {
    /**
     * 按照用户名检索书架
     * @param userid
     * @return
     */
    public List<BookShelf> selectBookShelf(Integer userid);
    /**
     * 加入书架
     * @param bookShelf
     * @return
     */
    public boolean addBookShelf(BookShelf bookShelf);
    /**
     * 移出书架
     * @param userid
     * @param bookid
     * @return
     */
    public boolean removeBookShelf(Integer userid,Integer bookid);
}

RecordDao

package com.sjsq.dao;
import com.sjsq.po.Record;
import java.util.List;
/**
 * @author shuijianshiqing
 * @date 2021/5/22 22:07
 */
public interface RecordDao {
    /**
     * 查询所有借阅信息
     * @return
     */
    public List<Record> selectRecords();
    /**
     * 查询借阅信息
     * @return
     */
    public List<Record> selectRecord(Integer userid);
    /**
     * 新增借阅记录
     * @param record
     * @return
     */
    public boolean addRecord(Record record);
    /**
     * 删除借阅记录
     * @param borrowid
     * @return
     */
    public boolean deleteRecord(Integer borrowid);
}

UserDao

package com.sjsq.dao;
import com.sjsq.po.User;
import java.util.List;
/**
 * @author shuijianshiqing
 * @date 2020/5/20 22:10
 * 创建一个接口用于声明用户登录注册的方法
 */
public interface UserDao {
    /**
     * 用户登录
     * @param user
     * @return
     */
    public User login(User user);
    /**
     * 用户注册
     * @param user
     * @return
     */
    public boolean register(User user);
    /**
     * 查询用户信息
     * @param sql
     * @param arr
     * @return
     */
    public List<User> selectUser(String sql, Object arr[]);
    /**
     * 根据用户编号进行查询
     * @param userid
     * @return
     */
    public User getUser(Integer userid);
    /**
     * 新增用户
     * @param user
     * @return
     */
    public boolean addUser(User user);
    /**
     * 修改用户
     * @param user
     * @return
     */
    public boolean updateUser(User user);
    /**
     * 删除用户
     * @param userid
     * @return
     */
    public boolean deleteUser(Integer userid);
}

BookService

package com.sjsq.service;
import com.sjsq.po.Book;
import java.util.List;
/**
 * @author shuijianshiqing
 * @date 2020/5/20 23:37
 * Book的Service层
 */
public interface BookService {
    /**
     * 查询图书信息
     * @param bookname
     * @return
     */
    public List<Book> select(String bookname);
    /**
     * 根据图书编号进行查询
     * @param id
     * @return
     */
    public Book getBook(Integer id);
    /**
     * 图书新增
     * @param book
     * @return
     */
    public boolean addBook(Book book);
    /**
     * 图书修改
     * @param book
     * @return
     */
    public boolean updateBook(Book book);
    /**
     * 删除图书
     * @param bookid
     * @return
     */
    public boolean deleteBook(Integer bookid);
}

BookShelfService

package com.sjsq.service;
import com.sjsq.po.BookShelf;
import java.util.List;
/**
 * @author shuijianshiqing
 * @date 2021/5/22 12:36
 */
public interface BookShelfService {
    /**
     * 按照用户名检索书架
     * @param userid
     * @return
     */
    public List<BookShelf> selectBookShelf(Integer userid);
    /**
     * 加入书架
     * @param bookShelf
     * @return
     */
    public boolean addBookShelf(BookShelf bookShelf);
    /**
     * 移出书架
     * @param userid
     * @param bookid
     * @return
     */
    public boolean removeBookShelf(Integer userid,Integer bookid);
}

CommentService

package com.sjsq.service;
import com.sjsq.po.Comment;
import java.util.List;
/**
 * @author shuijianshiqing
 * @date 2021/5/22 17:21
 */
public interface CommentService {
    /**
     * 添加留言
     * @param comment
     * @return
     */
    public boolean addComment(Comment comment);
    /**
     * 展示留言
     * @param bookid
     * @return
     */
    public List<Comment> selectComment(Integer bookid);
}

RecordService

package com.sjsq.service;
import com.sjsq.po.Record;
import java.util.List;
/**
 * @author shuijianshiqing
 * @date 2021/5/22 22:17
 */
public interface RecordService {
    /**
     * 查询所有借阅信息
     * @return
     */
    public List<Record> selectRecords();
    /**
     * 查询借阅信息
     * @return
     */
    public List<Record> selectRecord(Integer userid);
    /**
     * 新增借阅记录
     * @param record
     * @return
     */
    public boolean addRecord(Record record);
    /**
     * 删除借阅记录
     * @param borrowid
     * @return
     */
    public boolean deleteRecord(Integer borrowid);
}

login.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
    <%
        // 获取绝对路径路径 ,开发项目一定要使用绝对路径,不然肯定出错
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":"
                + request.getServerPort() + path + "/";
    %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <base href="<%=basePath %>" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>用户登录</title>
    <style type="text/css">
        h1{
            text-align: center;
        }
        h4{
            text-align: center;color: red;
        }
        body{
            background-color: antiquewhite;
        }
        a{
            text-decoration: none;font-size: 20px;color: black;
        }
        a:hover{
            text-decoration: underline;font-size: 24px;color: red;
        }
    </style>
</head>
<body>
    <form action="login-do-info.jsp" method="post">
        <h1>用户登录</h1>
        <hr/>
        <table align="center">
            <tr>
                <td>账号:</td>
                <td><input type="text" name="username" id="username" placeholder="请输入您的账号" autofocus="autofocus"></td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input type="password" name="password" id="password" placeholder="请输入您的密码"></td>
                <td><a href="search-password.jsp">找回密码</a></td>
            </tr>
            <tr>
                <td colspan="1">
                </td>
                <td>
                    <input type="submit" value="登录"/>
                    <input type="reset" value="重置"/>
                    <a href="register.jsp" target="_blank">注册</a>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

login-do-info.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ page import="com.sjsq.dao.UserDao" %>
<%@ page import="com.sjsq.dao.impl.UserDaoImpl" %>
<%@ page import="com.sjsq.po.User" %>
<%@ page import="com.sjsq.service.UserService" %>
<%@ page import="com.sjsq.service.impl.UserServiceImpl" %>
<%@ page import="java.util.List" %>
<%
    // 获取绝对路径路径 ,开发项目一定要使用绝对路径,不然肯定出错
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":"
            + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <base href="<%=basePath %>"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>用户登录</title>
    <style type="text/css">
        h1 {
            text-align: center;
        }
        h4 {
            text-align: center;
            color: red;
        }
        body {
            background-color: antiquewhite;
        }
    </style>
</head>
<body>
<h1>现存图书列表</h1>
<hr>
<%
    // 设置接收的编码为UTF-8
    request.setCharacterEncoding("utf-8");
    User user = new User();
    UserDao dao = new UserDaoImpl();
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    user.setUsername(username);
    user.setPassword(password);
    // 获取用户登录信息
    User us = dao.login(user);
    // 把数据库里面的User获取出来
    UserService service = new UserServiceImpl();
    List<User> list = service.selectUser(username);
    for (int i = 0; i < list.size(); i++) {
        user = list.get(i);
    }
    System.out.println("----us的信息----");
    System.out.println(us);
    // 设置会话
    session.setAttribute("user", user);
    // 这里要对us判空处理,1是管理者,0是学生,此处的isadmin必须填写不能为空。
    if (us != null && us.getIsadmin().equals(1)) {
        response.sendRedirect("admin-home.jsp");
    } else if (us != null && !us.getIsadmin().equals(1)) {
        response.sendRedirect("user-home.jsp");
    } else {
        response.sendRedirect("login-fail.jsp");
    }
%>
</body>
</html>

login-fail.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>登录失败</title>
    <style type="text/css">
        h1{
            text-align: center;
        }
        h4{
            text-align: center;color: red;
        }
        body{
            background-color: antiquewhite;
        }
        div{
            text-align: center;
        }
    </style>
</head>
<body>
    <h1>登录失败</h1>
    <hr>
    <div>
        <a href="login.jsp">返回登录</a>
    </div>
</body>
</html>

logout.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>退出登录</title>
</head>
<body>
    <%
        // 杀掉会话
        session.invalidate();
        // 重定向,地址栏的链接会发生改变
        response.sendRedirect("login.jsp");
    %>
</body>
</html>

register.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>用户注册</title>
    <style type="text/css">
        h1{
            text-align: center;
        }
        h4{
            text-align: center;color: red;
        }
        body{
            background-color: antiquewhite;
        }
        div{
            text-align: center;
        }
    </style>
</head>
<body>
    <h1>用户注册</h1>
    <hr/>
    <form action="register-do.jsp" method="post" name="registerForm">
        <div>
            <tr>
                <label>您的账号:</label>
                <input type="text" name="name" id="name" placeholder="请输入用户名">
            </tr>
        </div>
        <div>
            <tr>
                <label>您的密码:</label>
                <input type="password" name="password" id="password" placeholder="请输入密码">
            </tr>
        </div>
        <div>
            <tr>
                <label>确认密码:</label>
                <input type="password" name="relpassword" id="relpassword" placeholder="请确认密码">
            </tr>
        </div>
        <div>
            <tr>
                <label>电话号码:</label>
                <input type="text" name="phone" id="phone" placeholder="请输入电话号码">
            </tr>
        </div>
        <div>
            <tr>
                <label>电子邮件:</label>
                <input type="text" name="email" id="email" placeholder="请输入电子邮件">
            </tr>
        </div>
        <div>
            <tr>
                <button type="submit" onclick="return checkForm()">注册</button>
                <button type="reset">重置</button>
                <a href="login.jsp" target="_blank">登录</a>
            </tr>
        </div>
    </form>
    <script type="text/javascript">
        function checkForm() {
            var name = registerForm.name.value;
            var pwd = registerForm.password.value;
            var repwd = registerForm.relpassword.value;
            //alert(name + pwd + repwd);
            if (name == "" || name == null) {
                alert("请输入用户名");
                registerForm.name.focus();
                return false;
            } else if (pwd == "" || pwd == null) {
                alert("请输入密码");
                registerForm.password.focus();
                return false;
            } else if (repwd == "" || repwd == null) {
                alert("请输入确认密码");
                registerForm.relpassword.focus();
                return false;
            } else if (pwd != repwd) {
                alert("两次密码输入不一致,请重新输入!");
                registerForm.relpassword.focus();
                return false;
            }
            alert('注册成功!');
            return true;
        }
    </script>
</body>
</html>

register-do.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@page import="com.sjsq.dao.impl.UserDaoImpl"%>
<%@page import="com.sjsq.dao.UserDao"%>
<%@page import="com.sjsq.po.User"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>处理注册</title>
</head>
<body>
    <%
        // 设置获取注册时的编码为UTF-8
        request.setCharacterEncoding("UTF-8");
        User user=new User();
        //获取register.jsp页面提交的账号和密码
        String name=request.getParameter("name");
        String password=request.getParameter("password");
        String email=request.getParameter("email");
        String phone=request.getParameter("phone");
        //获取register.jsp页面提交的账号和密码设置到实体类User中
        user.setUsername(name);
        user.setPassword(password);
        user.setEmail(email);
        user.setPhone(phone);
        //引入数据交互层
        UserDao dao=new UserDaoImpl();
        boolean flag=dao.register(user);
        if(flag){
            response.sendRedirect("login.jsp");
        }else{
            response.sendRedirect("register.jsp");
        }
    %>
</body>
</html>

search-password.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%
    // 获取绝对路径路径 ,开发项目一定要使用绝对路径,不然肯定出错
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":"
            + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath %>" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>找回密码</title>
    <style type="text/css">
        h1{
            text-align: center;
        }
        div{
            text-align: center;
        }
        body{
            background-color:antiquewhite;
        }
    </style>
</head>
<body>
    <h1>找回密码</h1>
    <hr>
    <div>
        <a href="javascript: window.history.go(-1)">返回上一级</a>
    </div>
    <br>
    <form action="search-password-do.jsp" method="post">
        <table align="center">
            <tr>
                <td>请输入账号:</td>
                <td><input type="text" name="name"/></td>
            </tr>
            <tr>
                <td colspan="1"></td>
                <td>
                    <input type="submit" value="提交">
                    <input type="reset" value="重置">
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

search-password-do.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@page import="java.util.List"%>
<%@page import="com.sjsq.service.impl.UserServiceImpl"%>
<%@page import="com.sjsq.po.User"%>
    <%
        // 获取绝对路径路径 ,开发项目一定要使用绝对路径,不然肯定出错
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":"
                + request.getServerPort() + path + "/";
    %>
<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath %>" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>处理找回密码</title>
</head>
<body>
    <%
        User user=new User();
        //获取searchPassword.jsp页面提交的账号和密码
        String name=request.getParameter("name");
        user.setUsername(name);
        UserServiceImpl service=new UserServiceImpl();
        List<User> list=service.selectUser(user);
        request.setAttribute("list", list);
        for(User u:list){
            request.setAttribute("user", u);
            out.print(u);
        }
        if(user!=null){
            request.getRequestDispatcher("search-password-info.jsp").forward(request, response);
        }
    %>
</body>
</html>

search-password-info.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%
    // 获取绝对路径路径 ,开发项目一定要使用绝对路径,不然肯定出错
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":"
            + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath %>" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>弹出信息</title>
    <script type="text/javascript">
        alert("您的密码是:${user.password}");
    </script>
    <style type="text/css">
        h1{
            text-align: center;
        }
        div{
            text-align: center;
        }
    </style>
</head>
<body>
    <h1>您的密码是:${user.password}</h1>
    <div>
        <td><a href="login.jsp">返回登录</a></td>
    </div>
</body>
</html>

admin-home.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>管理员主页</title>
    <style type="text/css">
        body {
            background-color: antiquewhite;
            text-align: center;
        }
    </style>
</head>
<body>
<%-- 头部 --%>
<jsp:include page="top.jsp"/>
<h1>欢迎来到图书管理系统</h1>
<hr>
<h4>管理员操作</h4>
    <a href="admin-user-manager.jsp">管理用户</a>
    <a href="admin-book-manager.jsp">管理图书</a>
</body>
</html>

admin-book-add.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>新增图书</title>
    <style type="text/css">
        h1 {
            text-align: center;
        }
        h4 {
            text-align: center;
            color: red;
        }
        body {
            background-color: antiquewhite;
        }
        div {
            text-align: center;
        }
        #before {
            text-align: center;
        }
    </style>
</head>
<body>
<%-- 头部 --%>
<jsp:include page="top.jsp"/>
<h1>新增图书</h1>
<hr>
<div id="before">
    <a href="javascript: window.history.go(-1)">返回上一级</a>
</div>
</br>
<form action="admin-book-do-add.jsp" method="post" name="registerForm">
    <div>
        <tr>
            <label>图书名称:</label>
            <input type="text" name="bookname" id="bookname" placeholder="图书名称" autofocus="autofocus">
        </tr>
    </div>
    <div>
        <tr>
            <label>图书价格:</label></td>
            <input type="text" name="price" id="price" placeholder="图书价格(数字)">
        </tr>
    </div>
    <div>
        <tr>
            <label>图书作者:</label>
            <input type="text" name="author" id="author" placeholder="图书作者">
        </tr>
    </div>
    <div>
        <tr>
            <label>出版公司:</label>
            <input type="text" name="publish" id="publish" placeholder="出版公司">
        </tr>
    </div>
    <div>
        <tr>
            <label>类型编号:</label>
            <input type="text" name="categoryid" id="categoryid" placeholder="类型编号">
        </tr>
    </div>
    <div>
        <tr>
            <label>书籍链接:</label>
            <input type="text" name="booklink" id="booklink" placeholder="书籍链接">
        </tr>
    </div>
    <div id="submitbtn">
        <tr>
            <button type="submit" onclick="return checkForm()">添加</button>
            <button type="reset">重置</button>
        </tr>
    </div>
</form>
<script type="text/javascript">
    function checkForm() {
        var bookname = registerForm.bookname.value;
        var price = registerForm.price.value;
        if (bookname == "" || bookname == null) {
            alert("请输入图书名称");
            registerForm.bookname.focus();
            return false;
        } else if (price == "" || price == null) {
            alert("请输入图书价格");
            registerForm.price.focus();
            return false;
        }
        alert('添加成功!');
        return true;
    }
</script>
</body>
</html>

admin-book-delete.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ page import="com.sjsq.dao.BookDao" %>
<%@ page import="com.sjsq.dao.impl.BookDaoImpl" %>
<%@ page import="com.sjsq.po.Book" %>
<%@ page import="com.sjsq.service.BookService" %>
<%@ page import="com.sjsq.service.impl.BookServiceImpl" %>
<html>
<head>
    <title>删除图书</title>
    <style type="text/css">
        #before {
            text-align: center;
        }
        body {
            background-color: antiquewhite;
        }
    </style>
</head>
<body>
<%-- 头部 --%>
<jsp:include page="top.jsp"/>
<%
    // 设置获取注册时的编码为UTF-8
    request.setCharacterEncoding("UTF-8");
    //获取admin.jsp页面的bookid
    Integer bookid = Integer.parseInt(request.getParameter("bookid"));
    //引入数据交互层
    BookService bookService = new BookServiceImpl();
    Book book = new Book();
    book = bookService.getBook(bookid);
    System.out.println("删除的图书信息:");
    System.out.println(book);
    boolean flag = bookService.deleteBook(bookid);
    if (flag) {
        response.sendRedirect("admin-book-manager.jsp");
    } else {
        response.sendRedirect("error.jsp");
    }
%>
</body>
</html>

admin-book-update.jsp

<%@ page import="com.sjsq.dao.BookDao" %>
<%@ page import="com.sjsq.dao.impl.BookDaoImpl" %>
<%@ page import="com.sjsq.po.Book" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>修改图书</title>
    <style type="text/css">
        h1 {
            text-align: center;
        }
        h4 {
            text-align: center;
            color: red;
        }
        body {
            background-color: antiquewhite;
        }
        div {
            text-align: center;
        }
    </style>
</head>
<body>
<%-- 头部 --%>
<jsp:include page="top.jsp"/>
<h1>修改图书</h1>
<hr/>
<%
    //获取admin-home.jsp页面的bookid
    Integer bookid = Integer.parseInt(request.getParameter("bookid"));
    BookDao dao = new BookDaoImpl();
    Book book = new Book();
    book = dao.getBook(bookid);
%>
<form action="admin-book-do-update.jsp" method="post" name="registerForm">
    <div>
        <tr>
            <input type="hidden" name="bookid" id="bookid" value="<%=book.getBookid()%>">
        </tr>
    </div>
    <div>
        <tr>
            <label>图书名称:</label>
            <input type="text" name="bookname" id="bookname" value="<%=book.getBookname()%>" autofocus="autofocus">
        </tr>
    </div>
    <div>
        <tr>
            <label>图书价格:</label></td>
            <input type="text" name="price" id="price" value="<%=book.getPrice()%>">
        </tr>
    </div>
    <div>
        <tr>
            <label>图书作者:</label>
            <input type="text" name="author" id="author" value="<%=book.getAuthor()%>">
        </tr>
    </div>
    <div>
        <tr>
            <label>出版公司:</label>
            <input type="text" name="publish" id="publish" value="<%=book.getPublish()%>">
        </tr>
    </div>
    <div>
        <tr>
            <label>类型编号:</label>
            <input type="text" name="categoryid" id="categoryid" value="<%=book.getCategoryid()%>">
        </tr>
    </div>
    <div>
        <tr>
            <label>书籍链接:</label>
            <input type="text" name="booklink" id="booklink" value="<%=book.getBooklink()%>">
        </tr>
    </div>
    <div>
        <tr>
            <button type="submit" onclick="return checkForm()">修改</button>
            <button type="reset">重置</button>
        </tr>
    </div>
</form>
<script type="text/javascript">
    function checkForm() {
        var bookname = registerForm.bookname.value;
        var price = registerForm.price.value;
        //alert(name + pwd + repwd);
        if (bookname == "" || bookname == null) {
            alert("请输入图书名称");
            registerForm.bookname.focus();
            return false;
        } else if (price == "" || price == null) {
            alert("请输入图书价格");
            registerForm.price.focus();
            return false;
        }
        alert('修改成功!');
        return true;
    }
</script>
</body>
</html>

admin-user-add.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>新增用户</title>
    <style type="text/css">
        h1 {
            text-align: center;
        }
        h4 {
            text-align: center;
            color: red;
        }
        body {
            background-color: antiquewhite;
        }
        div {
            text-align: center;
        }
        #before {
            text-align: center;
        }
    </style>
</head>
<body>
<%-- 头部 --%>
<jsp:include page="top.jsp"/>
<h1>新增用户</h1>
<hr>
<div id="before">
    <a href="javascript: window.history.go(-1)">返回上一级</a>
</div>
</br>
<form action="admin-user-do-add.jsp" method="post" name="registerForm">
    <div>
        <tr>
            <label>账号:</label>
            <input type="text" name="username" id="username" placeholder="用户名" autofocus="autofocus">
        </tr>
    </div>
    <div>
        <tr>
            <label>密码:</label></td>
            <input type="text" name="password" id="password" placeholder="密码">
        </tr>
    </div>
    <div>
        <tr>
            <label>邮箱:</label>
            <input type="text" name="email" id="email" placeholder="邮箱">
        </tr>
    </div>
    <div>
        <tr>
            <label>电话:</label>
            <input type="text" name="phone" id="phone" placeholder="电话">
        </tr>
    </div>
    <div>
        <tr>
            <label>是否管理员:</label>
            <input type="text" name="isadmin" id="isadmin" placeholder="是否管理员(1是,0否)">
        </tr>
    </div>
    <div id="submitbtn">
        <tr>
            <button type="submit" onclick="return checkForm()">添加</button>
            <button type="reset">重置</button>
        </tr>
    </div>
</form>
<script type="text/javascript">
    function checkForm() {
        var username = registerForm.username.value;
        var password = registerForm.password.value;
        if (username == "" || username == null) {
            alert("请输入用户名");
            registerForm.username.focus();
            return false;
        } else if (password == "" || password == null) {
            alert("请输入密码");
            registerForm.password.focus();
            return false;
        }
        alert('添加成功!');
        return true;
    }
</script>
</body>
</html>

admin-user-delete.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ page import="com.sjsq.po.User" %>
<%@ page import="com.sjsq.service.UserService" %>
<%@ page import="com.sjsq.service.impl.UserServiceImpl" %>
<html>
<head>
    <title>删除用户</title>
    <style type="text/css">
        #before {
            text-align: center;
        }
        body {
            background-color: antiquewhite;
        }
    </style>
</head>
<body>
<%-- 头部 --%>
<jsp:include page="top.jsp"/>
<%
    // 设置获取注册时的编码为UTF-8
    request.setCharacterEncoding("UTF-8");
    //获取admin-user-manager.jsp页面的userid
    Integer userid = Integer.parseInt(request.getParameter("userid"));
    //引入数据交互层
    UserService userService = new UserServiceImpl();
    // 获取删除用户的信息
    User user = userService.getUser(userid);
    System.out.println("删除的用户信息:"+user);
    boolean flag = userService.deleteUser(userid);
    if (flag) {
        response.sendRedirect("admin-user-manager.jsp");
    } else {
        response.sendRedirect("error.jsp");
    }
%>
</body>
</html>

admin-user-update.jsp

<%@ page import="com.sjsq.po.User" %>
<%@ page import="com.sjsq.service.UserService" %>
<%@ page import="com.sjsq.service.impl.UserServiceImpl" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>修改用户</title>
    <style type="text/css">
        h1 {
            text-align: center;
        }
        h4 {
            text-align: center;
            color: red;
        }
        body {
            background-color: antiquewhite;
        }
        div {
            text-align: center;
        }
    </style>
</head>
<body>
<%-- 头部 --%>
<jsp:include page="top.jsp"/>
<h1>修改用户</h1>
<hr/>
<%
    //获取admin-user-home.jsp页面的userid
    Integer userid = Integer.parseInt(request.getParameter("userid"));
    UserService userService = new UserServiceImpl();
    User user = userService.getUser(userid);
%>
<form action="admin-user-do-update.jsp" method="post" name="registerForm">
    <div>
        <tr>
            <label>编号:</label>
            <input type="text" name="userid" id="userid" readonly="readonly" value="<%=user.getUserid()%>">
        </tr>
    </div>
    <div>
        <tr>
            <label>用户:</label>
            <input type="text" name="username" id="username" readonly="readonly" value="<%=user.getUsername()%>">
        </tr>
    </div>
    <div>
        <tr>
            <label>密码:</label>
            <input type="text" name="password" id="password" value="<%=user.getPassword()%>">
        </tr>
    </div>
    <div>
        <tr>
            <label>邮箱:</label>
            <input type="text" name="email" id="email" value="<%=user.getEmail()%>">
        </tr>
    </div>
    <div>
        <tr>
            <label>电话:</label>
            <input type="text" name="phone" id="phone" value="<%=user.getPhone()%>">
        </tr>
    </div>
    <div>
        <tr>
            <label>是否管理员:</label>
            <input type="text" name="isadmin" id="isadmin" value="<%=user.getIsadmin()%>">
        </tr>
    </div>
    <div>
        <tr>
            <button type="submit" onclick="return checkForm()">修改</button>
            <button type="reset">重置</button>
        </tr>
    </div>
</form>
<script type="text/javascript">
    function checkForm() {
        var password = registerForm.password.value;
        if (password == "" || password == null) {
            alert("请输入密码");
            registerForm.password.focus();
            return false;
        }
        alert('修改成功!');
        return true;
    }
</script>
</body>
</html>

user-home.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ page import="com.sjsq.po.Book" %>
<%@ page import="com.sjsq.service.impl.BookServiceImpl" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>查看图书</title>
    <style type="text/css">
        h1 {
            text-align: center;
        }
        #before {
            text-align: center;
        }
    </style>
</head>
<body>
<%-- 头部 --%>
<jsp:include page="user-top.jsp"/>
<%--图书信息--%>
<%
    // 获取上一个页面传过来的值
    String bookname = request.getParameter("bookname");
    System.out.println("书名:" + bookname);
    // 传入的空字符串处理,null不能使用equals
    if (bookname != null && bookname.equals("")) {
        bookname = null;
    }
    BookServiceImpl service = new BookServiceImpl();
    List<Book> list = service.select(bookname);
%>
<h1>图书列表</h1>
<hr>
<div id="before">
    <form action="user-home.jsp" method="post">
        请输入书名:<input type="text" name="bookname" placeholder="输入图书名称搜索">
        <input type="submit" value="查询"/>
    </form>
    <a href="javascript: window.history.go(-1)">返回上一级</a>
</div>
<br>
<table align="center" cellspacing="0">
    <tr bgcolor="#5f9ea0" style="font-size: 20px;height:40px;text-align: center">
        <td style="width: 120px">编号</td>
        <td style="width: 120px">书名</td>
        <td style="width: 120px">价格</td>
        <td style="width: 120px">作者</td>
        <td style="width: 120px">出版社</td>
    </tr>
    <%
        String bg = null;
        for (int i = 0; i < list.size(); i++) {
            Book b = list.get(i);
            if (i % 2 == 0) {
                bg = "pink";
            } else {
                bg = "yellow";
            }
    %>
    <tr bgcolor="<%=bg%>" style="height:40px;text-align: center">
        <td><%=b.getBookid()%>
        </td>
        <td><a href="user-book-info.jsp?bookid=<%=b.getBookid()%>"><%=b.getBookname()%>
        </a></td>
        <td><%=b.getPrice() %>
        </td>
        <td><%=b.getAuthor() %>
        </td>
        <td><%=b.getPublish() %>
        </td>
    </tr>
    <%
        }
    %>
</table>
</body>
</html>

user-comment-add.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ page import="com.sjsq.po.User" %>
<%@ page import="com.sjsq.service.BookShelfService" %>
<%@ page import="com.sjsq.service.impl.BookShelfServiceImpl" %>
<%@ page import="com.sjsq.po.BookShelf" %>
<%@ page import="com.sjsq.po.Book" %>
<%@ page import="com.sjsq.service.BookService" %>
<%@ page import="com.sjsq.service.impl.BookServiceImpl" %>
<%@ page import="com.sjsq.service.CommentService" %>
<%@ page import="com.sjsq.service.impl.CommentServiceImpl" %>
<%@ page import="com.sjsq.po.Comment" %>
<html>
<head>
    <title>加入书架</title>
    <style type="text/css">
        body {
            background-color: antiquewhite;
        }
    </style>
</head>
<body>
<%-- 头部 --%>
<jsp:include page="top.jsp"/>
<%
    // 设置获取注册时的编码为UTF-8
    request.setCharacterEncoding("UTF-8");
    // 获取user信息
    User user =(User)session.getAttribute("user");
    Integer userid = user.getUserid();
    String username = user.getUsername();
    //获取book信息
    Integer bookid = Integer.parseInt(request.getParameter("bookid"));
    BookService bookService = new BookServiceImpl();
    Book book = bookService.getBook(bookid);
    String bookname = book.getBookname();
    String content = request.getParameter("content");
    Comment comment = new Comment();
    comment.setUserid(userid);
    comment.setUsername(username);
    comment.setBookid(bookid);
    comment.setBookname(bookname);
    comment.setComment(content);
    session.setAttribute("bookid",bookid);
    //引入数据交互层
    CommentService commentService = new CommentServiceImpl();
    boolean flag = commentService.addComment(comment);
    if (flag) {
        response.sendRedirect("user-book-info.jsp");
    } else {
        response.sendRedirect("error.jsp");
    }
%>
</body>
</html>


四、其他


1.其他系统实现


Java+JSP系统系列实现

Java+JSP实现学生图书管理系统

Java+JSP实现学生信息管理系统

Java+JSP实现用户信息管理系统


Java+Servlet+JSP系统系列实现

Java+Servlet+JSP实现航空订票系统

Java+Servlet+JSP实现新闻发布系统

Java+Servlet+JSP实现图书管理系统

Java+Servlet+JSP实现停车场管理系统

Java+Servlet+JSP实现房屋租赁管理系统

Java+Servlet+JSP实现学生选课管理系统

Java+Servlet+JSP实现宠物诊所管理系统

Java+Servlet+JSP实现学生宿舍管理系统

Java+Servlet+JSP实现学生信息管理系统

Java+Servlet+JSP实现学生成绩管理系统1

Java+Servlet+JSP实现学生成绩管理系统2


Java+SSM系统系列实现

Java+SSM+JSP实现宠物商城系统

Java+SSM+JSP实现超市订单系统

Java+SSM+Easyui实现网上考试系统

Java+SSM+Layui实现学生成绩管理系统

Java+SSM+Bootstrap实现学生信息管理系统

Java+SSM+Bootstrap+Maven实现网上书城系统

Java+SSM+Bootstrap+Maven实现学校教务管理系统


Java+SSH系统系列实现

Java+SSH+Bootstrap实现在线考试系统

Java+SSH+JSP实现医院在线挂号系统


Java+Springboot系统系列实现

Java+Springboot+H-ui实现营销管理系统

Java+Springboot+Bootstrap实现网上商城系统

Java+Springboot+Bootstrap+Maven实现景区旅游管理系统


JavaSwing+Mysql系统系列实现

Java+Swing实现斗地主游戏

Java+Swing实现图书管理系统

Java+Swing实现医院管理系统

Java+Swing实现考试管理系统

Java+Swing实现酒店管理系统

Java+Swing实现超市管理系统

Java+Swing实现网上订餐系统

Java+Swing实现电影购票系统

Java+Swing实现仓库管理系统1

Java+Swing实现仓库管理系统2

Java+Swing实现进销存管理系统

Java+Swing实现通讯录管理系统

Java+Swing实现停车场管理系统

Java+Swing实现学生宿舍管理系统

Java+Swing实现学生选课管理系统

Java+Swing实现学生成绩管理系统

Java+Swing实现学校教材管理系统

Java+Swing实现学校教务管理系统

Java+Swing实现企业人事管理系统

Java+Swing实现电子相册管理系统

Java+Swing实现学生信息管理系统1

Java+Swing实现学生信息管理系统2

Java+Swing实现自助取款机(ATM)系统


JavaSwing+Txt系统系列实现

Java+Swing实现超市管理系统-TXT存储信息

Java+Swing实现宠物商店管理系统-TXT存储信息

Java+Swing实现自助取款机(ATM)系统-TXT存储信息


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
19天前
|
监控 JavaScript 前端开发
《理解 WebSocket:Java Web 开发的实时通信技术》
【4月更文挑战第4天】WebSocket是Java Web实时通信的关键技术,提供双向持久连接,实现低延迟、高效率的实时交互。适用于聊天应用、在线游戏、数据监控和即时通知。开发涉及服务器端实现、客户端连接及数据协议定义,注意安全、错误处理、性能和兼容性。随着实时应用需求增加,WebSocket在Java Web开发中的地位将更加重要。
|
22天前
|
Java
学校教师管理系统【JSP+Servlet+JavaBean】(Java课设)
学校教师管理系统【JSP+Servlet+JavaBean】(Java课设)
19 1
|
22天前
|
Java
人事管理系统【JSP+Servlet+JavaBean】(Java课设)
人事管理系统【JSP+Servlet+JavaBean】(Java课设)
18 0
|
25天前
|
缓存 NoSQL 关系型数据库
在Python Web开发过程中:数据库与缓存,MySQL和NoSQL数据库的主要差异是什么?
MySQL是关系型DB,依赖预定义的表格结构,适合结构化数据和复杂查询,但扩展性有限。NoSQL提供灵活的非结构化数据存储(如JSON),无统一查询语言,但能横向扩展,适用于大规模、高并发场景。选择取决于应用需求和扩展策略。
114 1
|
29天前
|
前端开发 Java
java通过commons-fileupload实现多张图片的上传(jsp页面)
java通过commons-fileupload实现多张图片的上传(jsp页面)
16 2
|
Java
java实现遍历树形菜单方法——index.jsp实现
java实现遍历树形菜单方法——index.jsp实现
6 0
|
1月前
|
Java 计算机视觉
java实现人脸识别源码【含测试效果图】——前台页面层(login.jsp)
java实现人脸识别源码【含测试效果图】——前台页面层(login.jsp)
13 0
|
8天前
|
Web App开发 Java 应用服务中间件
【Java Web】在 IDEA 中部署 Tomcat
【Java Web】在 IDEA 中部署 Tomcat
20 0
|
8天前
|
PHP
web简易开发——通过php与HTML+css+mysql实现用户的登录,注册
web简易开发——通过php与HTML+css+mysql实现用户的登录,注册
|
17天前
|
安全 前端开发 Java
Java Web开发知识点学习总结
Java Web开发涉及Java基础、Servlet、JSP、数据库操作(SQL+JDBC)、MVC设计模式、Spring框架、Hibernate ORM、Web服务(SOAP&RESTful)、安全认证(HTTP Basic/Digest/OAuth)及性能优化(缓存、异步、负载均衡)。
17 3