首页 > 其他分享 >学生选课系统之教师功能的实现

学生选课系统之教师功能的实现

时间:2022-11-12 22:34:42浏览次数:44  
标签:教师 http 选课 resp req 学生 import servlet javax

教师(MyBatis版)

查看个人信息(该功能主要是依靠session实现的,也算是远程传送数据吧)

根据教师id(唯一性)进行查询自己的基本信息,用类封装,然后再传递到jsp页面。输出即可

teacherLookInformation.java

package org.example.Servlet;

import org.example.Bean.teacher;
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("/teacherLookInformation")
public class teacherLookInformation 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");

        teacher t=us.getIt(id);

        req.setAttribute("t",t);

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

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

showTeacher.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>查看个人信息</title>
</head>
<body>
<center>
  <form>
      <table border="1">
          <tr>
              <td>教师工号</td> <td>${t.idT}</td>
          </tr>
          <tr>
              <td>姓名</td> <td>${t.name}</td>
          </tr>
          <tr>
              <td>职称</td> <td>${t.zhiCheng}</td>
          </tr>
          <tr>
              <td>院系</td> <td>${t.yuan}</td>
          </tr>
      </table>
  </form>
</center>
</body>
</html>

修改个人基本信息

先查询到自己的个人信息,然后传递到jsp页面,使用数据回显,将不允许修改的数据disabled一下,就改成了只读,其余改完之后,点击修改按钮就可以啦!

updatePersonal1.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 javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/updatePersonal3")
public class updatePersonal3 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();

        String password=(String)session.getAttribute("password");

        int idT=us.getIDFromTeacher(password);

        session.setAttribute("idT",idT);
        teacher t=us.getIt(idT);

        req.setAttribute("t",t);
        req.getRequestDispatcher("updatePersonal2.jsp").forward(req,resp);
    }

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

updatePersonal2.jsp(修改个人信息界面)

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 12140
  Date: 2022/11/11
  Time: 17:01
  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="updateTeacher2" method="post">
        <table border="1">
            <input type="hidden" name="idT" value="${t.idT}">
            <tr>
                <td>姓名:</td>
                <td><input type="text" name="name" value="${t.name}"></td>
            </tr>
            <tr>
                <td>职称:</td>
                <td><input type="radio" name="zhiCheng" value="助教"  <c:if test="${t.zhiCheng eq '助教'}"> checked="checked"</c:if>>助教
                    <input type="radio" name="zhiCheng" value="讲师"  <c:if test="${t.zhiCheng eq '讲师'}"> checked="checked"</c:if>>讲师
                    <input type="radio" name="zhiCheng" value="副教授"  <c:if test="${t.zhiCheng eq '副教授'}"> checked="checked"</c:if>>副教授
                    <input type="radio" name="zhiCheng" value="教授"  <c:if test="${t.zhiCheng eq '教授'}"> checked="checked"</c:if>>教授
                </td>
            </tr>
            <tr>
                <td>所属学院:</td>
                <td>
                    <input type="radio" name="yuan" value="信息"  <c:if test="${t.yuan eq '信息'}"> checked="checked"</c:if>>信息
                    <input type="radio" name="yuan" value="土木"  <c:if test="${t.yuan eq '土木'}"> checked="checked"</c:if>>土木
                    <input type="radio" name="yuan" value="机械"  <c:if test="${t.yuan eq '机械'}"> checked="checked"</c:if>>机械
                    <input type="radio" name="yuan" value="电气"  <c:if test="${t.yuan eq '电气'}"> checked="checked"</c:if>>电气
                    <input type="radio" name="yuan" value="交通"  <c:if test="${t.yuan eq '交通'}"> checked="checked"</c:if>>交通
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="修改"></td>
            </tr>
        </table>
    </form>
</center>
</body>
</html>

updateTeacher2.java(修改操作实现界面)

package org.example.Servlet;

import org.example.Bean.teacher;
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("/updateTeacher2")
public class updateTeacher2 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 idT=(int)session.getAttribute("idT");

        String name=req.getParameter("name");
        String zhiCheng=req.getParameter("zhiCheng");
        String yuan=req.getParameter("yuan");

        teacher t=new teacher();
        t.setIdT(idT);
        t.setName(name);
        t.setZhiCheng(zhiCheng);
        t.setYuan(yuan);

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

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

修改个人密码

很怯的密码修改,建议使用下面那种方式哦!(这个使用的是数据回显)

password4.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("/password4")
public class password4 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");

        teacherAdmin u=us.getIt1(id);

        req.setAttribute("u",u);
        req.getRequestDispatcher("password5.jsp").forward(req,resp);

    }

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

