图书管理系统(图书录入和管理,借阅管理,图书管理)
立即下载
资源介绍:
在图书管理系统中,通常会包括以下功能和模块:
图书录入和管理:包括添加、修改和删除图书信息,包括编号、书名、作者、出版社、出版日期、价格、数量等。
借阅管理:记录读者借阅的图书信息,包括借阅日期、归还日期等。
图书管理:登陆注册,查看当前书籍信息,如图书编号、图书名称、出版社、出版日期、图书作者、价格、数量(修改)、操作(删除、借阅)
package com.example.demo.servlet;
import com.example.demo.utils.JDBCUtil;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* @author jiang
* @create 2024/5/22
*/
//登录接口
@WebServlet(name = "loginServlet", value = "/login-servlet")
public class LoginServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// super.doPost(req, resp);
try (Connection con = JDBCUtil.getCon();){
String sqlByCou = "select count(1) as num from user where username = ? and password = ?";
String sqlByUser = "select id from user where username = ? and password = ?";
PreparedStatement preparedStatement = con.prepareStatement(sqlByCou);
preparedStatement.setString(1,req.getParameter("username"));
preparedStatement.setString(2,req.getParameter("password"));
ResultSet resultSet = preparedStatement.executeQuery();
// boolean next = resultSet.next();
// int num = resultSet.getInt("num");
while (resultSet.next()){
int num = resultSet.getInt("num");
if (num != 1){
req.setAttribute("prompt","账号密码错误");
req.getRequestDispatcher("/login.jsp").forward(req,resp);
}else {
// 存储当前登陆人信息
PreparedStatement preparedStatementByUser = con.prepareStatement(sqlByUser);
preparedStatementByUser.setString(1,req.getParameter("username"));
preparedStatementByUser.setString(2,req.getParameter("password"));
ResultSet resultSet1 = preparedStatementByUser.executeQuery();
resultSet1.next();
getServletContext().setAttribute("userId",resultSet1.getInt("id"));
System.out.println(getServletContext().getAttribute("userId"));
resp.sendRedirect(req.getContextPath()+"/bookList");
// req.getRequestDispatcher("/bookList").forward(req,resp);
}
}
// if (resul)
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
资源文件列表:
图书管理系统.zip 大约有162个文件