首页 > 其他分享 >学生选课系统之系统管理员功能的实现

学生选课系统之系统管理员功能的实现

时间:2022-11-12 22:02:11浏览次数:44  
标签:选课 系统管理员 resp req 学生 org import servlet javax

系统管理员(MyBatis版,有两个.xml文件,不要忘记配置呀!)

新增学生信息

addStudent.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 12140
  Date: 2022/11/11
  Time: 14:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加学生信息</title>
</head>
<body>
<center>
    <form action="addStudent1" method="post">
        <table border="1">
            <caption><h1>新添学生信息</h1></caption>
            <tr>
                <td>学生姓名:</td>
                <td><input type="text" name="name" id="name"></td>
            </tr>
            <tr>
                <td>性别:</td>
                <td><input type="radio" name="sex" value="男">男
                    <input type="radio" name="sex" value="女">女</td>
            </tr>
            <tr>
                <td>年龄:</td>
                <td><input type="text" name="age" id="age"></td>
            </tr>
            <tr>
                <td>专业</td>
                <td>
                    <input type="radio" name="major" value="计算机科学与技术">计算机科学与技术
                    <input type="radio" name="major" value="软件工程">软件工程
                    <input type="radio" name="major" value="网络工程">网络工程
                    <input type="radio" name="major" value="数字媒体技术">数字媒体技术

                </td>
            </tr>
            <tr>
                <td>班级:</td>
                <td><input type="text" name="ban" id="ban"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="添加"></td>
            </tr>
        </table>
    </form>
</center>
</body>
</html>

addStudent1.java(执行完添加操作,会直接跳转回登录界面,有点小麻烦)

package org.example.Servlet;

import org.example.Bean.user;
import org.example.Service.userService;

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;

@WebServlet("/addStudent1")
public class addStudent1 extends HttpServlet {
    private userService us=new userService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");

        resp.setContentType("text/html;charset=utf-8");

        String name=req.getParameter("name");
        String sex=req.getParameter("sex");
        String age1=req.getParameter("age");
        int age=Integer.parseInt(age1);
        String major=req.getParameter("major");
        String ban=req.getParameter("ban");

        user u=new user();

        u.setName(name);
        u.setSex(sex);
        u.setAge(age);
        u.setMajor(major);
        u.setBan(ban);

        us.addStudent(u);
        req.getRequestDispatcher("index.jsp").forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}

新增教师信息的功能同上述结构,自行更改即可

删除学生信息/修改学生信息(由于本人比较懒,就将删除和修改的前两个步骤共用一个啦!)

(共用)deleteStudent1.java

package org.example.Servlet;

import org.example.Bean.teacher;
import org.example.Bean.user;
import org.example.Service.userService;

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.util.List;

@WebServlet("/deleteStudent1")
public class deleteStudent1 extends HttpServlet {
    private userService us=new userService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        List<user> list=us.lookThem1();