password5.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改密码界面</title>
</head>
<body>
<center>
    <form action="password6" method="post">
        <table border="1">
            <input type="hidden" name="id" value="${u.id}">
            <tr>
                <td>请输入你想要的新密码:</td>
                <td><input type="text" name="password" value="${u.password}"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="修改"></td>
            </tr>
        </table>
    </form>
</center>
</body>
</html>

password6.java

package org.example.Servlet;

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 java.io.IOException;

@WebServlet("/password6")
public class password6 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 password=req.getParameter("password");

        userAdmin u=new userAdmin();
        u.setPassword(password);

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

    }

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

这个里面的修改密码界面是利用数据回显实现的,之前的房产管理系统里面的修改密码的操作是用旧密码和新密码来实现的,下面的方式就是那种方式:

修改密码:

updateAgentPassword.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>房产经纪修改密码界面</title>
</head>
<body>
<center>
    <form action="updateAgentPassword" method="post">
        <table border="1">
            <tr>
                <td>旧密码:</td>
                <td><input type="text" name="oldPass" id="oldPass"></td>
            </tr>
            <tr>
                <td>新密码:</td>
                <td><input type="password" name="newPassOne" id="newPassOne"></td>
            </tr>
            <tr>
                <td>请再次确认新密码:</td>
                <td><input type="password" name="newPassTwo" id="newPassTwo" onkeyup="checkPass()"><span id="clue"></span></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" id="submit" value="修改"></td>
            </tr>
        </table>
    </form>
    <%--判断两次输入的新密码是否一致--%>
    <script>
        function checkPass(){
            var newPassOne=document.getElementById("newPassOne").value;
            var newPassTwo=document.getElementById("newPassTwo").value;

            if(newPassOne==""||newPassTwo==""){
                document.getElementById("clue").innerHTML="<font color=red>密码不能空</font>"
                document.getElementById("submit").disabled=true;
            }else{
                if(newPassOne==newPassTwo){
                    document.getElementById("clue").innerHTML="<font color=green>密码一致</font>"
                    document.getElementById("submit").disabled=false;
                }else{
                    document.getElementById("clue").innerHTML="<font color=red>密码不一致</font>"
                    document.getElementById("submit").disabled=true;
                }
            }

        }
    </script>
</center>
</body>
</html>

updateAgentPassword.java

package org.example.Servlet;

import org.example.Bean.agentAdmin;
import org.example.Bean.userAdmin;
import org.example.Service.HouseService;

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

        String oldPass=req.getParameter("oldPass");
        int m=hs.selectUserPassword(oldPass);
        if(m==1) {
            String newPassOne = req.getParameter("newPassOne");

            HttpSession session = req.getSession();

            String agentID = (String) session.getAttribute("agentID");

            agentAdmin aa = new agentAdmin();
            aa.setAgentID(agentID);
            aa.setAgentPassword(newPassOne);

            hs.updateThePasswordAgent(aa);

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

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

修改个人所授课的限制人数

将本人所授课遍历出来,点击每一条数据后面的修改,就可以跳到那条数据的修改界面,点击修改即可

teacherUpdatePerson.java

package org.example.Servlet;

import org.example.Bean.ke;
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;
import java.util.List;

@WebServlet("/teacherUpdatePerson")
public class teacherUpdatePerson 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");

        List<ke> list=us.getBasic2(id);

        req.setAttribute("list",list);

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

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

teacherUpdatePerson2.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 12140
  Date: 2022/11/12
  Time: 11:08
  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>
            </tr>
            <c:forEach items="${list}" var="ke">
                <tr>
                    <td>${ke.className}</td>
                    <td>${ke.startTime}</td>
                    <td>${ke.startNum}</td>
                    <td>${ke.kPerson}</td>
                    <td><a href="teacherUpdatePerson3?idK=${ke.idK}">修改</a></td>
                </tr>
            </c:forEach>
        </table>
    </form>
</center>
</body>
</html>

teacherUpdatePerson3.java

package org.example.Servlet;

import org.example.Bean.ke;
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("/teacherUpdatePerson3")
public class teacherUpdatePerson3 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 idK1=req.getParameter("idK");
        int idK=Integer.parseInt(idK1);

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

        ke k=us.getOne(idK);


        req.setAttribute("k",k);
        req.getRequestDispatcher("teacherUpdatePerson4.jsp").forward(req,resp);
    }

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

