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

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: IDEA+Java+Servlet+JSP+Mysql实现学生选课签到系统

DeleteAction

package com.sjsq.servlet;
import com.sjsq.dao.CourseDao;
import com.sjsq.dao.JoinDao;
import com.sjsq.dao.UserDao;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
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;
import java.sql.SQLException;
@WebServlet("/DeleteAction")
@MultipartConfig
public class DeleteAction extends HttpServlet {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        String ope = req.getParameter("ope");
        if (ope.equals("userdel")) {
            // 删除用户
            String user_id = req.getParameter("user_id");
            UserDao userDao = new UserDao();
            if (userDao.DelUser(user_id) == 1) {
                out.println("<script> alert('删除成功'); location='toaudit.jsp'; </script>");
            } else {
                out.println("<script> alert('删除失败'); location='toaudit.jsp'; </script>");
            }
        } else if (ope.equals("useradd")) {
            // 用户审核
            String user_id = req.getParameter("user_id");
            UserDao userDao = new UserDao();
            try {
                if (userDao.Check(user_id) == 1) {
                    out.println("<script> alert('审核通过'); location='toaudit.jsp'; </script>");
                } else {
                    out.println("<script> alert('操作失败'); location='toaudit.jsp'; </script>");
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                out.println("<script> alert('操作失败'); location='toaudit.jsp'; </script>");
            }
        } else if (ope.equals("coursedel")) {
            // 课程删除
            String c = req.getParameter("course_id");
            String type = req.getParameter("type");
            int course_id = Integer.valueOf(c);
            CourseDao courseDao = new CourseDao();
            if (courseDao.DelCourse(course_id) == 1) {
                if (type.equals("admin")) {
                    out.println("<script> alert('课程删除成功'); location='show_all_courses.jsp'; </script>");
                } else {
                    out.println("<script> alert('课程删除成功'); location='my_courses.jsp'; </script>");
                }
            } else {
                if (type.equals("admin")) {
                    out.println("<script> alert('课程删除失败'); location='show_all_courses.jsp'; </script>");
                } else {
                    out.println("<script> alert('课程删除失败'); location='my_courses.jsp'; </script>");
                }
            }
        } else if (ope.equals("joindel")) {
            // 退出选课
            String c = req.getParameter("course_id");
            String user_id = req.getParameter("user_id");
            int course_id = Integer.valueOf(c);
            String from_ = req.getParameter("from_");
            JoinDao joinDao = new JoinDao();
            if (joinDao.Delete(course_id, user_id) == 1) {
                out.println("<script> alert('退出成功'); location='" + from_ + "'; </script>");
            } else {
                out.println("<script> alert('退出失败'); location='" + from_ + "'; </script>");
            }
        }
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}

LoginAction

package com.sjsq.servlet;
import com.sjsq.bean.User;
import com.sjsq.dao.UserDao;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
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;
import java.sql.SQLException;
@WebServlet("/LoginAction")
@MultipartConfig
public class LoginAction extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public LoginAction() {
        super();
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        resp.sendRedirect("login.jsp");
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        String user_id = req.getParameter("inputUser_id");   // 从name属性中获取
        String userPass = req.getParameter("inputPassword");
        User user = new User();
        user.setId(user_id);
        user.setPassword(userPass);
        UserDao userDao = new UserDao();
        User user2;
        try {
            user2 = userDao.Query(user);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            out.println("<script> alert('登陆失败'); location='login.jsp'; </script>");
            return;
        }
        if ((user2.getId()).equals("")) {
            // 用户不存在
            out.println("<script> alert('用户不存在'); location='login.jsp'; </script>");
        } else if (user2.getPassword().equals(userPass)) {
            // 登陆成功
            req.getSession(true).setAttribute("User", user2);
            out.println("<script> alert('登陆成功'); location='index.jsp'; </script>");
        } else {
            // 密码错误
            out.println("<script> alert('密码错误'); location='login.jsp'; </script>");
        }
    }
}

LogoutAction

package com.sjsq.servlet;
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;
@WebServlet("/LogoutAction")
public class LogoutAction extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public LogoutAction() {
        super();
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        HttpSession session = req.getSession(false);
        if (session == null) {
            resp.sendRedirect("login.jsp");
            return;
        }
        session.removeAttribute("User");
        resp.sendRedirect("login.jsp");
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        doGet(req, resp);
    }
}

MulAction