        req.setAttribute("list",list);
        req.getRequestDispatcher("lookAllStudent.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}

(共用)lookAllStudent.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 12140
  Date: 2022/11/11
  Time: 16:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>浏览全部学生界面</title>
</head>
<body>
<center>
    <form>
        <table border="1">
            <tr>
                <td>学生学号</td>
                <td>姓名</td>
                <td>性别</td>
                <td>年龄</td>
                <td>专业</td>
                <td>班级</td>
                <td>操作</td>
            </tr>
            <c:forEach items="${list}" var="tt">
                <tr>
                    <td>${tt.id}</td>
                    <td>${tt.name}</td>
                    <td>${tt.sex}</td>
                    <td>${tt.age}</td>
                    <td>${tt.major}</td>
                    <td>${tt.ban}</td>
                    <td><a href="deleteStudent2?id=${tt.id}">删除</a>
                        <a href="updateStudent1?id=${tt.id}">修改</a>
                    </td>
                </tr>
            </c:forEach>
        </table>
    </form>
</center>
</body>
</html>

(删除)deleteStudent2.java

package org.example.Servlet;

import org.example.Service.userService;

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;

@WebServlet("/deleteStudent2")
public class deleteStudent2 extends HttpServlet {
    private userService us=new userService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String id1=req.getParameter("id");
        int id=Integer.parseInt(id1);
        us.deleteStudentInformation(id);

        req.getRequestDispatcher("index.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}

(修改)updateStudent1.java

package org.example.Servlet;

import org.example.Bean.teacher;
import org.example.Bean.user;
import org.example.Service.userService;

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;

@WebServlet("/updateStudent1")
public class updateStudent1 extends HttpServlet {
    private userService us=new userService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String id1=req.getParameter("id");
        int id=Integer.parseInt(id1);

 HttpSession session=req.getSession();
        session.setAttribute("id",id);

        user u=us.getAllInformation(id);
        req.setAttribute("u",u);
        req.getRequestDispatcher("updateStudent1.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}

(修改)updateStudent1.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 12140
  Date: 2022/11/11
  Time: 16:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改学生信息界面</title>
</head>
<body>
<center>
    <form action="updateStudent2" method="post">
        <table border="1">
            <input type="hidden" name="id" value="${u.id}">
            <tr>
                <td>学生姓名:</td>
                <td><input type="text" name="name" value="${u.name}"></td>
            </tr>
            <tr>
                <td>性别:</td>
                <td><input type="radio" name="sex" value="男" <c:if test="${u.sex eq '男'}"> checked="checked"</c:if>>男
                    <input type="radio" name="sex" value="女" <c:if test="${u.sex eq '女'}"> checked="checked"</c:if>>女
                </td>
            </tr>
            <tr>
                <td>年龄:</td>
                <td><input type="text" name="age" value="${u.age}"></td>
            </tr>
            <tr>
                <td>专业</td>
                <td>
                    <input type="radio" name="major" value="计算机科学与技术" <c:if test="${u.major eq '计算机科学与技术'}"> checked="checked"</c:if>>计算机科学与技术
                    <input type="radio" name="major" value="软件工程" <c:if test="${u.major eq '软件工程'}"> checked="checked"</c:if>>软件工程
                    <input type="radio" name="major" value="网络工程" <c:if test="${u.major eq '网络工程'}"> checked="checked"</c:if>>网络工程
                    <input type="radio" name="major" value="数字媒体技术" <c:if test="${u.major eq '数字媒体技术'}"> checked="checked"</c:if>>数字媒体技术
                </td>

                </td>
            </tr>
            <tr>
                <td>班级:</td>
                <td><input type="text" name="ban" value="${u.ban}"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="修改"></td>
            </tr>
        </table>
    </form>
</center>
</body>
</html>

(修改)updateStudent2.java

package org.example.Servlet;

import org.example.Bean.user;
import org.example.Service.userService;

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("/updateStudent2")
public class updateStudent2 extends HttpServlet {
    private userService us=new userService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

       HttpSession session =req.getSession();

        int id=(int)session.getAttribute("id");


            String name = req.getParameter("name");
            String sex = req.getParameter("sex");
            String age1 = req.getParameter("age");
            int age = Integer.parseInt(age1);
            String major = req.getParameter("major");
            String ban = req.getParameter("ban");


        user u=new user();
        u.setId(id);
        u.setName(name);
        u.setSex(sex);
        u.setAge(age);
        u.setMajor(major);
        u.setBan(ban);

        us.updatePersonal1(u);

        req.getRequestDispatcher("index.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}

学生密码重置

makeNew2.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学生密码重置</title>
</head>
<body>
<center>
    <form action="makeNew4" method="post">
        <table border="1">
            <tr>
                <td>请输入学生学号:</td>
                <td><input type="text" name="id"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="确认"></td>
            </tr>
        </table>
    </form>
</center>
</body>
</html>

makeNew4.java

package org.example.Servlet;

import org.example.Bean.teacherAdmin;
import org.example.Bean.userAdmin;
import org.example.Service.userService;

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("/makeNew4")
public class makeNew4 extends HttpServlet {
    private userService us=new userService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String id1=req.getParameter("id");
        int id=Integer.parseInt(id1);
        HttpSession session=req.getSession();

        session.setAttribute("id",id);

        userAdmin u=new userAdmin();
        u.setId(id);
        u.setPassword("123456");

        us.updatePasswordStudent(u);


        req.getRequestDispatcher("index.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}

教师密码重置也是这样一个操作,可以将这个做个参考,将教师的做出来奥!

之后的还有新添课程信息、修改课程信息和删除课程信息,是最基本的增删改查了,就不列出来啦!

标签:选课,系统管理员,resp,req,学生,org,import,servlet,javax
From: https://www.cnblogs.com/liuzijin/p/16884290.html

相关文章