teacherUpdatePerson4.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改界面</title>
</head>
<body>
<center>
    <form action="teacherUpdateClass5" method="post">
        <table border="1">
            <tr>
                <td>课程名称:</td>
                <td><input type="text" name="className" value="${k.className}" disabled></td>
            </tr>
            <tr>
                <td>开课节次:</td>
                <td><input type="text" name="startNum" value="${k.startNum}" disabled></td>
            </tr>
            <tr>
                <td>开课时间:</td>
                <td><input type="text" name="startTime" value="${k.startTime}" disabled></td>
            </tr>
            <tr>
                <td>选课限制人数:</td>
                <td><input type="text" name="kPerson" value="${k.kPerson}"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="修改"></td>
            </tr>

        </table>
    </form>
</center>
</body>
</html>

teacherUpdatePerson5.java

package org.example.Servlet;

import org.example.Bean.ke;
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 javax.swing.*;
import java.io.IOException;

@WebServlet("/teacherUpdateClass5")
public class teacherUpdateClass5 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 idK=(int)session.getAttribute("idK");

        String kPerson1=req.getParameter("kPerson");
        int kPerson=Integer.parseInt(kPerson1);

        ke k=new ke();

        k.setIdK(idK);
        k.setkPerson(kPerson);

        us.updatePersonNum1(k);

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

    }

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

查询个人课表

根据自己的教师id查询list集合的数据,直接在下一个jsp页面显示出来即可

teacherCheckPersonalClass.java

package org.example.Servlet;

import org.example.Bean.ke;
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;
import java.util.List;

@WebServlet("/teacherCheckPersonalClass")
public class teacherCheckPersonalClass 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");

        List<ke> list=us.getBasic2(id);

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

    }

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

teacherCheckPersonalClass.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 12140
  Date: 2022/11/12
  Time: 11:00
  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>
            </tr>
            <c:forEach items="${list}" var="ke">
                <tr>
                    <td>${ke.className}</td>
                    <td>${ke.startTime}</td>
                    <td>${ke.startNum}</td>
                    <td>${ke.kPerson}</td>
                </tr>
            </c:forEach>
        </table>
    </form>
</center>
</body>
</html>

标签:教师,http,选课,resp,req,学生,import,servlet,javax
From: https://www.cnblogs.com/liuzijin/p/16884798.html

相关文章

  • 学生选课系统之系统管理员功能的实现
    系统管理员(MyBatis版,有两个.xml文件,不要忘记配置呀!)新增学生信息addStudent.jsp<%@taglibprefix="c"uri="http://java.sun.com/jsp/jstl/core"%><%--Createdby......
  • 学生成绩管理系统(实验四)
    /*1.学生成绩管理系统V1.0某班有最多不超过40人(具体人数由键盘输入)参加某门课程的考试,用数组作函数参数编程实现如下学生成绩管理:(1)录入每个学生的学号和考试成绩;(2)计算课......
  • 使用JFinal实现简单的学生管理系统
    JFinal简介Controller是JFinal核按心类美之一,该类作为MVC模式中的控制器。基于JFinal的Web应用的控制器需要继承该类。Controller是定义Action方法的地点,是组织Action的一......
  • 体验《论语》:一种以体验游戏为基础的学习方法,促进学生的学习动机和学习观念
    体验《论语》:一种以体验游戏为基础的学习方法,促进学生的学习动机和学习观念(ExperiencingtheAnalectsofConfucius:Anexperientialgame-basedlearning approacht......
  • 《分级考试》——学生选课管理系统的相关总结
    考试感言就这么说吧,那些功能,我都会,但是就是手打代码的速度不太行,导致任务并没有完成,没有达到理想的效果。有很强的挫败感啊!我之前一直认为,只要将逻辑思路练会就行,代码速......
  • 一个简单的查询学生信息的接口测试
    Test作业提交学习笔记编写一个业务接口(登录,查找学生等)打包成jar包在本机上面执行相应的命令,通过浏览器访问接口获得数据。(可选)将该jar包放在服务器上面运行,通......
  • 选课系统思路总结
    选课系统总结管理员系统检验用户是否登录装饰器1.添加全局变量2.有参装饰器判断身份管理员创建学校第一层 获取想要创建的学校信息调用第二层接口传(学......
  • 学生之家-6道练习题
    让用户输入一个数判断其是奇数还是偶数并把结果输出输入一个溶液的ph值试判断该溶液是酸性还是碱性或是中性溶液并把结果输出(常温25℃条件下)给定一个年份判断是否是......
  • 选课系统
    一、选课系统需求分析角色: 学校、学员、课程、讲师要求:1.创建北京、上海2所学校2.创建linux,python,go3个课程,linux\py在北京开,go在上海开3.......
  • 2022年11月10日 亲测可用Clion永久2022.2最新激活码 破解 账号一年 教育授权学生账号
    【正版授权个人专属】:Jetbrains全系列IDE使用1年只要...【官方授权正版激活】:官方授权正版激活支持Jetbrains家族下所有IDE个人账号...“本教程中激活插件文件......