作者主页 央顺技术团队
欢迎点赞 收藏 ⭐留言
文末获取源码联系方式
本项目采用eclipse工具开发,jsp+servlet技术编写,样式采用了layui前端框架,数据库采用的是mysql,navicat开发工具。
系统一共分为2个角色分别是:管理员,学生
二、模块简介
管理员
1、登录
2、修改个人信息
3、图书类型管理
4、图书管理
5、图书借阅管理
6、借阅审批管理
7、图书借阅统计
8、学生管理
9、公告管理
学生
1、登录、注册
2、个人信息修改
3、图书借阅
4、借阅管理
5、借阅统计
6、查看公告
、相关截图
项目结构、数据库结构
登录注册页面
四、相关代码
登录代码
用户通过login.jsp页面填写指定的用户名和密码,点击登录按钮,执行servlet里面的方法,后台校验成功后,返回main.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
Login Page
private void login(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
removeAll(request,response);
String userName = request.getParameter("userName");
String password = request.getParameter("password");
String type = request.getParameter("type");
if(type.equals("1")){
Admin admin = new Admin();
admin.setUserName(userName);
admin.setPwd(password);
Admin admin1 = ls.selectAdmin(admin);
try {
if (admin1 == null){
request.setAttribute("message", "管理员用户不存在或者密码错误");
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
}else {
request.getSession().setAttribute("admin",admin1);
request.getSession().setAttribute("flag",1);
request.getRequestDispatcher("/WEB-INF/views/main.jsp").forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();
}
}else if(type.equals("2")){
Student student = new Student();
student.setStno(userName);
student.setPwd(password);
Student student1 = ls.selectStudent(student);
try {
if (student1 == null){
request.setAttribute("message", "学号不存在或者密码错误");
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
}else {
request.getSession().setAttribute("student",student1);
request.getSession().setAttribute("flag",2);
request.getRequestDispatcher("/WEB-INF/views/main.jsp").forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();
}
}else{
request.setAttribute("message", "工作人员手机号不存在或者密码错误");
try {
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
注册代码
学生初始化注册自己的账号,填写form表单,提价后,后台进行插入的操作,注册成功后跳转登录页面
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
Login Page
/**
* 新增学生信息
* @param request
* @param response
*/
private void addStudent(HttpServletRequest request,
HttpServletResponse response) {
String te = request.getParameter("te");
String name = request.getParameter("name");
String sex = request.getParameter("sex");
String classes = request.getParameter("classes");
String time = request.getParameter("time");
String xy = request.getParameter("xy");
String phone = request.getParameter("phone");
String pwd = request.getParameter("pwd");
String stno = request.getParameter("stno");
Student stu = new Student();
stu.setClasses(classes);
stu.setName(name);
stu.setPhone(phone);
stu.setPwd(pwd);
stu.setSex(sex);
stu.setState("1");
stu.setStno(stno);
stu.setTime(time);
stu.setXy(xy);
Student student = ss.selectStudentByPhone(phone);
Student student1 = ss.selectStudentByStuNo(stno);
if(te == null || te.equals("")){
if(student != null){
request.setAttribute("message", "电话号码重复!");
try {
request.getRequestDispatcher("/WEB-INF/views/student/addStudent.jsp").forward(request,response);
} catch (Exception e) {
e.printStackTrace();
}
}else if(student1 != null){
request.setAttribute("message", "学号重复!");
try {
request.getRequestDispatcher("/WEB-INF/views/student/addStudent.jsp").forward(request,response);
} catch (Exception e) {
e.printStackTrace();
}
}else{
try {
ss.saveStudent(stu);
response.sendRedirect(request.getContextPath()+"/StudentServlet?action=studentList");
} catch (Exception e) {
e.printStackTrace();
}
}
}else{
if(student != null){
request.setAttribute("message", "电话号码重复!");
try {
request.getRequestDispatcher("/WEB-INF/views/register.jsp").forward(request,response);
} catch (Exception e) {
e.printStackTrace();
}
}else if(student1 != null){
request.setAttribute("message", "学号重复!");
try {
request.getRequestDispatcher("/WEB-INF/views/register.jsp").forward(request,response);
} catch (Exception e) {
e.printStackTrace();
}
}else{
try {
ss.saveStudent(stu);
response.sendRedirect(request.getContextPath()+"/LoginServlet?action=toLogin");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
学生列表代码
后台分页查询所有学生的信息,返回到studentList.jsp中,进行遍历展示
/**
* 分页查询学生
* @param request
* @param response
*/
private void studentList(HttpServletRequest request,
HttpServletResponse response) {
String p=request.getParameter("p");//接收页码
int pageSize=4;//每页显示5条
int pageNum=1; //默认第一页
if(p!=null){
pageNum= Integer.parseInt(p);
}
//调用分页查询
List list=ss.getstudentListPage(pageNum,pageSize);
//携带参数到页面
int nums=ss.queryStudentCount(); //查询总数
//计算总页数
int totalPage=(nums%pageSize==0)? (nums/pageSize):(nums/pageSize+1);
request.setAttribute("cp",pageNum); //当前页
request.setAttribute("tp",totalPage); //总页数
try {
request.removeAttribute("msg");
request.setAttribute("list" ,list);
request.getRequestDispatcher("/WEB-INF/views/student/studentList.jsp").forward(request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>