package com.sjsq.servlet;
import com.sjsq.bean.Join;
import com.sjsq.dao.CourseDao;
import com.sjsq.dao.JoinDao;
import com.sjsq.dao.SigninDao;
import com.sjsq.dao.SigninStuDao;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
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("/MulAction")
@MultipartConfig
public class MulAction extends HttpServlet {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        String ope = req.getParameter("ope");
        if (ope.equals("joincreat")) {
            String c = req.getParameter("course_id");
            String user_id = req.getParameter("user_id");
            int course_id = Integer.valueOf(c);
            Join join = new Join(course_id, user_id, "checking");
            JoinDao joinDao = new JoinDao();
            int result = joinDao.Creat(join);
            if (result == 2) {
                out.println("<script> alert('课程已经选过'); location='show_all_courses.jsp'; </script>");
            } else if (result == 1) {
                out.println("<script> alert('加入成功'); location='show_all_courses.jsp'; </script>");
            } else {
                out.println("<script> alert('加入失败'); location='show_all_courses.jsp'; </script>");
            }
        } else if (ope.equals("joinaccept")) {
            String c = req.getParameter("course_id");
            String user_id = req.getParameter("user_id");
            int course_id = Integer.valueOf(c);
            String from_ = req.getParameter("from_");
            JoinDao joinDao = new JoinDao();
            int result = joinDao.Update(course_id, user_id, "true");
            if (result == 1) {
                out.println("<script> alert('通过成功'); location='" + from_ + "'; </script>");
            } else {
                out.println("<script> alert('通过失败'); location='" + from_ + "'; </script>");
            }
        } else if (ope.equals("signincreat")) {
            String c = req.getParameter("course_id");
            int course_id = Integer.valueOf(c);
            String from_ = req.getParameter("from_");
            SigninDao signinDao = new SigninDao();
            int result = signinDao.Creat(course_id);
            if (result == 1) {
                SigninStuDao signinStuDao = new SigninStuDao();
                CourseDao courseDao = new CourseDao();
                int signin_id = signinDao.FindLast(course_id);
                signinStuDao.Creat(signin_id, course_id);
                courseDao.Update(course_id, "true");
                out.println("<script> alert('签到已开始'); location='" + from_ + "'; </script>");
            } else {
                out.println("<script> alert('开始失败'); location='" + from_ + "'; </script>");
            }
        } else if (ope.equals("signinstop")) {
            String c = req.getParameter("course_id");
            int course_id = Integer.valueOf(c);
            String from_ = req.getParameter("from_");
            CourseDao courseDao = new CourseDao();
            int result = courseDao.Update(course_id, "false");
            if (result == 1) {
                SigninDao signinDao = new SigninDao();
                signinDao.Update(signinDao.FindLast(course_id));
                out.println("<script> alert('签到已停止'); location='" + from_ + "'; </script>");
            } else {
                out.println("<script> alert('停止失败'); location='" + from_ + "'; </script>");
            }
        } else if (ope.equals("signin")) {
            String stu_id = req.getParameter("stu_id");
            String c = req.getParameter("signin_id");
            int signin_id = Integer.valueOf(c);
            String from_ = java.net.URLDecoder.decode(req.getParameter("from_"), "UTF-8");
            SigninStuDao signinStuDao = new SigninStuDao();
            int result = signinStuDao.Update(signin_id, stu_id, "true");
            if (result == 1) {
                SigninDao signinDao = new SigninDao();
                signinDao.AddNum(signin_id);
                out.println("<script> alert('签到成功'); location='" + from_ + "'; </script>");
            } else {
                out.println("<script> alert('签到失败'); location='" + from_ + "'; </script>");
            }
        }
    }
}

RegisterAction

