IDEA+Java+Servlet+JSP+Mysql实现学生选课签到系统

举报
水坚石青 发表于 2021/12/31 22:58:23 2021/12/31
【摘要】 一、系统介绍 1.开发环境 开发工具:IDEA2018 JDK版本:jdk1.8 Mysql版本:8.0.13 2.技术选型 Java+Servlet+Boostrap+Jsp+Mysql 3.系统功能 1.用户注册登录系统; 2.管理员审核用户,查看课程选课情况,开启签到,删除课程,修改密码; 3.教师创建课程,查...

一、系统介绍

1.开发环境

开发工具:IDEA2018

JDK版本:jdk1.8

Mysql版本:8.0.13

2.技术选型

Java+Servlet+Boostrap+Jsp+Mysql

3.系统功能

1.用户注册登录系统;

2.管理员审核用户,查看课程选课情况,开启签到,删除课程,修改密码;

3.教师创建课程,查看成员,开启签到,删除课程,修改密码;

4.学生选择课程,退选课程,修改密码;

4.数据库文件


  
  1. /*
  2. Navicat Premium Data Transfer
  3. Source Server : MYSQL
  4. Source Server Type : MySQL
  5. Source Server Version : 80013
  6. Source Host : localhost:3306
  7. Source Schema : servlet_select_course
  8. Target Server Type : MySQL
  9. Target Server Version : 80013
  10. File Encoding : 65001
  11. Date: 24/12/2021 16:58:38
  12. */
  13. SET NAMES utf8mb4;
  14. SET FOREIGN_KEY_CHECKS = 0;
  15. -- ----------------------------
  16. -- Table structure for tb_courses
  17. -- ----------------------------
  18. DROP TABLE IF EXISTS `tb_courses`;
  19. CREATE TABLE `tb_courses` (
  20. `course_id` int(11) NOT NULL AUTO_INCREMENT,
  21. `name` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
  22. `teach_id` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
  23. `day` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
  24. `is_signin` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
  25. `member_num` int(11) NULL DEFAULT NULL,
  26. PRIMARY KEY (`course_id`) USING BTREE,
  27. INDEX `C_FK`(`teach_id`) USING BTREE,
  28. CONSTRAINT `C_FK` FOREIGN KEY (`teach_id`) REFERENCES `tb_users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
  29. ) ENGINE = InnoDB AUTO_INCREMENT = 29 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic;
  30. -- ----------------------------
  31. -- Records of tb_courses
  32. -- ----------------------------
  33. INSERT INTO `tb_courses` VALUES (27, '软件工程', '101', '星期一, 1 - 2 节', 'false', 1);
  34. INSERT INTO `tb_courses` VALUES (28, '计算机导论', '104', '星期二, 3 - 4 节', 'false', 0);
  35. -- ----------------------------
  36. -- Table structure for tb_join
  37. -- ----------------------------
  38. DROP TABLE IF EXISTS `tb_join`;
  39. CREATE TABLE `tb_join` (
  40. `course_id` int(11) NULL DEFAULT NULL,
  41. `stu_id` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
  42. `checked` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL
  43. ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic;
  44. -- ----------------------------
  45. -- Records of tb_join
  46. -- ----------------------------
  47. INSERT INTO `tb_join` VALUES (27, '1001', 'true');
  48. INSERT INTO `tb_join` VALUES (28, '1001', 'checking');
  49. -- ----------------------------
  50. -- Table structure for tb_signin
  51. -- ----------------------------
  52. DROP TABLE IF EXISTS `tb_signin`;
  53. CREATE TABLE `tb_signin` (
  54. `signin_id` int(11) NOT NULL AUTO_INCREMENT,
  55. `course_id` int(11) NULL DEFAULT NULL,
  56. `time` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
  57. `signin_num` int(11) NULL DEFAULT NULL,
  58. `end_time` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
  59. PRIMARY KEY (`signin_id`) USING BTREE
  60. ) ENGINE = InnoDB AUTO_INCREMENT = 25 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic;
  61. -- ----------------------------
  62. -- Records of tb_signin
  63. -- ----------------------------
  64. INSERT INTO `tb_signin` VALUES (24, 27, '2021-12-20 15:15:48', 1, '2021-12-20 15:16:16');
  65. -- ----------------------------
  66. -- Table structure for tb_signin_stu
  67. -- ----------------------------
  68. DROP TABLE IF EXISTS `tb_signin_stu`;
  69. CREATE TABLE `tb_signin_stu` (
  70. `signin_id` int(11) NULL DEFAULT NULL,
  71. `stu_id` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
  72. `state` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL
  73. ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic;
  74. -- ----------------------------
  75. -- Records of tb_signin_stu
  76. -- ----------------------------
  77. INSERT INTO `tb_signin_stu` VALUES (24, '1001', 'true');
  78. -- ----------------------------
  79. -- Table structure for tb_users
  80. -- ----------------------------
  81. DROP TABLE IF EXISTS `tb_users`;
  82. CREATE TABLE `tb_users` (
  83. `user_id` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  84. `password` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
  85. `name` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
  86. `type` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
  87. `checked` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
  88. PRIMARY KEY (`user_id`) USING BTREE
  89. ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic;
  90. -- ----------------------------
  91. -- Records of tb_users
  92. -- ----------------------------
  93. INSERT INTO `tb_users` VALUES ('1001', '123456', '同学1', 'stu', 'true');
  94. INSERT INTO `tb_users` VALUES ('1002', '123456', '同学2', 'stu', 'true');
  95. INSERT INTO `tb_users` VALUES ('101', '123456', '教师1', 'teach', 'true');
  96. INSERT INTO `tb_users` VALUES ('102', '123456', '教师2', 'teach', 'true');
  97. INSERT INTO `tb_users` VALUES ('103', '123456', '教师3', 'teach', 'true');
  98. INSERT INTO `tb_users` VALUES ('104', '123456', '王老师', 'teach', 'true');
  99. INSERT INTO `tb_users` VALUES ('105', '123456', '李老师', 'teach', 'false');
  100. INSERT INTO `tb_users` VALUES ('admin', 'admin', '管理员', 'admin', 'true');
  101. SET FOREIGN_KEY_CHECKS = 1;

二、系统展示

1.登录系统

2.注册系统

3.管理员-首页

4.管理员-管理用户

5.管理员-管理课程

6.管理员-修改密码

7.教师-创建课程

8.教师-我的课程

9.教师-修改密码

10.学生-加入课程

11.学生-我的课程

12.学生-修改密码

三、部分代码

CreateCourseAction


  
  1. package com.sjsq.servlet;
  2. import com.sjsq.bean.Course;
  3. import com.sjsq.bean.User;
  4. import com.sjsq.dao.CourseDao;
  5. import javax.servlet.ServletException;
  6. import javax.servlet.annotation.MultipartConfig;
  7. import javax.servlet.annotation.WebServlet;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import java.io.IOException;
  12. import java.io.PrintWriter;
  13. @WebServlet("/CreateCourseAction")
  14. @MultipartConfig
  15. public class CreateCourseAction extends HttpServlet {
  16. /**
  17. *
  18. */
  19. private static final long serialVersionUID = 1L;
  20. @Override
  21. protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  22. super.doGet(req, resp);
  23. }
  24. @Override
  25. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  26. req.setCharacterEncoding("utf-8");
  27. resp.setContentType("text/html;charset=utf-8");
  28. PrintWriter out = resp.getWriter();
  29. String courseName = req.getParameter("courseName");
  30. String day = req.getParameter("day");
  31. String courseTime = req.getParameter("courseTime");
  32. String Day = day + ", " + courseTime;
  33. User user = (User) req.getSession().getAttribute("User");
  34. String teach_id = user.getId();
  35. Course course = new Course(0, courseName, teach_id, Day, "false", 0);
  36. CourseDao courseDao = new CourseDao();
  37. int result = courseDao.Create(course);
  38. if (result == 0) {
  39. out.println("<script> alert('创建课程失败'); location='teacher_create.jsp'; </script>");
  40. } else if (result == 1) {
  41. out.println("<script> alert('创建课程成功'); location='teacher_create.jsp'; </script>");
  42. } else {
  43. out.println("<script> alert('上课时间冲突'); location='teacher_create.jsp'; </script>");
  44. }
  45. }
  46. }


DeleteAction


  
  1. package com.sjsq.servlet;
  2. import com.sjsq.dao.CourseDao;
  3. import com.sjsq.dao.JoinDao;
  4. import com.sjsq.dao.UserDao;
  5. import javax.servlet.ServletException;
  6. import javax.servlet.annotation.MultipartConfig;
  7. import javax.servlet.annotation.WebServlet;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import java.io.IOException;
  12. import java.io.PrintWriter;
  13. import java.sql.SQLException;
  14. @WebServlet("/DeleteAction")
  15. @MultipartConfig
  16. public class DeleteAction extends HttpServlet {
  17. /**
  18. *
  19. */
  20. private static final long serialVersionUID = 1L;
  21. @Override
  22. protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  23. req.setCharacterEncoding("utf-8");
  24. resp.setContentType("text/html;charset=utf-8");
  25. PrintWriter out = resp.getWriter();
  26. String ope = req.getParameter("ope");
  27. if (ope.equals("userdel")) {
  28. // 删除用户
  29. String user_id = req.getParameter("user_id");
  30. UserDao userDao = new UserDao();
  31. if (userDao.DelUser(user_id) == 1) {
  32. out.println("<script> alert('删除成功'); location='toaudit.jsp'; </script>");
  33. } else {
  34. out.println("<script> alert('删除失败'); location='toaudit.jsp'; </script>");
  35. }
  36. } else if (ope.equals("useradd")) {
  37. // 用户审核
  38. String user_id = req.getParameter("user_id");
  39. UserDao userDao = new UserDao();
  40. try {
  41. if (userDao.Check(user_id) == 1) {
  42. out.println("<script> alert('审核通过'); location='toaudit.jsp'; </script>");
  43. } else {
  44. out.println("<script> alert('操作失败'); location='toaudit.jsp'; </script>");
  45. }
  46. } catch (SQLException e) {
  47. // TODO Auto-generated catch block
  48. e.printStackTrace();
  49. out.println("<script> alert('操作失败'); location='toaudit.jsp'; </script>");
  50. }
  51. } else if (ope.equals("coursedel")) {
  52. // 课程删除
  53. String c = req.getParameter("course_id");
  54. String type = req.getParameter("type");
  55. int course_id = Integer.valueOf(c);
  56. CourseDao courseDao = new CourseDao();
  57. if (courseDao.DelCourse(course_id) == 1) {
  58. if (type.equals("admin")) {
  59. out.println("<script> alert('课程删除成功'); location='show_all_courses.jsp'; </script>");
  60. } else {
  61. out.println("<script> alert('课程删除成功'); location='my_courses.jsp'; </script>");
  62. }
  63. } else {
  64. if (type.equals("admin")) {
  65. out.println("<script> alert('课程删除失败'); location='show_all_courses.jsp'; </script>");
  66. } else {
  67. out.println("<script> alert('课程删除失败'); location='my_courses.jsp'; </script>");
  68. }
  69. }
  70. } else if (ope.equals("joindel")) {
  71. // 退出选课
  72. String c = req.getParameter("course_id");
  73. String user_id = req.getParameter("user_id");
  74. int course_id = Integer.valueOf(c);
  75. String from_ = req.getParameter("from_");
  76. JoinDao joinDao = new JoinDao();
  77. if (joinDao.Delete(course_id, user_id) == 1) {
  78. out.println("<script> alert('退出成功'); location='" + from_ + "'; </script>");
  79. } else {
  80. out.println("<script> alert('退出失败'); location='" + from_ + "'; </script>");
  81. }
  82. }
  83. }
  84. @Override
  85. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  86. super.doPost(req, resp);
  87. }
  88. }

LoginAction


  
  1. package com.sjsq.servlet;
  2. import com.sjsq.bean.User;
  3. import com.sjsq.dao.UserDao;
  4. import javax.servlet.ServletException;
  5. import javax.servlet.annotation.MultipartConfig;
  6. import javax.servlet.annotation.WebServlet;
  7. import javax.servlet.http.HttpServlet;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import java.io.IOException;
  11. import java.io.PrintWriter;
  12. import java.sql.SQLException;
  13. @WebServlet("/LoginAction")
  14. @MultipartConfig
  15. public class LoginAction extends HttpServlet {
  16. private static final long serialVersionUID = 1L;
  17. public LoginAction() {
  18. super();
  19. }
  20. @Override
  21. protected void doGet(HttpServletRequest req, HttpServletResponse resp)
  22. throws ServletException, IOException {
  23. resp.sendRedirect("login.jsp");
  24. }
  25. @Override
  26. protected void doPost(HttpServletRequest req, HttpServletResponse resp)
  27. throws ServletException, IOException {
  28. req.setCharacterEncoding("utf-8");
  29. resp.setContentType("text/html;charset=utf-8");
  30. PrintWriter out = resp.getWriter();
  31. String user_id = req.getParameter("inputUser_id"); // 从name属性中获取
  32. String userPass = req.getParameter("inputPassword");
  33. User user = new User();
  34. user.setId(user_id);
  35. user.setPassword(userPass);
  36. UserDao userDao = new UserDao();
  37. User user2;
  38. try {
  39. user2 = userDao.Query(user);
  40. } catch (SQLException e) {
  41. // TODO Auto-generated catch block
  42. e.printStackTrace();
  43. out.println("<script> alert('登陆失败'); location='login.jsp'; </script>");
  44. return;
  45. }
  46. if ((user2.getId()).equals("")) {
  47. // 用户不存在
  48. out.println("<script> alert('用户不存在'); location='login.jsp'; </script>");
  49. } else if (user2.getPassword().equals(userPass)) {
  50. // 登陆成功
  51. req.getSession(true).setAttribute("User", user2);
  52. out.println("<script> alert('登陆成功'); location='index.jsp'; </script>");
  53. } else {
  54. // 密码错误
  55. out.println("<script> alert('密码错误'); location='login.jsp'; </script>");
  56. }
  57. }
  58. }


LogoutAction


  
  1. package com.sjsq.servlet;
  2. import javax.servlet.ServletException;
  3. import javax.servlet.annotation.WebServlet;
  4. import javax.servlet.http.HttpServlet;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import javax.servlet.http.HttpSession;
  8. import java.io.IOException;
  9. @WebServlet("/LogoutAction")
  10. public class LogoutAction extends HttpServlet {
  11. private static final long serialVersionUID = 1L;
  12. public LogoutAction() {
  13. super();
  14. }
  15. @Override
  16. protected void doGet(HttpServletRequest req, HttpServletResponse resp)
  17. throws ServletException, IOException {
  18. HttpSession session = req.getSession(false);
  19. if (session == null) {
  20. resp.sendRedirect("login.jsp");
  21. return;
  22. }
  23. session.removeAttribute("User");
  24. resp.sendRedirect("login.jsp");
  25. }
  26. @Override
  27. protected void doPost(HttpServletRequest req, HttpServletResponse resp)
  28. throws ServletException, IOException {
  29. doGet(req, resp);
  30. }
  31. }


MulAction


  
  1. package com.sjsq.servlet;
  2. import com.sjsq.bean.Join;
  3. import com.sjsq.dao.CourseDao;
  4. import com.sjsq.dao.JoinDao;
  5. import com.sjsq.dao.SigninDao;
  6. import com.sjsq.dao.SigninStuDao;
  7. import javax.servlet.ServletException;
  8. import javax.servlet.annotation.MultipartConfig;
  9. import javax.servlet.annotation.WebServlet;
  10. import javax.servlet.http.HttpServlet;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletResponse;
  13. import java.io.IOException;
  14. import java.io.PrintWriter;
  15. @WebServlet("/MulAction")
  16. @MultipartConfig
  17. public class MulAction extends HttpServlet {
  18. /**
  19. *
  20. */
  21. private static final long serialVersionUID = 1L;
  22. @Override
  23. protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  24. req.setCharacterEncoding("utf-8");
  25. resp.setContentType("text/html;charset=utf-8");
  26. PrintWriter out = resp.getWriter();
  27. String ope = req.getParameter("ope");
  28. if (ope.equals("joincreat")) {
  29. String c = req.getParameter("course_id");
  30. String user_id = req.getParameter("user_id");
  31. int course_id = Integer.valueOf(c);
  32. Join join = new Join(course_id, user_id, "checking");
  33. JoinDao joinDao = new JoinDao();
  34. int result = joinDao.Creat(join);
  35. if (result == 2) {
  36. out.println("<script> alert('课程已经选过'); location='show_all_courses.jsp'; </script>");
  37. } else if (result == 1) {
  38. out.println("<script> alert('加入成功'); location='show_all_courses.jsp'; </script>");
  39. } else {
  40. out.println("<script> alert('加入失败'); location='show_all_courses.jsp'; </script>");
  41. }
  42. } else if (ope.equals("joinaccept")) {
  43. String c = req.getParameter("course_id");
  44. String user_id = req.getParameter("user_id");
  45. int course_id = Integer.valueOf(c);
  46. String from_ = req.getParameter("from_");
  47. JoinDao joinDao = new JoinDao();
  48. int result = joinDao.Update(course_id, user_id, "true");
  49. if (result == 1) {
  50. out.println("<script> alert('通过成功'); location='" + from_ + "'; </script>");
  51. } else {
  52. out.println("<script> alert('通过失败'); location='" + from_ + "'; </script>");
  53. }
  54. } else if (ope.equals("signincreat")) {
  55. String c = req.getParameter("course_id");
  56. int course_id = Integer.valueOf(c);
  57. String from_ = req.getParameter("from_");
  58. SigninDao signinDao = new SigninDao();
  59. int result = signinDao.Creat(course_id);
  60. if (result == 1) {
  61. SigninStuDao signinStuDao = new SigninStuDao();
  62. CourseDao courseDao = new CourseDao();
  63. int signin_id = signinDao.FindLast(course_id);
  64. signinStuDao.Creat(signin_id, course_id);
  65. courseDao.Update(course_id, "true");
  66. out.println("<script> alert('签到已开始'); location='" + from_ + "'; </script>");
  67. } else {
  68. out.println("<script> alert('开始失败'); location='" + from_ + "'; </script>");
  69. }
  70. } else if (ope.equals("signinstop")) {
  71. String c = req.getParameter("course_id");
  72. int course_id = Integer.valueOf(c);
  73. String from_ = req.getParameter("from_");
  74. CourseDao courseDao = new CourseDao();
  75. int result = courseDao.Update(course_id, "false");
  76. if (result == 1) {
  77. SigninDao signinDao = new SigninDao();
  78. signinDao.Update(signinDao.FindLast(course_id));
  79. out.println("<script> alert('签到已停止'); location='" + from_ + "'; </script>");
  80. } else {
  81. out.println("<script> alert('停止失败'); location='" + from_ + "'; </script>");
  82. }
  83. } else if (ope.equals("signin")) {
  84. String stu_id = req.getParameter("stu_id");
  85. String c = req.getParameter("signin_id");
  86. int signin_id = Integer.valueOf(c);
  87. String from_ = java.net.URLDecoder.decode(req.getParameter("from_"), "UTF-8");
  88. SigninStuDao signinStuDao = new SigninStuDao();
  89. int result = signinStuDao.Update(signin_id, stu_id, "true");
  90. if (result == 1) {
  91. SigninDao signinDao = new SigninDao();
  92. signinDao.AddNum(signin_id);
  93. out.println("<script> alert('签到成功'); location='" + from_ + "'; </script>");
  94. } else {
  95. out.println("<script> alert('签到失败'); location='" + from_ + "'; </script>");
  96. }
  97. }
  98. }
  99. }


RegisterAction


  
  1. package com.sjsq.servlet;
  2. import com.sjsq.bean.User;
  3. import com.sjsq.dao.UserDao;
  4. import javax.servlet.RequestDispatcher;
  5. import javax.servlet.ServletException;
  6. import javax.servlet.annotation.MultipartConfig;
  7. import javax.servlet.annotation.WebServlet;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import java.io.IOException;
  12. import java.io.PrintWriter;
  13. @WebServlet("/RegisterAction")
  14. @MultipartConfig
  15. public class RegisterAction extends HttpServlet {
  16. /**
  17. *
  18. */
  19. private static final long serialVersionUID = 1L;
  20. public RegisterAction() {
  21. super();
  22. }
  23. @Override
  24. protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  25. req.setCharacterEncoding("utf-8");
  26. RequestDispatcher rd = req.getRequestDispatcher("register.jsp");
  27. rd.forward(req, resp);
  28. }
  29. @Override
  30. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  31. req.setCharacterEncoding("utf-8");
  32. resp.setContentType("text/html;charset=utf-8");
  33. PrintWriter out = resp.getWriter();
  34. String user_id = req.getParameter("inputUser_id");
  35. String userPass = req.getParameter("inputPassword");
  36. String Confirm = req.getParameter("confirmPassword");
  37. String name = req.getParameter("inputName");
  38. String type = req.getParameter("type");
  39. int flag = 0;
  40. for (int i = 0; i < user_id.length(); i++) if (user_id.charAt(i) < '0' || user_id.charAt(i) > '9') flag++;
  41. if (flag != 0) {
  42. out.println("<script> alert('学号只能含有数字'); location='register.jsp'; </script>");
  43. } else if (!userPass.equals(Confirm)) {
  44. out.println("<script> alert('两次密码不相同'); location='register.jsp'; </script>");
  45. } else {
  46. User user = new User(user_id, userPass, name, type);
  47. UserDao userDao = new UserDao();
  48. int result = userDao.create(user);
  49. if (result == 1) {
  50. out.println("<script> alert('注册成功'); location='login.jsp'; </script>");
  51. } else {
  52. if (result == 0) out.println("<script> alert('注册失败'); location='register.jsp'; </script>");
  53. else out.println("<script> alert('该账号已被注册'); location='register.jsp'; </script>");
  54. }
  55. }
  56. }
  57. }


UpdateUserAction


  
  1. package com.sjsq.servlet;
  2. import com.sjsq.bean.User;
  3. import com.sjsq.dao.UserDao;
  4. import javax.servlet.ServletException;
  5. import javax.servlet.annotation.MultipartConfig;
  6. import javax.servlet.annotation.WebServlet;
  7. import javax.servlet.http.HttpServlet;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import javax.servlet.http.HttpSession;
  11. import java.io.IOException;
  12. import java.io.PrintWriter;
  13. import java.sql.SQLException;
  14. @WebServlet("/UpdateUserAction")
  15. @MultipartConfig
  16. public class UpdateUserAction extends HttpServlet {
  17. /**
  18. *
  19. */
  20. private static final long serialVersionUID = 1L;
  21. @Override
  22. protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  23. super.doGet(req, resp);
  24. }
  25. @Override
  26. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  27. req.setCharacterEncoding("utf-8");
  28. resp.setContentType("text/html;charset=utf-8");
  29. PrintWriter out = resp.getWriter();
  30. String oldPass = req.getParameter("oldPassword");
  31. String newPass = req.getParameter("newPassword");
  32. String Confirm = req.getParameter("confirmPassword");
  33. if (!newPass.equals(Confirm)) {
  34. out.println("<script> alert('两次密码不相同'); location='update_user.jsp'; </script>");
  35. } else {
  36. User user = (User) req.getSession().getAttribute("User");
  37. if (!user.getPassword().equals(oldPass)) {
  38. out.println("<script> alert('原密码错误'); location='update_user.jsp'; </script>");
  39. } else {
  40. UserDao userDao = new UserDao();
  41. int result = 0;
  42. try {
  43. result = userDao.Update(user.getId(), newPass);
  44. } catch (SQLException e) {
  45. // TODO Auto-generated catch block
  46. e.printStackTrace();
  47. }
  48. if (result == 1) {
  49. HttpSession session = req.getSession(false);
  50. session.removeAttribute("User");
  51. out.println("<script> alert('修改密码成功'); location='login.jsp'; </script>");
  52. resp.sendRedirect("login.jsp");
  53. } else {
  54. out.println("<script> alert('修改密码失败'); location='update_user.jsp'; </script>");
  55. resp.sendRedirect("update_user.jsp");
  56. }
  57. }
  58. }
  59. }
  60. }

四、其他

1.更多系统

Java+JSP系统系列实现

Java+JSP实现学生图书管理系统

Java+JSP实现学生信息管理系统

Java+JSP实现用户信息管理系统

Java+Servlet系统系列实现

Java+Servlet+JSP实现航空订票系统

Java+Servlet+JSP实现新闻发布系统

Java+Servlet+JSP学生宿舍管理系统

Java+Servlet+JSP实现图书管理系统

Java+Servlet+JSP实现停车场管理系统

Java+Servlet+JSP实现房屋租赁管理系统

Java+Servlet+JSP实现学生信息管理系统

Java+Servlet+JSP实现学生选课管理系统

Java+Servlet+JSP实现宠物诊所管理系统

Java+Servlet+JSP实现学生成绩管理系统-1

Java+Servlet+JSP实现学生成绩管理系统-2

Java+SSM系统系列实现

J​​​ava+SSM+JSP实现网上考试系统

Java+SSM+JSP实现宠物商城系统

Java+SSM+JSP实现超市管理系统

Java+SSM+JSP实现学生成绩管理系统

Java+SSM+JSP实现学生信息管理系统

Java+SSM+JSP+Maven实现网上书城系统

Java+SSM+JSP+Maven实现学校教务管理系统

Java+SSH系统系列实现

Java+SSH+JSP实现在线考试系统

Java+SSH+JSP实现医院在线挂号系统

Java+Springboot系统系列实现

Java+Springboot+H-ui+Maven实现营销管理系统

Java+Springboot+Bootstrap+Maven实现网上商城系统

Java+Springboot+Bootstrap+Maven实现景区旅游管理系统

1.更多JavaWeb系统请关注专栏。

https://blog.csdn.net/helongqiang/category_10020130.htmlhttps://blog.csdn.net/helongqiang/category_10020130.html

2.更多JavaSwing系统请关注专栏。

https://blog.csdn.net/helongqiang/category_6229101.htmlhttps://blog.csdn.net/helongqiang/category_6229101.html

2.源码下载

sql在sql文件夹下面

Java+Servlet+JSP+Mysql实现Web学生选课签到系统

3.备注

如有侵权请联系我删除。

4.支持博主

如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!想要获取其他资源可关注左侧微信公众号获取!

文章来源: blog.csdn.net,作者:水坚石青,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/helongqiang/article/details/122132170

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。