基于javaweb+mysql的jsp+servlet图书管理系统(java+jsp+servlet+javascript+mysql)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的JSP+Servlet图书管理系统(java+jsp+servlet+javascript+mysql)
项目介绍
本项目为后台管理项目;
管理员角色包含以下功能: 管理员登录,系统设置,管理员管理,办证费用管理,书架管理,读者类型管理,读者管理,图书管理,图书类型管理,图书借阅,图书归还,图书续借,图书查询等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:否;
技术栈
JSP+CSS+JavaScript+mysql+servlet
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中connDB.properties及core/ConnDB.java配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入http://localhost:8080/jsp_online_library_sys/ 登录 注:Tomcat中配置项目路径必须为jsp_online_library_sys,否则会有问题; 管理员账号/密码:admin/111
readerTypeDAO.queryM(readerTypeForm));
request.getRequestDispatcher("readerType_Modify.jsp").forward(request,
response);
}
/***********************
* 修改读者类型信息
*
* @throws IOException
* @throws ServletException
* *
*************************/
private void readerTypeModify(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ReaderTypeForm readerTypeForm = new ReaderTypeForm();
readerTypeForm.setId(Integer.parseInt(request.getParameter("id")));
readerTypeForm.setName(request.getParameter("name"));
readerTypeForm.setNumber(Integer.parseInt(request
.getParameter("number")));
int ret = readerTypeDAO.update(readerTypeForm);
if (ret == 0) {
request.setAttribute("error", "修改读者类型信息失败!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else {
request.getRequestDispatcher("readerType_ok.jsp?para=2").forward(
request, response);
}
}
/***********************
* 删除读者类型信息
*
* @throws IOException
* @throws ServletException
* *
*************************/
private void readerTypeDel(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ReaderTypeForm readerTypeForm = new ReaderTypeForm();
readerTypeForm.setId(Integer.valueOf(request.getParameter("ID")));
int ret = readerTypeDAO.delete(readerTypeForm);
if (ret == 0) {
request.setAttribute("error", "删除读者类型信息失败!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else {
request.getRequestDispatcher("library_modify.jsp").forward(request,
response);
}
}
public class Parameter extends HttpServlet {
ParameterDAO parameterDAO = null;
public Parameter() {
parameterDAO = new ParameterDAO();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String str = request.getParameter("action");
if ("parameterQuery".equals(str)) {
parameterModifyQuery(request, response);
} else if ("parameterModify".equals(str)) {
parameterModify(request, response);
}
}
private void parameterModify(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ParameterForm parameterForm = new ParameterForm();
parameterForm.setId(1);
parameterForm.setCost(Integer.parseInt(request.getParameter("cost")));
parameterForm.setValidity(Integer.parseInt(request
.getParameter("validity")));
int ret = parameterDAO.update(parameterForm);
if (ret == 0) {
request.setAttribute("error", "参数设置信息修改失败!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else {
request.getRequestDispatcher("parameter_ok.jsp?para=2").forward(
request, response);
}
managerForm.setId(Integer.valueOf(request.getParameter("id")));// 获取并设置管理ID号
System.out.print("查询到的id:" + request.getParameter("id"));
request.setAttribute("managerQueryif",
managerDAO.query_update(managerForm));
request.getRequestDispatcher("manager_Modify.jsp").forward(request,
response); // 转到权限设置成功页面
}
// 修改密码时查询
private void pwdQuery(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ManagerForm managerForm = new ManagerForm();
HttpSession session = request.getSession();
String manager = (String) session.getAttribute("manager");
managerForm.setName(manager);
System.out.print("查询到的manager:" + manager);
request.setAttribute("pwdQueryif", managerDAO.query_pwd(managerForm));
request.getRequestDispatcher("pwd_Modify.jsp").forward(request,
response);
}
// 管理员权限设置
private void managerModify(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ManagerForm managerForm = new ManagerForm();
managerForm.setId(Integer.parseInt(request.getParameter("id"))); // 获取并设置管理员ID号
managerForm.setName(request.getParameter("name")); // 获取并设置管理员名称
managerForm.setPwd(request.getParameter("pwd")); // 获取并设置管理员密码
managerForm.setSysset(request.getParameter("sysset") == null ? 0
: Integer.parseInt(request.getParameter("sysset"))); // 获取并设置系统设置权限
managerForm.setReaderset(request.getParameter("readerset") == null ? 0
: Integer.parseInt(request.getParameter("readerset"))); // 获取并设置读者管理权限
managerForm.setBookset(request.getParameter("bookset") == null ? 0
: Integer.parseInt(request.getParameter("bookset"))); // 获取并设置图书管理权限
managerForm
.setBorrowback(request.getParameter("borrowback") == null ? 0
: Integer.parseInt(request.getParameter("borrowback"))); // 获取并设置图书借还权限
managerForm.setSysquery(request.getParameter("sysquery") == null ? 0
: Integer.parseInt(request.getParameter("sysquery"))); // 获取并设置系统查询权限
int ret = managerDAO.update(managerForm); // 调用设置管理员权限的方法
if (ret == 0) {
request.setAttribute("error", "设置管理员权限失败!"); // 保存错误提示信息到error参数中
request.getRequestDispatcher("error.jsp")
.forward(request, response); // 转到错误提示页面
} else {
request.getRequestDispatcher("manager_ok.jsp?para=2").forward(
request, response);// 转到权限设置成功页面
}
}
// 删除管理员信息
private void managerDel(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else if ("readerTypeAdd".equals(action)) {
readerTypeAdd(request, response);
} else if ("readerTypeQuery".equals(action)) {
readerTypeQuery(request, response);
} else if ("readerTypeModifyQuery".equals(action)) {
readerTypeModifyQuery(request, response);
} else if ("readerTypeModify".equals(action)) {
readerTypeModify(request, response);
} else if ("readerTypeDel".equals(action)) {
readerTypeDel(request, response);
}
}
/***********************
* 添加读者类型信息
*
* @throws IOException
* @throws ServletException
* *
*************************/
private void readerTypeAdd(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ReaderTypeForm readerTypeForm = new ReaderTypeForm();
System.out.println("servlet:" + request.getParameter("name"));
readerTypeForm.setName(request.getParameter("name"));
readerTypeForm.setNumber(Integer.parseInt(request
.getParameter("number")));
int a = readerTypeDAO.insert(readerTypeForm);
if (a == 0) {
request.setAttribute("error", "读者类型信息添加失败!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else if (a == 2) {
request.setAttribute("error", "该读者类型信息已经添加!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else {
request.getRequestDispatcher("readerType_ok.jsp?para=1").forward(
request, response);
}
}
/***********************
* 查询全部读者类型信息
*
* @throws IOException
request.setAttribute("pwdQueryif", managerDAO.query_pwd(managerForm));
request.getRequestDispatcher("pwd_Modify.jsp").forward(request,
response);
}
// 管理员权限设置
private void managerModify(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ManagerForm managerForm = new ManagerForm();
managerForm.setId(Integer.parseInt(request.getParameter("id"))); // 获取并设置管理员ID号
managerForm.setName(request.getParameter("name")); // 获取并设置管理员名称
managerForm.setPwd(request.getParameter("pwd")); // 获取并设置管理员密码
managerForm.setSysset(request.getParameter("sysset") == null ? 0
: Integer.parseInt(request.getParameter("sysset"))); // 获取并设置系统设置权限
managerForm.setReaderset(request.getParameter("readerset") == null ? 0
: Integer.parseInt(request.getParameter("readerset"))); // 获取并设置读者管理权限
managerForm.setBookset(request.getParameter("bookset") == null ? 0
: Integer.parseInt(request.getParameter("bookset"))); // 获取并设置图书管理权限
managerForm
.setBorrowback(request.getParameter("borrowback") == null ? 0
: Integer.parseInt(request.getParameter("borrowback"))); // 获取并设置图书借还权限
managerForm.setSysquery(request.getParameter("sysquery") == null ? 0
: Integer.parseInt(request.getParameter("sysquery"))); // 获取并设置系统查询权限
int ret = managerDAO.update(managerForm); // 调用设置管理员权限的方法
if (ret == 0) {
request.setAttribute("error", "设置管理员权限失败!"); // 保存错误提示信息到error参数中
request.getRequestDispatcher("error.jsp")
.forward(request, response); // 转到错误提示页面
} else {
request.getRequestDispatcher("manager_ok.jsp?para=2").forward(
request, response);// 转到权限设置成功页面
}
}
// 删除管理员信息
private void managerDel(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ManagerForm managerForm = new ManagerForm();
managerForm.setId(Integer.valueOf(request.getParameter("id"))); // 获取并设置管理员ID号
int ret = managerDAO.delete(managerForm); // 调用删除信息的方法delete()
if (ret == 0) {
request.setAttribute("error", "删除管理员信息失败!"); // 保存错误提示信息到error参数中
request.getRequestDispatcher("error.jsp")
.forward(request, response); // 转到错误提示页面
} else {
request.getRequestDispatcher("manager_ok.jsp?para=3").forward(
request, response); // 转到删除管理员信息成功页面
}
}
// 修改管理员密码
private void modifypwd(HttpServletRequest request,
public class BookCase extends HttpServlet {
private BookCaseDAO bookCaseDAO = null;
public BookCase() {
this.bookCaseDAO = new BookCaseDAO();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = request.getParameter("action");
System.out.println("\nbookCase*********************action=" + action);
if (action == null || "".equals(action)) {
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else if ("bookCaseAdd".equals(action)) {
bookCaseAdd(request, response);
} else if ("bookCaseQuery".equals(action)) {
bookCaseQuery(request, response);
} else if ("bookCaseModifyQuery".equals(action)) {
bookCaseModifyQuery(request, response);
} else if ("bookCaseModify".equals(action)) {
bookCaseModify(request, response);
} else if ("bookCaseDel".equals(action)) {
bookCaseDel(request, response);
}
}
/*********************** 添加书架信息 **************************/
private void bookCaseAdd(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
BookCaseForm bookCaseForm = new BookCaseForm();
bookCaseForm.setName(request.getParameter("name"));
int a = bookCaseDAO.insert(bookCaseForm);
}
}
// 查询管理员信息
private void managerQuery(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String str = null;
request.setAttribute("managerQuery", managerDAO.query(str));
request.getRequestDispatcher("manager.jsp").forward(request, response);
}
// 添加管理员信息
private void managerAdd(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ManagerForm managerForm = new ManagerForm();
managerForm.setName(request.getParameter("name")); // 获取设置管理员名称
managerForm.setPwd(request.getParameter("pwd")); // 获取并设置密码
int ret = managerDAO.insert(managerForm); // 调用添加管理员信息
if (ret == 1) {
request.getRequestDispatcher("manager_ok.jsp?para=1").forward(
request, response); // 转到管理员信息添加成功页面
} else if (ret == 2) {
request.setAttribute("error", "该管理员信息已经添加!"); // 将错误信息保存到error参数中
request.getRequestDispatcher("error.jsp")
.forward(request, response); // 转到错误提示页面
} else {
request.setAttribute("error", "添加管理员信息失败!"); // 将错误信息保存到error参数中
request.getRequestDispatcher("error.jsp")
.forward(request, response); // 转到错误提示页面
}
}
// 查询修改管理员信息
private void managerModifyQuery(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ManagerForm managerForm = new ManagerForm();
managerForm.setId(Integer.valueOf(request.getParameter("id")));// 获取并设置管理ID号
System.out.print("查询到的id:" + request.getParameter("id"));
request.setAttribute("managerQueryif",
managerDAO.query_update(managerForm));
request.getRequestDispatcher("manager_Modify.jsp").forward(request,
response); // 转到权限设置成功页面
}
request.setAttribute("borrowinfo",
borrowDAO.borrowinfo(request.getParameter("barcode")));
if (request.getParameter("id") != null) {
int id = Integer.parseInt(request.getParameter("id"));
if (id > 0) { // 执行继借操作
int ret = borrowDAO.renew(id);
if (ret == 0) {
request.setAttribute("error", "图书继借失败!");
request.getRequestDispatcher("error.jsp").forward(request,
response);
} else {
request.setAttribute("bar", request.getParameter("barcode"));
request.getRequestDispatcher("bookRenew_ok.jsp").forward(
request, response);
}
}
} else {
request.getRequestDispatcher("bookRenew.jsp").forward(request,
response);
}
}
/********************* 图书归还 ***********************/
private void bookback(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 查询读者信息
readerForm.setBarcode(request.getParameter("barcode"));
ReaderForm reader = (ReaderForm) readerDAO.queryM(readerForm);
request.setAttribute("readerinfo", reader);
// 查询读者的借阅信息
request.setAttribute("borrowinfo",
borrowDAO.borrowinfo(request.getParameter("barcode")));
if (request.getParameter("id") != null) {
int id = Integer.parseInt(request.getParameter("id"));
String operator = request.getParameter("operator");
if (id > 0) { // 执行归还操作
int ret = borrowDAO.back(id, operator);
if (ret == 0) {
request.setAttribute("error", "图书归还失败!");
request.getRequestDispatcher("error.jsp").forward(request,
response);
} else {
request.setAttribute("bar", request.getParameter("barcode"));
request.getRequestDispatcher("bookBack_ok.jsp").forward(
request, response);
}
}
} else {
request.getRequestDispatcher("bookBack.jsp").forward(request,
response);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
/*********************** 添加图书信息 **************************/
private void bookAdd(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
BookForm bookForm = new BookForm();
bookForm.setBarcode(request.getParameter("barcode"));
bookForm.setBookName(request.getParameter("bookName"));
bookForm.setTypeId(Integer.parseInt(request.getParameter("typeId")));
bookForm.setAuthor(request.getParameter("author"));
bookForm.setTranslator(request.getParameter("translator"));
bookForm.setIsbn(request.getParameter("isbn"));
bookForm.setPrice(Float.valueOf(request.getParameter("price")));
bookForm.setPage(request.getParameter("page") == "" ? 0 : Integer
.parseInt(request.getParameter("page")));
bookForm.setBookcaseid(Integer.parseInt(request
.getParameter("bookcaseid")));
// 获取系统日期
Date date1 = new Date();
java.sql.Date date = new java.sql.Date(date1.getTime());
bookForm.setInTime(date.toString());
bookForm.setOperator(request.getParameter("operator"));
int a = bookDAO.insert(bookForm);
if (a == 1) {
request.getRequestDispatcher("book_ok.jsp?para=1").forward(request,
response);
} else if (a == 2) {
request.setAttribute("error", "该图书信息已经添加!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else {
request.setAttribute("error", "图书信息添加失败!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
}
}
/*********************** 查询全部图书信息 **************************/
private void bookQuery(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String str = null;
request.setAttribute("book", bookDAO.query(str)); // 将查询结果保存到book中
request.getRequestDispatcher("book.jsp").forward(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
public class BookCase extends HttpServlet {
private BookCaseDAO bookCaseDAO = null;
public BookCase() {
this.bookCaseDAO = new BookCaseDAO();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = request.getParameter("action");
System.out.println("\nbookCase*********************action=" + action);
if (action == null || "".equals(action)) {
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else if ("bookCaseAdd".equals(action)) {
bookCaseAdd(request, response);
} else if ("bookCaseQuery".equals(action)) {
bookCaseQuery(request, response);
} else if ("bookCaseModifyQuery".equals(action)) {
bookCaseModifyQuery(request, response);
} else if ("bookCaseModify".equals(action)) {
bookCaseModify(request, response);
} else if ("bookCaseDel".equals(action)) {
bookCaseDel(request, response);
}
}
readerTypeForm.setId(Integer.valueOf(request.getParameter("ID")));
int ret = readerTypeDAO.delete(readerTypeForm);
if (ret == 0) {
request.setAttribute("error", "删除读者类型信息失败!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else {
request.getRequestDispatcher("readerType_ok.jsp?para=3").forward(
request, response);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
public class BookType extends HttpServlet {
private BookTypeDAO bookTypeDAO = null;
public BookType() {
this.bookTypeDAO = new BookTypeDAO();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = request.getParameter("action");
System.out.println("\nbookType*********************action=" + action);
if (action == null || "".equals(action)) {
request.setAttribute("error", "您的操作有误!");
response);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
public class Borrow extends HttpServlet {
/****************** 在构造方法中实例化Borrow类中应用的持久层类的对象 **************************/
private BorrowDAO borrowDAO = null;
private ReaderDAO readerDAO = null;
private BookDAO bookDAO = null;
private ReaderForm readerForm = new ReaderForm();
public Borrow() {
this.borrowDAO = new BorrowDAO();
this.readerDAO = new ReaderDAO();
this.bookDAO = new BookDAO();
}
/******************************************************************************************/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = request.getParameter("action");
if (action == null || "".equals(action)) {
request.setAttribute("error", "您的操作有误!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else if ("bookBorrowSort".equals(action)) {
bookBorrowSort(request, response);
} else if ("bookborrow".equals(action)) {
bookborrow(request, response); // 图书借阅
} else if ("bookrenew".equals(action)) {
bookrenew(request, response); // 图书续借
} else if ("bookback".equals(action)) {
bookback(request, response); // 图书归还
} else if ("Bremind".equals(action)) {
bremind(request, response); // 借阅到期提醒
int ret = libraryDAO.update(libraryForm);
if (ret == 0) {
request.setAttribute("error", "图书馆信息修改失败!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else {
request.getRequestDispatcher("library_ok.jsp?para=2").forward(
request, response);
}
}
private void libraryModifyQuery(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("libraryModifyif", libraryDAO.query());
request.getRequestDispatcher("library_modify.jsp").forward(request,
response);
}
}
public class Parameter extends HttpServlet {
ParameterDAO parameterDAO = null;
public Parameter() {
parameterDAO = new ParameterDAO();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String str = request.getParameter("action");
if ("parameterQuery".equals(str)) {
parameterModifyQuery(request, response);
private void bookTypeAdd(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
BookTypeForm bookTypeForm = new BookTypeForm();
bookTypeForm.setTypeName(request.getParameter("typeName"));
bookTypeForm.setDays(Integer.parseInt(request.getParameter("days")));
int a = bookTypeDAO.insert(bookTypeForm);
if (a == 0) {
request.setAttribute("error", "图书类型信息添加失败!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else if (a == 2) {
request.setAttribute("error", "该图书类型信息已经添加!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else {
request.getRequestDispatcher("bookType_ok.jsp?para=1").forward(
request, response);
}
}
/*********************** 查询全部图书类型信息 **************************/
private void bookTypeQuery(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String str = null;
request.setAttribute("bookType", bookTypeDAO.query(str));
request.getRequestDispatcher("bookType.jsp").forward(request, response);
}
/*********************** 查询修改图书类型信息 **************************/
private void bookTypeModifyQuery(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
BookTypeForm bookTypeForm = new BookTypeForm();
bookTypeForm.setId(Integer.valueOf(request.getParameter("ID")));
request.setAttribute("bookTypeQueryif",
bookTypeDAO.queryM(bookTypeForm));
request.getRequestDispatcher("bookType_Modify.jsp").forward(request,
response);
}
/*********************** 修改图书类型信息 **************************/
private void bookTypeModify(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
BookTypeForm bookTypeForm = new BookTypeForm();
bookTypeForm.setId(Integer.parseInt(request.getParameter("id")));
bookTypeForm.setTypeName(request.getParameter("typeName"));
bookTypeForm.setDays(Integer.parseInt(request.getParameter("days")));
int ret = bookTypeDAO.update(bookTypeForm);
if (ret == 0) {
request.setAttribute("error", "修改图书类型信息失败!");
request.getRequestDispatcher("error.jsp")
}
}
/*********************** 添加图书信息 **************************/
private void bookAdd(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
BookForm bookForm = new BookForm();
bookForm.setBarcode(request.getParameter("barcode"));
bookForm.setBookName(request.getParameter("bookName"));
bookForm.setTypeId(Integer.parseInt(request.getParameter("typeId")));
bookForm.setAuthor(request.getParameter("author"));
bookForm.setTranslator(request.getParameter("translator"));
bookForm.setIsbn(request.getParameter("isbn"));
bookForm.setPrice(Float.valueOf(request.getParameter("price")));
bookForm.setPage(request.getParameter("page") == "" ? 0 : Integer
.parseInt(request.getParameter("page")));
bookForm.setBookcaseid(Integer.parseInt(request
.getParameter("bookcaseid")));
// 获取系统日期
Date date1 = new Date();
java.sql.Date date = new java.sql.Date(date1.getTime());
bookForm.setInTime(date.toString());
bookForm.setOperator(request.getParameter("operator"));
int a = bookDAO.insert(bookForm);
if (a == 1) {
request.getRequestDispatcher("book_ok.jsp?para=1").forward(request,
response);
} else if (a == 2) {
request.setAttribute("error", "该图书信息已经添加!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else {
request.setAttribute("error", "图书信息添加失败!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
}
}
/*********************** 查询全部图书信息 **************************/
private void bookQuery(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
} else if ("managerDel".equals(action)) {
managerDel(request, response);// 删除管理员
} else if ("querypwd".equals(action)) {
pwdQuery(request, response);// 更改口令时应用的查询
} else if ("modifypwd".equals(action)) {
modifypwd(request, response); // 更改口令
}
}
// 管理员身份验证
public void managerLogin(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ManagerForm managerForm = new ManagerForm();// 实例化managerForm类
managerForm.setName(request.getParameter("name"));// 获取管理员名称并设置name属性
managerForm.setPwd(request.getParameter("pwd"));// 获取管理员密码并设置pwd属性
int ret = managerDAO.checkManager(managerForm);// 调用ManagerDAO类的checkManager()方法
if (ret == 1) {
/********** 将登录到系统的管理员名称保存到session中 ***********************************/
HttpSession session = request.getSession();
session.setAttribute("manager", managerForm.getName());
session.setAttribute("power", managerForm.getName());//将该管理员名字存入session,用于查询权限所用
/***********************************************************************************/
request.getRequestDispatcher("index.jsp").forward(request, response);// 转到系统主界面
} else {
request.setAttribute("error", "您输入的管理员名称或密码错误!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);// 转到错误提示页
}
}
// 查询管理员信息
private void managerQuery(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String str = null;
request.setAttribute("managerQuery", managerDAO.query(str));
request.getRequestDispatcher("manager.jsp").forward(request, response);
}
// 添加管理员信息
private void managerAdd(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ManagerForm managerForm = new ManagerForm();
managerForm.setName(request.getParameter("name")); // 获取设置管理员名称
managerForm.setPwd(request.getParameter("pwd")); // 获取并设置密码
int ret = managerDAO.insert(managerForm); // 调用添加管理员信息
if (ret == 1) {
/*********************** 查询全部图书信息 **************************/
private void bookQuery(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String str = null;
request.setAttribute("book", bookDAO.query(str)); // 将查询结果保存到book中
request.getRequestDispatcher("book.jsp").forward(request, response);
}
/*********************** 条件查询图书信息 **************************/
private void bookifQuery(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String str = null;
if (request.getParameter("f") != null) {
str = request.getParameter("f") + " like '%"
+ request.getParameter("key") + "%";
}
request.setAttribute("ifbook", bookDAO.query(str));
System.out.print("条件查询图书信息时的str:" + str);
request.getRequestDispatcher("bookQuery.jsp")
.forward(request, response);
}
/*********************** 查询修改图书信息 **************************/
private void bookModifyQuery(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
BookForm bookForm = new BookForm();
System.out.println("查询修改图书信息:" + request.getParameter("ID"));
bookForm.setId(Integer.valueOf(request.getParameter("ID")));
request.setAttribute("bookQueryif", bookDAO.queryM(bookForm));
request.getRequestDispatcher("book_Modify.jsp").forward(request,
response);
}
/*********************** 查询图书详细信息 **************************/
private void bookDetail(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
BookForm bookForm = new BookForm();
bookForm.setId(Integer.valueOf(request.getParameter("ID")));
request.setAttribute("bookDetail", bookDAO.queryM(bookForm));
request.getRequestDispatcher("book_detail.jsp").forward(request,
response);
}
/*********************** 修改图书信息 **************************/
private void bookModify(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
BookForm bookForm = new BookForm(); // 实例化BookForm类