package com.sjsq.servlet;
import com.sjsq.bean.User;
import com.sjsq.dao.UserDao;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
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("/RegisterAction")
@MultipartConfig
public class RegisterAction extends HttpServlet {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    public RegisterAction() {
        super();
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        RequestDispatcher rd = req.getRequestDispatcher("register.jsp");
        rd.forward(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        String user_id = req.getParameter("inputUser_id");
        String userPass = req.getParameter("inputPassword");
        String Confirm = req.getParameter("confirmPassword");
        String name = req.getParameter("inputName");
        String type = req.getParameter("type");
        int flag = 0;
        for (int i = 0; i < user_id.length(); i++) if (user_id.charAt(i) < '0' || user_id.charAt(i) > '9') flag++;
        if (flag != 0) {
            out.println("<script> alert('学号只能含有数字'); location='register.jsp'; </script>");
        } else if (!userPass.equals(Confirm)) {
            out.println("<script> alert('两次密码不相同'); location='register.jsp'; </script>");
        } else {
            User user = new User(user_id, userPass, name, type);
            UserDao userDao = new UserDao();
            int result = userDao.create(user);
            if (result == 1) {
                out.println("<script> alert('注册成功'); location='login.jsp'; </script>");
            } else {
                if (result == 0) out.println("<script> alert('注册失败'); location='register.jsp'; </script>");
                else out.println("<script> alert('该账号已被注册'); location='register.jsp'; </script>");
            }
        }
    }
}

UpdateUserAction

package com.sjsq.servlet;
import com.sjsq.bean.User;
import com.sjsq.dao.UserDao;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
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.sql.SQLException;
@WebServlet("/UpdateUserAction")
@MultipartConfig
public class UpdateUserAction extends HttpServlet {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        String oldPass = req.getParameter("oldPassword");
        String newPass = req.getParameter("newPassword");
        String Confirm = req.getParameter("confirmPassword");
        if (!newPass.equals(Confirm)) {
            out.println("<script> alert('两次密码不相同'); location='update_user.jsp'; </script>");
        } else {
            User user = (User) req.getSession().getAttribute("User");
            if (!user.getPassword().equals(oldPass)) {
                out.println("<script> alert('原密码错误'); location='update_user.jsp'; </script>");
            } else {
                UserDao userDao = new UserDao();
                int result = 0;
                try {
                    result = userDao.Update(user.getId(), newPass);
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                if (result == 1) {
                    HttpSession session = req.getSession(false);
                    session.removeAttribute("User");
                    out.println("<script> alert('修改密码成功'); location='login.jsp'; </script>");
                    resp.sendRedirect("login.jsp");
                } else {
                    out.println("<script> alert('修改密码失败'); location='update_user.jsp'; </script>");
                    resp.sendRedirect("update_user.jsp");
                }
            }
        }
    }
}


四、其他


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系统系列实现

Java+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.html

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


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


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

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


2.源码下载

sql在sql文件夹下面


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


3.备注

如有侵权请联系我删除。


4.支持博主

如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!


相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
4月前
|
Java
使用IDEA创建项目运行我的第一个JAVA文件输出Helloword
本文介绍了如何使用IDEA(IntelliJ IDEA)创建一个新的Java项目,并运行一个简单的Java程序输出"Hello Word"。文章详细展示了创建项目的步骤,包括选择JDK版本、设置项目名称和路径、创建包和类,以及编写和运行代码。最后,还展示了如何通过IDEA的运行功能来执行程序并查看输出结果。
223 4
使用IDEA创建项目运行我的第一个JAVA文件输出Helloword
|
3月前
|
关系型数据库 MySQL Java
【IDEA】java后台操作mysql数据库驱动常见错误解决方案
【IDEA】java后台操作mysql数据库驱动常见错误解决方案
140 0
|
3月前
|
Oracle IDE Java
IDEA安装教程配置java环境(超详细)
IDEA安装教程配置java环境(超详细)
1791 1
|
5月前
|
存储 缓存 前端开发
Servlet与JSP在Java Web应用中的性能调优策略
Servlet与JSP在Java Web应用中的性能调优策略
51 1
|
5月前
|
Java Android开发
如何使用IDEA创建一个简单的java工程?
这篇文章提供了使用IntelliJ IDEA创建简单Java工程的步骤,包括在`src`目录下建立两个特定的包。
如何使用IDEA创建一个简单的java工程?
|
5月前
|
IDE Java 测试技术
Java零基础(4) - JDK、IntelliJ IDEA的安装和环境变量配置
【8月更文挑战第4天】🏆本文收录于「滚雪球学Java」专栏,专业攻坚指数级提升,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家关注&&收藏&&订阅!持续更新中,up!up!up!!
163 0
Java零基础(4) - JDK、IntelliJ IDEA的安装和环境变量配置
|
5月前
|
存储 Java 关系型数据库
基于Servlet和JSP的Java Web应用开发指南
基于Servlet和JSP的Java Web应用开发指南
132 0
|
6月前
|
Java Spring
idea新建spring boot 项目右键无package及java类的选项
idea新建spring boot 项目右键无package及java类的选项
258 5
|
6月前
|
Java
关于idea报错:Cannot determine path to 'tools.jar' library for 17 (E:\java-jdk\jdk17)的解决办法
关于idea报错:Cannot determine path to 'tools.jar' library for 17 (E:\java-jdk\jdk17)的解决办法
|
6月前
|
JSON Java Maven
几个适合Java开发者的免费IDEA插件
【7月更文挑战第15天】以下是适合Java开发者的免费IDEA插件: - **Test Data**: 生成用于单元测试的随机数据,支持多种格式如JSON、CSV等。 - **SonarLint**: 实时检测并修正代码质量问题,提供详细的风险分析。 - **Maven Helper**: 提供pom.xml文件的UI界面,便于管理Maven项目依赖。 - **RestFulTool**: 辅助RESTful服务开发与测试,尤其适合Spring MVC和Spring Boot项目。 - **EnvFile**: 在IDE内部设置运行配置的环境变量,支持YAML、JSON等格式。
133 2