/**
- @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
- @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//doGet(request, response);
request.setCharacterEncoding(“UTF-8”);
response.setContentType(“text/html;charset=UTF-8”);
//因为在管理员界面和读者界面都有查找功能,为了将查找的结果返回正确的页面,设置了tip,tip=1表示管理员界面
int tip = Integer.parseInt(request.getParameter(“tip”));
String name = request.getParameter(“name”);
BookDao bookdao = new BookDao();
ArrayList data = bookdao.getLikeList(name);
//将获取的结果存入请求中
request.setAttribute(“data”, data);
String url = “”;
//转发不同的界面
if (tip == 1) {
url = response.encodeURL(“/books/admin/admin_books.jsp”);
} else {
url = response.encodeURL(“/books/user/select.jsp”);
}
//将请求转发
request.getRequestDispatcher(url).forward(request, response);
}
}
5.2 用户端–借阅信息模块
当普通用户借阅完图书,会在该模块自动生成借阅信息,如借阅日期,归还日期,也可在该模块进行还书,如下图所示。
其中,还书功能的Servlet代码如下:
package com.cya.controller;
import java.io.IOException;
import java.io.PrintWriter;
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 javax.servlet.http.HttpSession;
import com.cya.pojo.Admin;
import com.cya.dao.AdminDao;
import com.cya.dao.BookDao;
/**
- Servlet implementation class borrowServlet
*/
@WebServlet(“/borrowServlet”)
public class borrowServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
- @see HttpServlet#HttpServlet()
*/
public borrowServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
- @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
//设置编码类型
request.setCharacterEncoding(“UTF-8”);
response.setContentType(“text/html;charset=UTF-8”);
BookDao bookdao = new BookDao();
//为了区分借书和还书的功能,设置tip,tip为1,表示借书
int tip = Integer.parseInt(request.getParameter(“tip”));
if (tip == 1) {
//获取图书id
int bid = Integer.parseInt(request.getParameter(“bid”));
HttpSession session = request.getSession();
Admin admin = new Admin();
String status=request.getParameter(“status”);
String id=“”;
if(status.equals(“user”)) {
//获取到存入session的读者id
id = (String) session.getAttribute(“uid”);
}
else {
//获取到存入session的aid读者id
id = (String) session.getAttribute(“aid”);
}
AdminDao admindao = new AdminDao();
//通过aid获取到读者的信息
admin = admindao.get_AidInfo2(id);
//将借阅记录存入数据表
bookdao.borrowBook(bid, admin);
response.sendRedirect(“/manage_books/books/user/select.jsp”);
} else {
//还书功能,获取借阅记录的hid
int hid = Integer.parseInt(request.getParameter(“hid”));
/**
- 还书在管理员和读者界面都有,为了区分,设置了show字段,show为1表示读者界面
*/
int show = Integer.parseInt(request.getParameter(“show”));
//调用还书函数,改变status字段
bookdao.borrowBook2(hid);
if (show == 1) {
response.sendRedirect(“/manage_books/books/user/borrow.jsp”);
} else {
response.sendRedirect(“/manage_books/books/admin/admin_borrows.jsp”);
}
}
}
/**
- @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
5.3 管理员端–图书管理模块
管理员可以通过根据图书号 、图书名称,作者名称,出版社等查询图书信息。
管理员登录系统以后,可以进行图书添加操作,这是管理员主要的输入信息部分,填写好各项信息后,单击保存按钮,系统将对这些信息进行处理。界面见下图所示:
除此以外,管理员对已经添加好的图书信息有修改权限。
其中,添加图书功能的代码如下:
package com.cya.controller;
import java.io.IOException;
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 com.cya.dao.BookDao;
/**
- Servlet implementation class AddBookServlet
*/
@WebServlet(“/AddBookServlet”)
public class AddBookServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
- @see HttpServlet#HttpServlet()
*/
public AddBookServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
- @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
- @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// doGet(request, response);
//设置编码类型
request.setCharacterEncoding(“UTF-8”);
response.setContentType(“text/html;charset=UTF-8”);
//获取要添加图书的信息
String card = request.getParameter(“card”);
String name = request.getParameter(“name”);
String type = request.getParameter(“type”);
String autho = request.getParameter(“autho”);
String press = request.getParameter(“press”);
int num = Integer.parseInt(request.getParameter(“num”));
BookDao bookdao = new BookDao();
//调用函数,存入图书
bookdao.addBook(card, name, type, autho, press, num);
response.sendRedirect(“/manage_books/books/admin/admin_books.jsp”);
}
}
5.4 管理员端–图书分类模块
管理员在该界面可以增加、删除、修改图书分类信息,操作效果如图。
![在这里插入图片描述](https://img-blog.csdnimg.cn/
真题解析、进阶学习笔记、最新讲解视频、实战项目源码、学习路线大纲
详情关注公中号【编程进阶路】
20200711143617913.png)
修改图书分类功能的代码如下:
package com.cya.controller;
import java.io.IOException;
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 com.cya.dao.BookDao;
import com.cya.dao.TypeDao;
/**
- Servlet implementation class updateBookTypeServlet
*/
@WebServlet(“/updateBookTypeServlet”)
public class updateBookTypeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
- @see HttpServlet#HttpServlet()
*/
public updateBookTypeServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
- @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
- @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
最后
小编的一位同事在校期间连续三年参加ACM-ICPC竞赛。从参赛开始,原计划每天刷一道算法题,实际上每天有时候不止一题,一年最终完成了 600+:
凭借三年刷题经验,他在校招中很快拿到了各大公司的offer。
入职前,他把他的刷题经验总结成1121页PDF书籍,作为礼物赠送给他的学弟学妹,希望同学们都能在最短时间内掌握校招常见的算法及解题思路。
整本书,我仔细看了一遍,作者非常细心地将常见核心算法题和汇总题拆分为4个章节。
而对于有时间的同学,作者还给出了他结合众多数据结构算法书籍,挑选出的一千多道题的解题思路和方法,以供有需要的同学慢慢研究。
版权归原作者 2401_84437604 所有, 如有侵权,请联系我们删除。