赞
踩
软件环境
OS:Windows10
IDEA:2017.3.5
Java:jdk1.8
Mysql:8.0.13
Bootstrap:bootstrap.min.css
Juqery:jquery-ui-1.10.4.custom.min.css
Tomcat:9.0.52
Browser:Microsoft Edge
该图书管理系统实现了学生的成绩管理。学生实现了登录登出功能,查看成绩功能。教师端实现了注册登录,对学生成绩和信息进行增删改查的功能,实现Execl导出成绩功能。
数据库有三张表:一张是学生表(student),一张是教师表(teacher),一张是成绩表(score)。
登录页面
注册页面
教师端学生成绩管理
学生端
退出页面
1.后端实现
Score
package vo; public class Score { private String id; private String database; private String android; private String jsp; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getDatabase() { return database; } public void setDatabase(String database) { this.database = database; } public String getAndroid() { return android; } public void setAndroid(String android) { this.android = android; } public String getJsp() { return jsp; } public void setJsp(String jsp) { this.jsp = jsp; } }
Student
package vo; public class Student { private String id; private String password; private String name; private String sex; private String school_date; private String major; private String email; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getSchool_date() { return school_date; } public void setSchool_date(String school_date) { this.school_date = school_date; } public String getMajor() { return major; } public void setMajor(String major) { this.major = major; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } }
Teacher
package vo; public class Teacher { private String id; private String password; private String email; private String name; private String sex; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } }
ScoreDao
package dao; import vo.Score; import vo.Student; import java.sql.*; import java.util.ArrayList; public class ScoreDao { private Connection conn = null; static String driver = "com.mysql.jdbc.Driver"; static String url = "jdbc:mysql:///pby?serverTimezone=GMT%2B8"; static String user = "root"; static String password="root"; /** * 录入成绩 * @param id * @return * @throws Exception */ /** * 初始化数据库连接 * * @throws Exception */ private void initConnection() throws Exception { Class.forName(driver); conn = DriverManager.getConnection(url, user, password); } /** * 关闭连接 * * @throws Exception */ private void closeConnection() throws Exception { conn.close(); } public boolean insertScore(String id) throws Exception{ initConnection(); String sql = "insert into score(id) values(?)"; PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, id); int i = ps.executeUpdate(); closeConnection(); return i == 1; } /** * 删除成绩 * @param id * @return * @throws Exception */ public boolean deleteScore(String id) throws Exception{ initConnection(); Statement stat = conn.createStatement(); String sql = "delete from score where id='"+id+"'"; int i = stat.executeUpdate(sql); closeConnection(); return i==1; } /** * 更新成绩 * @param id * @param database * @param android * @param jsp * @throws Exception */ public void updateScoreInfo(String id, String database, String android, String jsp) throws Exception{ initConnection(); String sql = "update score set dat=?, android=?, jsp=? where id=?"; PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, database); ps.setString(2, android); ps.setString(3, jsp); ps.setString(4, id); ps.executeUpdate(); closeConnection(); } /** * 以id查找信息 * @param id * @return * @throws Exception */ public Score findWithId(String id) throws Exception{ initConnection(); Statement stat = conn.createStatement(); String sql = "select * from score where id = '" + id + "'"; ResultSet rs = stat.executeQuery(sql); Score stu = getScore(rs); closeConnection(); return stu; } /** * 分页查询 * @param page * @param size * @return * @throws Exception */ public ArrayList<Score> getOnePage(int page, int size) throws Exception{ ArrayList<Score> al = new ArrayList<>(); initConnection(); String sql = "SELECT * FROM score limit ?, ?"; PreparedStatement ps = conn.prepareStatement(sql); ps.setInt(1, (page-1)*size); ps.setInt(2, size); ResultSet rs = ps.executeQuery(); // getMoreScore(al, rs); closeConnection(); return al; } /** * 查询总数 * @return * @throws Exception */ public int getScoreCount() throws Exception{ initConnection(); String sql = "select count(*) from score"; Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery(sql); rs.next(); int count = rs.getInt(1); closeConnection(); return count; } /** * 获取成绩 * @param rs * @return * @throws SQLException */ private Score getScore(ResultSet rs) throws SQLException { Score stu = null; if (rs.next()){ stu = new Score(); stu.setId(rs.getString("id")); stu.setDatabase(rs.getString("dat")); stu.setAndroid(rs.getString("android")); stu.setJsp(rs.getString("jsp")); } return stu; } /** * 获取所有成绩 * @param al * @param rs * @throws SQLException */ private void getMoreStudent(ArrayList<Student> al, ResultSet rs) throws SQLException { while (rs.next()){ Student stu = new Student(); stu.setId(rs.getString("id")); stu.setPassword(rs.getString("password")); stu.setName(rs.getString("name")); stu.setSex(rs.getString("sex")); stu.setSchool_date(rs.getString("school_date")); stu.setMajor(rs.getString("major")); stu.setEmail(rs.getString("email")); al.add(stu); } } }
StudentDao
package dao; import vo.Student; import java.sql.*; import java.util.ArrayList; public class StudentDao { private Connection conn = null; // 定义数据常量 static String driver = "com.mysql.jdbc.Driver"; static String url = "jdbc:mysql:///pby?serverTimezone=GMT%2B8"; static String user = "root"; static String password = "root"; /** * 初始化数据库连接 * * @throws Exception */ private void initConnection() throws Exception { Class.forName(driver); conn = DriverManager.getConnection(url, user, password); } /** * 关闭连接 * * @throws Exception */ private void closeConnection() throws Exception { conn.close(); } /** * 验证学生账号和密码 * * @param user * @param password * @return * @throws Exception */ public Student checkAccount(String user, String password) throws Exception { initConnection(); Statement stat = conn.createStatement(); String sql = "select * from student where id = '" + user + "' and password = '" + password + "'"; ResultSet rs = stat.executeQuery(sql); Student stu = getStudent(rs); closeConnection(); return stu; } /** * 使用学生id来查找学生信息 * * @param id * @return * @throws Exception */ public Student findWithId(String id) throws Exception { initConnection(); Statement stat = conn.createStatement(); String sql = "select * from student where id = '" + id + "'"; ResultSet rs = stat.executeQuery(sql); Student stu = getStudent(rs); closeConnection(); return stu; } /** * 使用学生姓名查找学生信息 * * @param name * @return * @throws Exception */ public ArrayList<Student> findWithName(String name) throws Exception { ArrayList<Student> al = new ArrayList<>(); initConnection(); Statement stat = conn.createStatement(); String sql = "select * from student where name = '" + name + "'"; ResultSet rs = stat.executeQuery(sql); getMoreStudent(al, rs); closeConnection(); return al; } /** * 添加学生信息 * * @param id * @param name * @param sex * @param school_date * @param major * @return * @throws Exception */ public boolean insertStudent(String id, String name, String sex, String school_date, String major) throws Exception { initConnection(); String sql = "insert into student(id, name, sex, school_date, major) values(?, ?, ?, ?, ?)"; PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, id); ps.setString(2, name); ps.setString(3, sex); ps.setString(4, school_date); ps.setString(5, major); int i = ps.executeUpdate(); closeConnection(); return i == 1; } /** * 删除学生信息 * * @param id * @return * @throws Exception */ public boolean deleteStudent(String id) throws Exception { initConnection(); Statement stat = conn.createStatement(); String sql = "delete from student where id='" + id + "'"; int i = stat.executeUpdate(sql); closeConnection(); return i == 1; } /** * 获取每页的信息 * * @param page * @param size * @return * @throws Exception */ public ArrayList<Student> getOnePage(int page, int size) throws Exception { ArrayList<Student> al = new ArrayList<>(); initConnection(); String sql = "SELECT * FROM student limit ?, ?"; PreparedStatement ps = conn.prepareStatement(sql); ps.setInt(1, (page - 1) * size); ps.setInt(2, size); ResultSet rs = ps.executeQuery(); getMoreStudent(al, rs); closeConnection(); return al; } /** * 获取学生总数 * * @return * @throws Exception */ public int getStudentCount() throws Exception { initConnection(); String sql = "select count(*) from student"; Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery(sql); rs.next(); int count = rs.getInt(1); closeConnection(); return count; } /** * 更新学生信息 * * @param id * @param name * @param sex * @param major * @throws Exception */ public void updateStudentInfo(String id, String name, String sex, String major) throws Exception { initConnection(); String sql = "update student set name=?, sex=?, major=? where id=?"; PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, name); ps.setString(2, sex); ps.setString(3, major); ps.setString(4, id); ps.executeUpdate(); closeConnection(); } /** * 更新学生密码和邮件 * * @param id * @param email * @param password * @throws Exception */ public void updateStudentSecurity(String id, String email, String password) throws Exception { initConnection(); String sql = "update student set password=?, email=? where id=?"; PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, password); ps.setString(2, email); ps.setString(3, id); ps.executeUpdate(); closeConnection(); } /** * 获取单个学生信息 * * @param rs * @return * @throws SQLException */ private Student getStudent(ResultSet rs) throws SQLException { Student stu = null; if (rs.next()) { stu = new Student(); stu.setId(rs.getString("id")); stu.setPassword(rs.getString("password")); stu.setName(rs.getString("name")); stu.setSex(rs.getString("sex")); stu.setSchool_date(rs.getString("school_date")); stu.setMajor(rs.getString("major")); stu.setEmail(rs.getString("email")); } return stu; } /** * 获取多个学生信息 * * @param al * @param rs * @throws SQLException */ private void getMoreStudent(ArrayList<Student> al, ResultSet rs) throws SQLException { while (rs.next()) { Student stu = new Student(); stu.setId(rs.getString("id")); stu.setPassword(rs.getString("password")); stu.setName(rs.getString("name")); stu.setSex(rs.getString("sex")); stu.setSchool_date(rs.getString("school_date")); stu.setMajor(rs.getString("major")); stu.setEmail(rs.getString("email")); al.add(stu); } } public static void main(String[] args) throws Exception{ StudentDao studentDao=new StudentDao(); studentDao.initConnection(); System.out.println("数据库连接成功"); studentDao.closeConnection(); } }
TeacherDao
package dao; import vo.Teacher; import java.sql.*; public class TeacherDao { private Connection conn = null; // 定义数据常量 static String driver = "com.mysql.jdbc.Driver"; static String url = "jdbc:mysql:///pby?serverTimezone=GMT%2B8"; static String user = "root"; static String password = "root"; /** * 初始化数据库连接 * * @throws Exception */ private void initConnection() throws Exception { Class.forName(driver); conn = DriverManager.getConnection(url, user, password); } /** * 关闭连接 * * @throws Exception */ private void closeConnection() throws Exception { conn.close(); } public Teacher checkAccount(String id, String password) throws Exception { initConnection(); Statement stat = conn.createStatement(); String sql = "select * from teacher where id = '" + id + "' and password = '" + password + "'"; ResultSet rs = stat.executeQuery(sql); Teacher tea = getTeacher(rs); closeConnection(); return tea; } /** * 使用教师id来查询教师信息 * @param id * @return * @throws Exception */ public Teacher findWithId(String id) throws Exception { initConnection(); Statement stat = conn.createStatement(); String sql = "select * from teacher where id = '" + id + "'"; ResultSet rs = stat.executeQuery(sql); Teacher tea = getTeacher(rs); closeConnection(); return tea; } /** * 添加教师信息 * @param id * @param password * @param email * @return * @throws Exception */ public Teacher insertTeacher(String id, String password, String email) throws Exception { initConnection(); String sql = "insert into teacher(id, password, email) values(?, ?, ?)"; PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, id); ps.setString(2, password); ps.setString(3, email); ps.executeUpdate(); Teacher teacher = findWithId(id); closeConnection(); return teacher; } /** * 更新教师信息 * @param id * @param name * @param sex * @param email * @param password * @return * @throws Exception */ public Teacher updateTeacher(String id, String name, String sex, String email, String password) throws Exception{ initConnection(); String sql = "update teacher set name=?, sex=?, email=?, password=? where id=?"; PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, name); ps.setString(2, sex); ps.setString(3, email); ps.setString(4, password); ps.setString(5, id); ps.executeUpdate(); Teacher teacher = findWithId(id); closeConnection(); return teacher; } /** * 更新教师密码 * @param id * @param password * @throws Exception */ public void updateTeacherPassword(String id, String password) throws Exception{ initConnection(); String sql = "update teacher set password=? where id=?"; PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, password); ps.setString(2, id); ps.executeUpdate(); closeConnection(); } /** * 根据ResultSet来获取教师信息 * @param rs * @return * @throws SQLException */ private Teacher getTeacher(ResultSet rs) throws SQLException { Teacher tea = null; if (rs.next()) { tea = new Teacher(); tea.setId(rs.getString("id")); tea.setPassword(rs.getString("password")); tea.setName(rs.getString("name")); tea.setEmail(rs.getString("email")); tea.setSex(rs.getString("sex")); } return tea; } public static void main(String[] args) throws Exception{ TeacherDao dao = new TeacherDao(); dao.initConnection(); System.out.println("数据库连接成功"); dao.closeConnection(); } }
add_student
package servlet; import dao.ScoreDao; import dao.StudentDao; 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.io.PrintWriter; @WebServlet("/add_student") public class add_student extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request,response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); StudentDao studentDao = new StudentDao(); ScoreDao scoreDao = new ScoreDao(); String id = request.getParameter("id"); String name = request.getParameter("name"); String sex = request.getParameter("sex"); String major = request.getParameter("major"); String school_date = request.getParameter("school_date"); try { // 添加学生信息 studentDao.insertStudent(id, name, sex, school_date, major); // 添加分数信息 scoreDao.insertScore(id); } catch (Exception e){ out.print(e); } response.sendRedirect("one_page_student"); } }
check_login
package servlet; import dao.StudentDao; import dao.TeacherDao; import vo.Student; import vo.Teacher; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.*; import java.io.IOException; import java.io.PrintWriter; @WebServlet("/check_login") public class check_login extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request,response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); HttpSession session = request.getSession(); // 账号 String user = request.getParameter("user"); // 密码 String password = request.getParameter("password"); // 是否记住密码 String remember = request.getParameter("remember"); // 创建Dao层 TeacherDao teacherDao = new TeacherDao(); StudentDao studentDao = new StudentDao(); // 创建实体类 Teacher teacher = null; Student student = null; try { // 判断用户身份 teacher = teacherDao.checkAccount(user, password); student = studentDao.checkAccount(user, password); } catch (Exception e) { out.print(e); } if (teacher != null) { //向session中添加用户信息 session.setAttribute("info", teacher); //检查用户是否需要保持登录状态 if (remember != null) { //发送cookie到客户端 Cookie userCookie = new Cookie("name", user); userCookie.setMaxAge(10); response.addCookie(userCookie); } // 重定向 response.sendRedirect("one_page_student"); } else if (student != null){ //向session中添加用户信息 session.setAttribute("info", student); //检查用户是否需要保持登录状态 if (remember != null) { //发送cookie到客户端 Cookie userCookie = new Cookie("name", user); userCookie.setMaxAge(10); response.addCookie(userCookie); } response.sendRedirect("student/main.jsp"); } else { out.print("<script>alert(\"用户名或密码错误!\");"); } } }
check_register
package servlet; import dao.TeacherDao; import vo.Teacher; 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 java.io.IOException; import java.io.PrintWriter; @WebServlet("/check_register") public class check_register extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8"); String email = request.getParameter("email"); String user = request.getParameter("user"); String password = request.getParameter("password1"); String code = request.getParameter("code"); PrintWriter out = response.getWriter(); HttpSession session = request.getSession(); String randStr = (String) session.getAttribute("randStr"); if (!code.equals(randStr)) { out.print("<script>alert(\"验证码错误!\");location.href = \"register.jsp\";</script>"); } else { TeacherDao teacherDao = new TeacherDao(); Teacher teacher = null; try { teacher = teacherDao.insertTeacher(user, password, email); } catch (Exception e) { out.print(e); } if (teacher != null) { //向session中添加用户信息 session.setAttribute("info", teacher); response.sendRedirect("one_page_student"); } else { out.print("<script>alert(\"此用户已经注册!\");location.href = \"register.jsp\";</script>"); } } } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
delete_student
package servlet; import dao.ScoreDao; import dao.StudentDao; 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.io.PrintWriter; @WebServlet("/delete_student") public class delete_student extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); StudentDao studentDao = new StudentDao(); ScoreDao scoreDao = new ScoreDao(); String id = request.getParameter("id"); try { // 删除学生 studentDao.deleteStudent(id); // 删除成绩 scoreDao.deleteScore(id); response.sendRedirect("one_page_student"); } catch (Exception e){ out.print(e); } } }
exit
package servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet("/exit") public class exit extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //清除cookie, 跳到起始页 Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie c : cookies) { String cookieName = c.getName(); if ("name".equals(cookieName)) { c.setMaxAge(0); response.addCookie(c); } } } response.sendRedirect("index.jsp"); } }
one_page_score
package servlet; import dao.ScoreDao; import vo.Score; 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 java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; @WebServlet("/one_page_score") public class one_page_score extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); HttpSession session = request.getSession(); // 获取传入id的值 String key = request.getParameter("id"); if (key == null) { int currentIndex, count, size = 10; String index = request.getParameter("index"); if (index == null) index = "1"; currentIndex = Integer.parseInt(index); try { ScoreDao scoD = new ScoreDao(); count = scoD.getScoreCount(); ArrayList<Score> stus = scoD.getOnePage(currentIndex, size); int sumIndex = count % size == 0 ? count / size : count / size + 1; session.setAttribute("onePageScore", stus); session.setAttribute("sumScoreIndex", sumIndex); response.sendRedirect("teacher/score.jsp"); } catch (Exception e) { out.print(e); } } else { ScoreDao scoreDao = new ScoreDao(); try { Score score = scoreDao.findWithId(key); ArrayList<Score> scores = new ArrayList<>(); scores.add(score); session.setAttribute("onePageScore", scores); session.setAttribute("sumScoreIndex", 1); response.sendRedirect("teacher/score.jsp"); } catch (Exception e) { out.print(e); } } } }
one_page_student
package servlet; import dao.StudentDao; import vo.Student; 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 java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.regex.Pattern; @WebServlet("/one_page_student ") public class one_page_student extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); HttpSession session = request.getSession(); // 获取key的值 String key = request.getParameter("key"); // 如果key为空或者空字符串 if (key == null || key.equals("")) { int currentIndex, count, size = 10; String index = request.getParameter("index"); if (index == null) index = "1"; // 当前页赋值 currentIndex = Integer.parseInt(index); try { StudentDao sdao = new StudentDao(); // 查询当前页信息 ArrayList<Student> stus = sdao.getOnePage(currentIndex, size); count = sdao.getStudentCount(); // 计算总页数 int sumIndex = count % size == 0 ? count / size : count / size + 1; session.setAttribute("onePageStudent", stus); session.setAttribute("sumIndex", sumIndex); response.sendRedirect("teacher/main.jsp"); } catch (Exception e) { out.print(e); } } else { StudentDao studentDao = new StudentDao(); // 这里前一个"\"是转义字符,后一个是字符串,这个字符串表示数字至少出现一次 String pattern = "^\\d+"; boolean isMatch = Pattern.matches(pattern, key); if (isMatch) { try { // 某个学生的信息 Student student = studentDao.findWithId(key); ArrayList<Student> students = new ArrayList<>(); students.add(student); session.setAttribute("onePageStudent", students); session.setAttribute("sumIndex", 1); response.sendRedirect("teacher/main.jsp"); } catch (Exception e) { out.print(e); } } else { try { ArrayList<Student> stus = studentDao.findWithName(key); session.setAttribute("onePageStudent", stus); session.setAttribute("sumIndex", 1); response.sendRedirect("teacher/main.jsp"); } catch (Exception e) { out.print(e); } } } } }
update_student
package servlet; import dao.StudentDao; 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.io.PrintWriter; @WebServlet("/update_student") public class update_student extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); StudentDao studentDao = new StudentDao(); String stuno = request.getParameter("stuno"); String stuname = request.getParameter("stuname"); String stusex = request.getParameter("stusex"); String stumajor = request.getParameter("stumajor"); try { // 更新学生信息 studentDao.updateStudentInfo(stuno, stuname, stusex, stumajor); } catch (Exception e){ out.print(e); } response.sendRedirect("one_page_student"); } }
update_teacher
package servlet; import dao.TeacherDao; import vo.Teacher; 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 java.io.IOException; import java.io.PrintWriter; @WebServlet("/update_teacher") public class update_teacher extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); HttpSession session = request.getSession(); TeacherDao teacherDao = new TeacherDao(); String uid = request.getParameter("uid"); String name = request.getParameter("name"); String sex = request.getParameter("sex"); String email = request.getParameter("email"); String password = request.getParameter("password"); try { // 更新教师信息 Teacher teacher = teacherDao.updateTeacher(uid, name, sex, email, password); session.setAttribute("info", teacher); out.print("<script>alert(\"保存成功!\");location.href = \"teacher/personal.jsp\";</script>"); } catch (Exception e){ out.print(e); } } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } }
upload_studentImg
package servlet;//import org.omg.CORBA.Request; import com.jspsmart.upload.SmartUpload; import javax.servlet.ServletConfig; 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.io.PrintWriter; @WebServlet("/upload_studentImg") public class upload_studentImg extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); SmartUpload smartUpload = new SmartUpload(); com.jspsmart.upload.Request rq = smartUpload.getRequest(); ServletConfig config = this.getServletConfig(); smartUpload.initialize(config, request, response); try { //上传文件 smartUpload.upload(); String id = rq.getParameter("id"); com.jspsmart.upload.File smartFile = smartUpload.getFiles().getFile(0); smartFile.saveAs("/userImg/"+id+".jpeg"); out.print("<script>alert(\"上传成功!\");window.location.href='student/personal.jsp';</script>"); } catch (Exception e){ out.print(e); } } }
upload_teacherImg
package servlet; import com.jspsmart.upload.File; import com.jspsmart.upload.Request; import com.jspsmart.upload.SmartUpload; import javax.servlet.ServletConfig; 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.io.PrintWriter; @WebServlet("/upload_teacherImg") public class upload_teacherImg extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); SmartUpload smartUpload = new SmartUpload(); Request rq = smartUpload.getRequest(); ServletConfig config = this.getServletConfig(); smartUpload.initialize(config, request, response); try { //上传文件 smartUpload.upload(); String id = rq.getParameter("id"); File smartFile = smartUpload.getFiles().getFile(0); smartFile.saveAs("/userImg/"+id+".jpeg"); out.print("<script>alert(\"上传成功!\");window.location.href='teacher/personal.jsp';</script>"); } catch (Exception e){ out.print(e); } } }
2.前端实现
student(main.jsp)
<%@ page import="dao.StudentDao" %> <%@ page import="dao.ScoreDao" %> <%@ page import="vo.Score" %> <%@ page import="vo.Student" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>main</title> <link href="../resources/css/default.css" rel="stylesheet"/> </head> <body style="background:#c3e6cb"> <% Student student = (Student) session.getAttribute("info"); %> <div id="page" class="container"> <div id="header"> <div id="logo"> <img src="../userImg/<%=student.getId()%>.jpeg"/> <h1><%=student.getName()%></h1> </div> <div id="menu"> <ul> <li><a href="personal.jsp">个人信息</a></li> <li class="current_page_item"><a href="main.jsp">我的成绩</a></li> <li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li> </ul> </div> </div> <div id="main"> <div class="top"> <h2 style="color: darkslateblue">我的成绩</h2> <hr/> </div> <div class="table"> <table width="800" frame="box" align="center"> <tr> <th height="35">学号/工号</th> <th>姓名</th> <th>学院</th> <th>数据库</th> <th>安卓</th> <th>JSP</th> <%--<th>操作</th>--%> </tr> <% try { ScoreDao scoD = new ScoreDao(); StudentDao stuD = new StudentDao(); Score stu = scoD.findWithId(student.getId()); String name = stuD.findWithId(student.getId()).getName(); String major = stuD.findWithId(student.getId()).getMajor(); %> <tr> <td height="35"><%=stu.getId()%></td> <td><%=name%></td> <td><%=major%></td> <td><%=stu.getDatabase()%></td> <td><%=stu.getAndroid()%></td> <td><%=stu.getJsp()%></td> <%--<td><a href="pdf.jsp?id=<%=stu.getId()%>&name=<%=name%>&major=<%=major%>&database=<%=stu.getDatabase()%>&android=<%=stu.getAndroid()%>&jsp=<%=stu.getJsp()%>">PDF</a></td>--%> </tr> <% } catch (Exception e){ out.print(e); } %> </table> </div> </div> </div> </body> </html> </body> </html>
student(person.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>main</title> link rel="stylesheet" href="../resources/css/jquery-ui-1.10.4.custom.min.css"> <script src="../resources/js/jquery-1.10.2.js"></script> <script src="../resources/js/jquery-ui-1.10.4.custom.min.js"></script> <link href="../resources/css/default.css" rel="stylesheet"/> </head> <body style="background: #c3e6cb"> <% Student student = (Student) session.getAttribute("info"); %> <div id="page" class="container"> <div id="header"> <div id="logo"> <img src="../userImg/<%=student.getId()%>.jpeg"/> <h1><%=student.getName()%></h1> </div> <div id="menu"> <ul> <li class="current_page_item"><a href="personal.jsp" style="color: #10707f">个人信息</a></li> <li><a href="main.jsp" style="color: #10707f">我的成绩</a></li> <li><a onclick="return confirm('确认退出?');" href="../exit" style="color: #10707f">退出登录</a></li> </ul> </div> </div> <div id="main"> <div class="top"> <h2 style="color: darkslateblue">我的成绩</h2> <hr/> </div> <div class="info"> <img src="../userImg/<%=student.getId()%>.jpeg" class="personalImg"><br> <form action="../upload_studentImg" method="post" enctype="multipart/form-data"> <input type="hidden" name="id" value="<%=student.getId()%>"> <input type="file" name="img"> <input type="submit" value="上传头像"> </form> <form action="../update_student_email" method="post"> <table width="400" frame="box" align="center" style="margin-top: 30px;"> <tr> <td style="font-size: 25px;font-weight: bold">学号</td> <td style="font-size: 25px;font-weight: bold"><%=student.getId()%></td> </tr> <tr> <td style="font-size: 25px;font-weight: bold">姓名</td> <td style="font-size: 25px;font-weight: bold"><%=student.getName()%></td> </tr> <tr> <td style="font-size: 25px;font-weight: bold">性别</td> <td style="font-size: 25px;font-weight: bold"><%=student.getSex()%></td> </tr> <tr> <td style="font-size: 25px;font-weight: bold">学院</td> <td style="font-size: 25px;font-weight: bold"><%=student.getMajor()%></td> </tr> </table> </form> <button class="password-btn" style="margin-top: 30px; height: 40px">修改安全信息</button> </div> </div> </div> <%--修改密码对话框--%> <div id="password-dialog" title="修改安全信息" style="color: #004085"> <form id="password-form" method="post"> <input type="hidden" name="id" value="<%=student.getId()%>"> <%--邮箱: <input type="email" name="email" value="<%=student.getEmail()%>"><br><br>--%> 新密码:<input type="password" name="password"><br> <hr> <input style="float: right " type="submit" value="取消" onclick="function x() { $('#add-dialog').dialog('close'); }"> <input style="float: right; margin-right: 25px" type="submit" value="保存" onclick="this.form.action='../update_student_security'"> </form> </div> <script> $('#password-dialog').dialog({ width: 340, autoOpen: false, draggable: false, modal: true, resizable: false }); $('.password-btn').click(function () { $('#password-dialog').dialog('open'); }); </script> <style> .ui-dialog-titlebar-close { display: none } </style> </body> </html>
student(resetPassword.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>重置密码</title> <link rel="stylesheet" href="../resources/css/bootstrap.min.css"> <link href="../resources/css/forget.css" type="text/css" rel="stylesheet" /> </head> <body style="background: #c3e6cb"> h1 style="margin: 0px 80px; color:darkslateblue; font-family: STCaiyun">学生成绩管理系统</h1><br> <% String id = request.getParameter("id"); String email = request.getParameter("email"); String reset = request.getParameter("reset"); String code = (String) session.getAttribute("reset"); if (!reset.equals(code)){ %> <script>alert("验证码错误!");window.location.href='../forget.jsp';</script> <% } else { %> <div class="main"> <form role="form" action="../update_student_security" method="post"> <div class="form-group" align="center"> <input class="form-control" type="text" name="password" placeholder="新密码"><br> <input type="hidden" name="id" value="<%=id%>"> <input type="hidden" name="email" value="<%=email%>"> <input type="submit" class="btn btn-success" value="提交"> <input type="button" class="btn btn-info" value="取消" style="margin-left: 20px" onclick="window.location.href='../login.jsp'"> </div> </form> </div> <% } %> <script src="../resources/js/jquery-3.2.1.min.js"></script> <script src="../resources/js/popper.min.js"></script> <script src="../resources/js/bootstrap.min.js"></script> </body> </html>
teacher(main.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page import="vo.Student" %> <%@ page import="vo.Teacher" %> <%@ page import="java.util.ArrayList" %> <html> <head> <link rel="stylesheet" href="../resources/css/jquery-ui-1.10.4.custom.min.css"> <script src="../resources/js/jquery-1.10.2.js"></script> <script src="../resources/js/jquery-ui-1.10.4.custom.min.js"></script> <title>main</title> <link href="../resources/css/default.css" rel="stylesheet"/> </head> <body style="background: #c3e6cb"> <% Teacher teacher = (Teacher) session.getAttribute("info"); ArrayList<Student> stus = (ArrayList<Student>) session.getAttribute("onePageStudent"); int sumIndex = (int) session.getAttribute("sumIndex"); %> <div id="page" class="container"> <div id="header"> logo部分 <div id="logo"> <img src="../userImg/<%=teacher.getId()%>.jpeg"/> <h1><%=teacher.getId()%> </h1> </div> <%-- 左面的功能栏 --%> <div id="menu"> <ul> <li><a href="personal.jsp">个人信息</a></li> <li class="current_page_item"><a href="../one_page_student">学生信息管理</a></li> <li><a href="../one_page_score">学生成绩管理</a></li> <li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li> </ul> </div> </div> <div id="main"> <div class="top"> <h2 style="color: darkslateblue">学生成绩管理</h2> <hr/> <button class="btn-add" style="color: #2980b9">添加学生信息</button> <div class="find"> <form action="../one_page_student" method="post"> <input id="find-text" type="text" name="key" placeholder="输入学号/工号或姓名搜索"> <input class="find-btn" type="submit" value="搜索"> </form> </div> </div> <div class="table"> <table id="table" width="800" frame="box" align="center"> <tr> <th height="35">学号/工号</th> <th>姓名</th> <th>性别</th> <th>班级</th> <th>学院</th> <th>操作</th> </tr> <% for (Student stu : stus) { %> <tr> <form method="post" action="../update_student"> <td height="35"><%=stu.getId()%></td> <td><input value="<%=stu.getName()%>" name="stuname" class="table-input"></td> <td><input value="<%=stu.getSex()%>" name="stusex" class="table-input"></td> <td><%=stu.getSchool_date()%></td> <td><input value="<%=stu.getMajor()%>" name="stumajor" class="table-input" style="width: 110px"></td> <input value="<%=stu.getId()%>" name="stuno" type="hidden"> <td><input type="submit" class="update-btn" value="修改"> <a class="btn-delete" onclick="return confirm('确定要删除吗?');" href=<%="'../delete_student?id=" + stu.getId() + "'"%>>删除</a> <a href="../one_page_score?id=<%=stu.getId()%>" style="color: #117a8b">学生成绩</a> </td> </form> </tr> <% } %> </table> </div> <% if (sumIndex > 1){ %> <div id="index"> <a href="../one_page_student?index=1">首页</a> <% for (int i=1; i<=sumIndex; i++){ %> <a href="../one_page_student?index=<%=i%>">第<%=i%>页</a> <% } %> <a href="../one_page_student?index=<%=sumIndex%>">尾页</a> </div> <% } %> </div> </div> <%--添加学生信息对话框--%> <div id="add-dialog" title="添加学生信息"> <form id="add-form" method="post"> 学号:<input name="id" type="text"><br> 姓名:<input name="name" type="text"><br> 性别:<input name="sex" type="text"><br> 班级:<input name="school_date" type="text"> 学院:<input name="major" type="text"><br> <hr> <input style="float: right" type="submit" value="取消" onclick="function x() { $('#add-dialog').dialog('close'); }"> <input style="float: right; margin-right: 25px" type="submit" value="确定" onclick="this.form.action='../add_student'"> </form> </div> <style> .ui-dialog-titlebar-close { display: none } </style> <script> $('#add-dialog').dialog({ width: 310, autoOpen: false, draggable: false, modal: true, resizable: false }); $('.btn-add').click(function () { $('#add-dialog').dialog('open'); }); </script> </body> </html>
teacher(personal.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>main</title> <link href="../resources/css/default.css" rel="stylesheet"/> </head> <body style="background: #c3e6cb"> <% Teacher teacher = (Teacher) session.getAttribute("info"); %> <div id="page" class="container"> <div id="header"> <div id="logo"> <img src="../userImg/<%=teacher.getId()%>.jpeg"/> <h1><%=teacher.getId()%> </h1> </div> <div id="menu"> <ul> <li class="current_page_item"><a href="personal.jsp">个人信息</a></li> <li><a href="../one_page_student">学生信息管理</a></li> <li><a href="../one_page_score">学生成绩管理</a></li> <li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li> </ul> </div> </div> <div id="main"> <div class="top"> <h2 style="color: darkslateblue">个人信息</h2> <hr/> </div> <div class="info"> <img src="../userImg/<%=teacher.getId()%>.jpeg" class="personalImg"><br> <form action="../upload_teacherImg" method="post" enctype="multipart/form-data"> <input type="hidden" name="id" value="<%=teacher.getId()%>"> <input type="file" name="img"> <input type="submit" value="上传头像"> </form> <form method="post" action="../update_teacher" class="personalForm"> <input name="uid" value="<%=teacher.getId()%>" type="hidden"> 姓名: <input type="text" name="name" value="<%=teacher.getName()%>" class="personalInput"><br> 性别: <input type="text" name="sex" value="<%=teacher.getSex()%>" class="personalInput"><br> 邮箱: <input type="text" name="email" value="<%=teacher.getEmail()%>" class="personalInput"><br> 密码: <input type="text" name="password" value="<%=teacher.getPassword()%>" class="personalInput"><br> <input type="submit" value="保存" style="width: 100px; height: 30px; margin-top: 20px"> </form> </div> </div> </div> </body> </html>
teacher(resetPassword.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>重置密码</title> <link rel="stylesheet" href="../resources/css/bootstrap.min.css"> <link href="../resources/css/forget.css" type="text/css" rel="stylesheet" /> </head> <body> <h1 style="margin: 0px 80px; color:darkslateblue; font-family: STCaiyun">学生成绩管理系统</h1><br> <% String id = request.getParameter("id"); String reset = request.getParameter("reset"); String code = (String) session.getAttribute("reset"); if (!reset.equals(code)){ %> <script>alert("验证码错误!");window.location.href='../forget.jsp';</script> <% } else { %> <div class="main"> <form role="form" action="../update_teacher_password" method="post"> <div class="form-group" align="center"> <input type="text" class="form-control" name="password" placeholder="新密码"><br> <input type="hidden" name="id" value="<%=id%>"> <input type="submit" class="btn btn-success" value="提交"> <input type="button" class="btn btn-info" value="取消" style="margin-left: 20px" onclick="window.location.href='../login.jsp'"> </div> </form> </div> <% } %> <script src="../resources/js/jquery-3.2.1.min.js"></script> <script src="../resources/js/popper.min.js"></script> <script src="../resources/js/bootstrap.min.js"></script> </body> </html>
teacher(score.jsp)
<%@ page import="dao.StudentDao" %> <%@ page import="vo.Score" %> <%@ page import="vo.Teacher" %> <%@ page import="java.util.ArrayList" %><%-- Created by IntelliJ IDEA. User: 12276 Date: 2021/10/23 Time: 12:26 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>main</title> <link href="../resources/css/default.css" rel="stylesheet"/> </head> <body style="background: #c3e6cb"> <% Teacher teacher = (Teacher) session.getAttribute("info"); ArrayList<Score> stus = (ArrayList<Score>) session.getAttribute("onePageScore"); int sumIndex = (int) session.getAttribute("sumScoreIndex"); %> <div id="page" class="container"> <div id="header"> <div id="logo"> <img src="../userImg/<%=teacher.getId()%>.jpeg"/> <h1><%=teacher.getId()%> </h1> </div> <div id="menu"> <ul> <li><a href="personal.jsp">个人信息</a></li> <li><a href="../one_page_student">学生信息管理</a></li> <li class="current_page_item"><a href="../one_page_score">学生成绩管理</a></li> <li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li> </ul> </div> </div> <div id="main"> <div class="top"> <h2 style="color: darkslateblue">学生成绩管理</h2> <hr/> </div> <form method="post" action="../update_score" style="height: 525px; margin-top: 20px"> <input type="button" class="btn-add" onclick="location.href='score_excel.jsp';" value="导出EXCEL"> <input type="submit" class="btn-add" style="float: right;margin-bottom: 30px" value="修改"> <div class="table" style="margin-top: 20px; height: 525px"> <table id="table" width="800" frame="box" align="center"> <tr> <th height="35">学号</th> <th>姓名</th> <th>学院</th> <th>数据库</th> <th>安卓</th> <th>JSP</th> </tr> <% try { StudentDao stuD = new StudentDao(); for (Score stu : stus) { String name = stuD.findWithId(stu.getId()).getName(); String major = stuD.findWithId(stu.getId()).getMajor(); %> <tr> <td height="35"><%=stu.getId()%></td> <td><%=name%></td> <td><%=major%></td> <td><input value="<%=stu.getDatabase()%>" name="database" class="table-input"></td> <td><input value="<%=stu.getAndroid()%>" name="android" class="table-input"></td> <td><input value="<%=stu.getJsp()%>" name="jsp" class="table-input"></td> <input value="<%=stu.getId()%>" name="id" type="hidden"> </tr> <% } } catch (Exception e) { e.printStackTrace(); } %> </table> </div> </form> <%-- 展示下面的页签数 --%> <% if (sumIndex > 1){ %> <div id="index"> <a href="../one_page_score?index=1">首页</a> <% for (int i = 1; i <= sumIndex; i++) { %> <a href="../one_page_score?index=<%=i%>">第<%=i%>页</a> <% } %> <a href="../one_page_score?index=<%=sumIndex%>">尾页</a> </div> <% } %> </div> </div> </body> </html>
teacher(score_excel.jsp)
<%@ page import="dao.ScoreDao" %> <%@ page import="dao.StudentDao" %> <%@ page import="vo.Score" %> <%@ page import="java.util.ArrayList" %><%-- Created by IntelliJ IDEA. User: 12276 Date: 2021/10/23 Time: 12:30 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>main</title> </head> <body style="background: #c3e6cb"> <% out.clearBuffer(); response.setHeader("Content-Disposition", "attachment;filename=excel.xls"); %> <table align="center" border="1"> <tr> <th height="35">学号</th> <th>姓名</th> <th>学院</th> <th>数据库</th> <th>安卓</th> <th>JSP</th> </tr> <% try { ScoreDao scoD = new ScoreDao(); StudentDao stuD = new StudentDao(); ArrayList<Score> stus = scoD.getOnePage(1, 10000); for (Score stu : stus) { String name = stuD.findWithId(stu.getId()).getName(); String major = stuD.findWithId(stu.getId()).getMajor(); %> <tr> <td align="center"><%=stu.getId()%></td> <td align="center"><%=name%></td> <td align="center"><%=major%></td> <td align="center"><%=stu.getDatabase()%></td> <td align="center"><%=stu.getAndroid()%></td> <td align="center"><%=stu.getJsp()%></td> </tr> <% } } catch (Exception e) { e.printStackTrace(); } %> </table> </body> </html>
code.jsp
<%@ page import="java.awt.image.BufferedImage" %> <%@ page import="java.awt.*" %> <%@ page import="java.util.Random" %> <%@ page import="javax.imageio.ImageIO" %><%-- Created by IntelliJ IDEA. User: 12276 Date: 2021/10/23 Time: 12:32 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <% response.setCharacterEncoding("utf-8"); response.setHeader("Cache-Control", "no-cache"); //创建图像 int width = 60, height = 20; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); //获取画笔 Graphics g = image.getGraphics(); //设定背景色 g.setColor(new Color(100, 200, 200)); g.fillRect(0, 0, width, height); //随机产生四位数字 Random rnd = new Random(); int randNum = rnd.nextInt(8999) + 1000; String randStr = String.valueOf(randNum); //将验证码存入session session.setAttribute("randStr", randStr); //显示到图像中 g.setColor(Color.BLACK); g.setFont(new Font("", Font.PLAIN, 20)); g.drawString(randStr, 10, 17); //随机产生100个干扰点 for (int i = 0; i < 100; i++) { int x = rnd.nextInt(width); int y = rnd.nextInt(height); g.drawOval(x, y, 1, 1); } //输出到页面 ImageIO.write(image, "jpeg", response.getOutputStream()); out.clear(); out = pageContext.pushBody(); %> </body> </html>
login.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>请登陆</title> <link rel="stylesheet" href="resources/js/bootstrap.min.css"> <link href="resources/css/login.css" type="text/css" rel="stylesheet" /> </head> <body> <script> function check(form){ if (form.user.value === "") { alert("请输入账号!"); return false; } if (form.password.value === "") { alert("请输入密码!"); return false; } return true; } </script> <h1>学生成绩管理系统</h1><br> <div class="main"> <h5 class="title"> <a href="login.jsp" id="login">登录</a> <%--<b> · </b>--%> <a href="register.jsp" id="register">注册</a> </h5> <form action="check_login" method="post" onsubmit="return check(this)"> <div class="form-group" > <b> </b><b> </b><b> </b><b> </b><b> </b> <b> </b><b> </b><b> </b> <input type="text" name="user" class="form-control user" placeholder="请输入用户名"> <br> <b> </b><b> </b><b> </b><b> </b><b> </b> <b> </b><b> </b><b> </b> <input type="password" name="password" class="form-control password" placeholder="请输入密码"> <br> <div class="remember-btn"> <input type="checkbox" name="remember" value="true"> <span style="color: #d4edda">记住我</span> </div> <a href="forget.jsp" class="help" style="color: #1b1e21">登录遇到问题?</a> <br> <br> <b> </b><b> </b><b> </b><b> </b><b> </b><b> </b> <b> </b> <b> </b> <b> </b> <b> </b> <input type="submit" value="登录" class="btn btn-primary btn-lg btn-block" /> </div> </form> </div> <script src="resources/js/jquery-3.2.1.min.js"></script> <script src="resources/js/popper.min.js"></script> <script src="resources/js/bootstrap.min.js"></script> </body> </html>
register.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>注册</title> <link rel="stylesheet" href="resources/css/bootstrap.min.css"> <link href="resources/css/register.css" type="text/css" rel="stylesheet" /> </head> <body> <script> function check(form){ if (form.user.value === "") { alert("请输入账号!"); return false; } if (form.password1.value === "") { alert("请输入密码!"); return false; } return true; } function refresh() { var i=Math.random(); document.getElementById("image").src = "code.jsp?a="+i; } </script> <h1>学生成绩管理系统</h1><br> <div class="main"> <h5 class="title" > <a href="login.jsp" id="login">登录</a> <b> · </b> <a href="register.jsp" id="register">注册</a> </h5> <form action="check_register" method="post" onsubmit="return check(this)"> <div class="form-group"> <input type="email" name="email" class="form-control email" placeholder="安全邮箱"> <input type="text" name="user" class="form-control user" placeholder="用户名"> <input type="password" name="password1" class="form-control password1" placeholder="密码"> <input type="text" name="code" placeholder="验证码" class="code"> <img src="code.jsp" id="image" style="float: right; width: 90px;height: 50px; margin-top: 10px" onclick="refresh()"> <input type="submit" value="注册" class="btn btn-primary btn-lg btn-block we" /> </div> </form> </div> <script src="resources/js/jquery-3.2.1.min.js"></script> <script src="resources/js/popper.min.js"></script> <script src="resources/js/bootstrap.min.js"></script> </body> </html>
3.css
login.css
body{ /*background-color: #f1f1f1;*/ background:url(../img/1.jpg); } .main{ width: 400px; height: 450px; background-color:#005cbf; position: absolute; left: 50%; top: 50%; margin: -250px 0 0 -200px; padding: 50px; border-radius:10px ; box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2); } .title{ padding-top: 25px; padding-bottom: 40px; text-align: center; } .title a{ padding: 10px; color: #b19696; font-weight: 500; text-decoration: none; } #login{ font-weight: 600; color: #ea6f5a; border-bottom: 1px solid #ea6f5a; text-decoration: none; } .form-control{ height: 50px; } .user{ border-bottom: none; border-radius: 5px 5px 0 0; background:url(../img/user.png) no-repeat 5px 12px; background-size: 25px 25px; padding-left:35px; } .password{ border-radius: 0 0 5px 5px; background:url(../img/password.png) no-repeat 8px 12px; background-size: 20px 20px; padding-left:35px; } .code{ width: 200px; height: 30px; margin-top: 10px; border-radius: 5px; border: 1px solid #ced4da; padding-left: 10px; } .remember-btn{ float: left; margin: 25px 0 35px; font-size: 14px; color: #999; } .form-group .help{ float: right; position: relative; margin: 25px 0 35px; font-size: 14px; color: #999; } .btn{ margin-top: 40px; border: none; border-radius: 25px; background: #3194d0; }
forget.css
body{ background-color: #f1f1f1; } .main{ width: 600px; height: 300px; position: absolute; left: 50%; top: 50%; margin: -150px 0 0 -300px; padding: 100px; background-color: white; border-radius:10px ; box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2); }
default.css
body { background: #202020; font-size: 12pt; font-weight: 200; color: #444444; } h1 { font-weight: 400; color: #FFF; } ul { padding: 0; list-style: none; } a { color: #2980b9; } a:hover { /* 把链接取消 */ text-decoration: none; } .container { /* 如果元素中的内容超出了给定的宽度和高度属性,overflow 属性可以确定是否显示滚动条等行为。 */ overflow: hidden; margin: 40px auto; width: 1200px; } /*********************************************************************************/ /* Header */ /*********************************************************************************/ #header { /* 生成相对定位的元素,相对于其正常位置进行定位。 */ position: relative; /* 向右侧浮动 */ float: left; width: 300px; /* 填充 */ padding: 3em 0 1em; } /*********************************************************************************/ /* Logo */ /*********************************************************************************/ #logo { text-align: center; margin-top: 1em; margin-bottom: 4em; } #logo img { width: 140px; height: 140px; display: inline-block; margin-bottom: 1em; border-radius: 50%; } #logo h1 { display: block; } /*********************************************************************************/ /* Menu */ /*********************************************************************************/ #menu li { /* 设置上边框的样式 */ border-top: 1px solid rgba(255,255,255,0.08); } /* 没有选中的颜色及背景 */ #menunew { margin-top: 10em; border-top: 1px solid rgba(255,255,255,0.08); text-align: center; text-decoration: none; text-transform: uppercase; font-weight: 700; color: rgba(255,255,255,0.5); } /* 没有选中的颜色及背景 */ #menu tr a { display: block; padding: 2em 1.5em; text-align: center; text-decoration: none; text-transform: uppercase; font-weight: 700; color: rgba(255,255,255,0.5); } /* 当前颜色 */ #menu .current_page_item a { background: #2980b9; color: rgba(255,255,255,1); } /*********************************************************************************/ /* Page */ /*********************************************************************************/ #page { background: #2a2a2a; } /*********************************************************************************/ /* Main */ /*********************************************************************************/ #main { /* 声明了显示浏览器的屏幕的高度,以像素计。 */ height: 675px; overflow: hidden; float: right; width: 800px; padding: 2em 50px 1em 50px; background: #f9f9f9; border-top: 6px solid #2980b9; text-align: center; } .top{ width: 800px; } .table{ margin-top: 110px; height: 433px; } /* 添加按钮 */ .btn-add{ width: 100px; height: 38px; float: left; margin-top: 30px; } /* 查找文本 */ .find{ float: right; margin-top: 30px; } /* 查找文本 */ #find-text{ width: 250px; height: 30px; } /* 查找按钮 */ .find-btn{ height: 30px; } /* 表格输入 */ .table-input{ width: 40px; text-align: center; border-top: none; border-left: none; border-right: none; border-bottom-color: #e6e6e6; background: transparent; } /* 更新按钮 */ .update-btn{ font-weight: 100; font-size: 16px; color: #2980b9; cursor:pointer; border:none; background:transparent; text-decoration:underline } .update-btn:hover{ text-decoration: none; } .personalImg{ width: 200px; height: 200px; margin-bottom: 5px; } .info{ margin-top: 20px; } .personalForm{ margin-top: 20px; } .personalInput{ height: 35px; margin-bottom: 10px; background: transparent; border-top: none; border-left: none; border-right: none; } /* 上外边距 */ #index{ margin-top: 20px; }
register.css
body{ background-color: #f1f1f1; } .main{ width: 400px; height: 500px; position: absolute; left: 50%; top: 50%; margin: -250px 0 0 -200px; padding: 50px; background-color: white; border-radius:10px ; box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2); } .title{ padding-top: 25px; padding-bottom: 40px; text-align: center; } .title a{ padding: 10px; color: #b19696; font-weight: 500; text-decoration: none; } #register{ font-weight: 600; color: #ea6f5a; border-bottom: 1px solid #ea6f5a; text-decoration: none; } .form-control{ height: 50px; } .email{ border-radius: 5px 5px 0 0; background:url(../img/email.png) no-repeat 5px 12px; background-size: 22px 22px; padding-left:35px; } .user{ border-top: none; border-radius: 0; background:url(../img/user.png) no-repeat 5px 12px; background-size: 25px 25px; padding-left:35px; } .password1{ border-top: none; border-radius: 0 0 5px 5px; background:url(../img/password.png) no-repeat 8px 12px; background-size: 20px 20px; padding-left:35px; } .code{ width: 200px; height: 50px; margin-top: 10px; border-radius: 5px; border: 1px solid #ced4da; padding-left: 10px; } .btn{ margin-top: 40px; border: none; border-radius: 25px; background: #42c02e; }
所用到的jar包
itextpdf-5.5.5.jar
javax.annotation.jar
javax.ejb.jar
javax.jms.jar
javax.persistence.jar
javax.resource.jar
javax.servlet.jar
javax.servlet.jsp.jar
javax.servlet.jsp.jstl.jar
javax.transaction.jar
jsmartcom_zh_CN.jar
mysql-connector-java-5.1.46.jar
本项目严格按照MVC模式完成,什么是MVC,以下我就来简单介绍一下:MVC模式(Model-View-Controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:
模型(Model)、视图(View)和控制器(Controller)。
MVC模式最早为Trygve Reenskaug提出,为施乐帕罗奥多研究中心(Xerox PARC)的Smalltalk语言发明的一种软件设计模式。
MVC可对程序的后期维护和扩展提供了方便,并且使程序某些部分的重用提供了方便。而且MVC也使程序简化,更加直观。
* 视图View:界面设计人员进行图形界面设计;
* 控制器Controller:对请求进行处理,负责请求转发;
* 模型Model:程序编写程序应用的功能(实现算法等等)、数据库管理;
* 本项目M(模型)代表着javaBean里面的的成员属性,C(控制器)代表着Servlet,V(视图)代表着jsp页面.
注意:
MVC不是Java的东西,几乎现在所有B/S结构的软件都采用了MVC设计模式。
这个项目基本的JavaEE的知识点都包括了。但是没有用到日志框架,不过用来做简单的课程设计是绰绰有余了。
想要源码的可以加我的QQ:2407019276,或者私信我的csdn账号。如有侵权请联系我删除。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。