首页 > 其他分享 >2023年11月14号(学生选课管理系统源代码)

2023年11月14号(学生选课管理系统源代码)

时间:2023-11-14 22:46:19浏览次数:46  
标签:11 教师 name 选课 信息 学生 添加 源代码

今天将本周一的代码进行了bug修改和完善,下面是源代码

四张数据库的内容与命名:

主页面:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>选课管理系统</title>
</head>
<body>
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <th colspan=2>登录</th>
        </tr>
        <form action="tdenglu.jsp" method="post" target="_self">
            <tr>
                <td>老师</td>
                <td>
                    <input type="submit" value="跳转">
                </td>
            </tr>
        </form>
        <form action="sdenglu.jsp" method="post" target="_self">
            <tr>
                <td>学生</td>
                <td>
                    <input type="submit" value="跳转">
                </td>
            </tr>
        </form>
        <form action="gdenglu.jsp" method="post" target="_self">
            <tr>
                <td>管理员</td>
                <td>
                    <input type="submit" value="跳转">
                </td>
            </tr>
        </form>
    </table>
</body>
</html>

老师登录界面:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>教师登录</title>
</head>
<body>
<form action="teacher.jsp" method="post" target="_self">
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <th colspan=2>登录</th>
        </tr>
        <tr>
            <td>工号</td>
            <td><input type="text" name="tid"></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="password" name="tpass"></td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit"style=" background-color: aqua" value="登录"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

老师操作界面:

<%@ page import="java.sql.*" %><%--
  Created by IntelliJ IDEA.
  User: 惠普
  Date: 2023/11/13
  Time: 14:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>教师功能页</title>
</head>
<body>

<%
    String id=request.getParameter("tid");
    String passw=request.getParameter("tpass");
    String tname="";
    try{
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2.使用我自己的数据库 test 获取链接
        String url = "jdbc:mysql://localhost:3306/test";
        String username = "root";
        String password = "123456";
        Connection connection = DriverManager.getConnection(url, username, password);
        //获取执行sql的对象statement
        Statement statement = connection.createStatement();

        String sql2="select * from teacher where 教师工号 = '"+id+"'";
        ResultSet res=statement.executeQuery(sql2);
        while(res.next()) {
            if(!passw.equals(res.getString("密码"))){
                response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
                String newLocn = "tdenglu.jsp";
                response.setHeader("Location",newLocn);
                break;
            }
            tname=res.getString("教师姓名");
            pageContext.setAttribute("p1",tname);
            System.out.println(tname);

        }
        connection.close();
    }catch(Exception e){
        System.out.println(e);
    }
%>

    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <th colspan=2>操作</th>
        </tr>
        <form action="addclass.jsp" method="post" target="_self">
            <tr>

                <input type="hidden" name="tname" value="${p1}">
                <td>添加课程</td>
                <td>
                    <input type="submit" value="跳转">
                </td>
            </tr>
        </form>
        <form action="teacherupdate.jsp" method="post" target="_self">
            <tr>
                <input type="hidden" value="<%=id%>" name="id">
                <td>修改个人信息</td>
                <td>
                    <input type="submit" value="跳转">
                </td>
            </tr>
        </form>
        <form action="lookstudent.jsp" method="post" target="_self">
            <tr>
                <input type="hidden" name="tname" value="<%=tname%>">
                <td>浏览选课学生信息</td>
                <td>
                    <input type="submit" value="跳转">
                </td>
            </tr>
        </form>
    </table>
<form action="index.jsp" method="post" target="_self">
    <table  align="center" >
        <tr>
            <td>
                <input type="submit"style=" background-color: aqua" value="返回"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

老师操作1,添加课程:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加课程信息</title>
</head>
<body>
<%
    String name=request.getParameter("tname");
    pageContext.setAttribute("p1",name);
%>
<form action="acfinish.jsp" method="post" target="_self">
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <input type="hidden" name="teacher" value="${p1}">
        <tr>
            <th colspan=2>添加课程信息</th>
        </tr>
        <tr>
            <td>课程编号</td>
            <td><input type="text" name="cid"></td>
        </tr>
        <tr>
            <td>课程名称</td>
            <td><input type="text" name="cname"></td>
        </tr>
        <tr>
            <td>选课人数</td>
            <td><input type="text" name="cnum"></td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit"style=" background-color: aqua" value="添加"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

添加成功:

<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加成功</title>
</head>
<body>
<%
  String teacher=request.getParameter("teacher");
  String id=request.getParameter("cid");
  String name=request.getParameter("cname");
  String num=request.getParameter("cnum");

  try{
    Class.forName("com.mysql.cj.jdbc.Driver");
    // 2.使用我自己的数据库 test 获取链接
    String url = "jdbc:mysql://localhost:3306/test";
    String username = "root";
    String password = "123456";
    Connection connection = DriverManager.getConnection(url, username, password);
    //获取执行sql的对象statement
    Statement statement = connection.createStatement();


    String sql="insert into class(任课教师,课程编号,课程名称,选课人数) value(?,?,?,?)";
    PreparedStatement ps1=connection.prepareStatement(sql);
    ps1.setString(1,teacher);
    ps1.setString(2,id);
    ps1.setString(3,name);
    ps1.setString(4,num);
    ps1.executeUpdate();
    ps1.close();
    connection.close();
  }catch(Exception e){
    System.out.println(e);
  }
%>
<form action="teacher.jsp" method="post" target="_self">
  <table  align="center" >
    <tr>
      <td>
        <input type="submit"style=" background-color: aqua" value="返回"/>
      </td>
    </tr>
  </table>
</form>
</body>
</html>

老师操作2,修改个人信息:

<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: 惠普
  Date: 2023/11/13
  Time: 14:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改个人信息</title>
</head>
<body>
<%
    String id=request.getParameter("id");
    String tname="";
    String tgender="";
    String txueyuan="";
    String zhicheng="";

    try{
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2.使用我自己的数据库 test 获取链接
        String url = "jdbc:mysql://localhost:3306/test";
        String username = "root";
        String password = "123456";
        Connection connection = DriverManager.getConnection(url, username, password);
        //获取执行sql的对象statement
        Statement statement = connection.createStatement();

        String sql2="select * from teacher where 教师工号 = '"+id+"'";
        ResultSet res=statement.executeQuery(sql2);
        while(res.next()) {
            tname=res.getString("教师姓名");
            tgender=res.getString("教师性别");
            txueyuan=res.getString("教师所在学院");
            zhicheng=res.getString("职称");
        }
        connection.close();
    }catch(Exception e){
        System.out.println(e);
    }
%>
<form action="tufinish.jsp" method="post" target="_self">
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <input type="hidden" value="<%=id%>" name="id">
            <td>教师姓名</td>
            <td><input type="text" name="tname" value="<%=tname%>"></td>
        </tr>
        <tr>
            <td>教师性别</td>
            <td><input type="text" name="tgender" value="<%=tgender%>"></td>
        </tr>
        <tr>
            <td>教师所在学院</td>
            <td><input type="text" name="txueyuan" value="<%=txueyuan%>"></td>
        </tr>
        <tr>
            <td>职称</td>
            <td><input type="text" name="zhicheng" value="<%=zhicheng%>"></td>
        </tr>
        <tr>
            <td colspan=2>
                <input type="submit" value="修改">
            </td>
        </tr>
    </table>
</form>
</body>
</html>

修改成功:

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.PreparedStatement" %><%--
  Created by IntelliJ IDEA.
  User: 惠普
  Date: 2023/11/13
  Time: 15:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改成功</title>
</head>
<body>
<%
    String xueyuan=request.getParameter("txueyuan");
    String id=request.getParameter("id");
    String name=request.getParameter("tname");
    String gender=request.getParameter("tgender");
    String zhicheng=request.getParameter("zhicheng");

    try{
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2.使用我自己的数据库 test 获取链接
        String url = "jdbc:mysql://localhost:3306/test";
        String username = "root";
        String password = "123456";
        Connection connection = DriverManager.getConnection(url, username, password);
        //获取执行sql的对象statement
        Statement statement = connection.createStatement();

        String sql="update plan set 教师姓名 = '"+name+"' ,教师性别 = '"+gender+"' ,教师所在学院 = '"+xueyuan+"' ,职称 = '"+zhicheng+"' where 教师工号 = '"+id+"'";
        PreparedStatement ps1=connection.prepareStatement(sql);
        ps1.executeUpdate();
        ps1.close();
        connection.close();
    }catch(Exception e){
        System.out.println(e);
    }
%>
<form action="teacher.jsp" method="post" target="_self">
    <table  align="center" >
        <tr>
            <td>
                <input type="submit"style=" background-color: aqua" value="返回"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

老师操作3,浏览选课学生信息:

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>浏览选课学生信息</title>
</head>
<body>

<form action="lookstudent2.jsp" method="post" target="_self">
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <td>请选择要查看的课程</td>
                <%
                    String tname=request.getParameter("tname");
                    try{
                        Class.forName("com.mysql.cj.jdbc.Driver");
                        // 2.使用我自己的数据库 test 获取链接
                        String url = "jdbc:mysql://localhost:3306/test";
                        String username = "root";
                        String password = "123456";
                        Connection connection = DriverManager.getConnection(url, username, password);
                        //获取执行sql的对象statement
                        Statement statement = connection.createStatement();

                        String sql2="select * from class where 任课教师 = '"+tname+"'";
                        ResultSet res=statement.executeQuery(sql2);
                        while(res.next()) {
                            String cname=res.getString("课程名称");
                            pageContext.setAttribute("p1",cname);
                %>
                <td><input type="radio" name="cname" value="<%=cname%>">${p1}&nbsp</td>
                <%
                        }
                        connection.close();
                    }catch(Exception e){
                        System.out.println(e);
                    }
                %>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit"style=" background-color: aqua" value="查询"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

浏览界面:

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>浏览选课学生信息</title>
</head>
<body>
<form action="teacher.jsp" method="post" target="_self">
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <td>学号</td>
            <td>姓名</td>
            <td>性别</td>
            <td>班级</td>
            <td>所属专业组成</td>
        </tr>
<%
    String cname=request.getParameter("cname");

    //1.注册驱动
    Class.forName("com.mysql.cj.jdbc.Driver");
    // 2.使用我自己的数据库 test 获取链接
    String url = "jdbc:mysql://localhost:3306/test";
    String username = "root";
    String password = "123456";
    Connection connection = DriverManager.getConnection(url, username, password);
    //获取执行sql的对象statement
    Statement statement = connection.createStatement();

    String sql="select * from student where 所属专业组成 like '%"+cname+"%'";
    ResultSet res=statement.executeQuery(sql);
    while(res.next()){
        String s1=res.getString("学号");
        String s2=res.getString("姓名");
        String s3=res.getString("性别");
        String s4=res.getString("班级");
        String s5=res.getString("所属专业组成");
        pageContext.setAttribute("p1",s1);
        pageContext.setAttribute("p2",s2);
        pageContext.setAttribute("p3",s3);
        pageContext.setAttribute("p4",s4);
        pageContext.setAttribute("p5",s5);

%>
        <tr>
            <td><input type="hidden" name="name" value="${p1}">${p1}</td>
            <td><input type="hidden" name="talk" value="${p2}">${p2}</td>
            <td><input type="hidden" name="way" value="${p3}">${p3}</td>
            <td><input type="hidden" name="otime" value="${p4}">${p4}</td>
            <td><input type="hidden" name="ctime" value="${p5}">${p5}</td>
        </tr>
        <%
            }
        %>
        <tr>
            <td colspan="5">
                <input type="submit"style=" background-color: aqua" value="返回"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

至此,教师部分完成,学生部分:

学生登录界面:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学生登录</title>
</head>
<body>
<form action="student.jsp" method="post" target="_self">
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <th colspan=2>登录</th>
        </tr>
        <tr>
            <td>学号</td>
            <td><input type="text" name="sid"></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="password" name="spass"></td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit"style=" background-color: aqua" value="登录"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

学生操作界面:

<%--
  Created by IntelliJ IDEA.
  User: 惠普
  Date: 2023/11/13
  Time: 14:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<html>
<head>
    <title>学生功能页</title>
</head>
<body>
<%
    String id=request.getParameter("sid");
    String passw=request.getParameter("spass");
    String sname="";
    try{
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2.使用我自己的数据库 test 获取链接
        String url = "jdbc:mysql://localhost:3306/test";
        String username = "root";
        String password = "123456";
        Connection connection = DriverManager.getConnection(url, username, password);
        //获取执行sql的对象statement
        Statement statement = connection.createStatement();

        String sql2="select * from student where 学号 = '"+id+"'";
        ResultSet res=statement.executeQuery(sql2);
        while(res.next()) {
            if(!passw.equals(res.getString("密码"))){
                response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
                String newLocn = "sdenglu.jsp";
                response.setHeader("Location",newLocn);
                break;
            }
            sname=res.getString("姓名");



        }
        connection.close();
    }catch(Exception e){
        System.out.println(e);
    }
%>
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <th colspan=2>操作</th>
        </tr>
        <form action="studentupdate.jsp" method="post" target="_self">
            <tr>
                <input type="hidden" value="<%=id%>" name="id">
                <td>修改个人信息</td>
                <td>
                    <input type="submit" value="跳转">
                </td>
            </tr>
        </form>
        <form action="lookclass.jsp" method="post" target="_self">
            <tr>
                <input type="hidden" value="<%=id%>" name="id">
                <td>浏览课程信息</td>
                <td>
                    <input type="submit" value="跳转">
                </td>
            </tr>
        </form>
        <form action="choclass.jsp" method="post" target="_self">
            <tr>
                <input type="hidden" value="<%=id%>" name="id">
                <td>选课</td>
                <td>
                    <input type="submit" value="跳转">
                </td>
            </tr>
        </form>
    </table>
<form action="index.jsp" method="post" target="_self">
    <table  align="center" >
        <tr>
            <td>
                <input type="submit"style=" background-color: aqua" value="返回"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

学生操作1,修改个人信息:

<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: 惠普
  Date: 2023/11/13
  Time: 14:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改学生个人信息</title>
</head>
<body>
<%
    String id=request.getParameter("id");
    String sname="";
    String sgender="";
    String sbanji="";
    String zhuanye="";

    try{
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2.使用我自己的数据库 test 获取链接
        String url = "jdbc:mysql://localhost:3306/test";
        String username = "root";
        String password = "123456";
        Connection connection = DriverManager.getConnection(url, username, password);
        //获取执行sql的对象statement
        Statement statement = connection.createStatement();

        String sql2="select * from student where 学号 = '"+id+"'";
        ResultSet res=statement.executeQuery(sql2);
        while(res.next()) {
            sname=res.getString("姓名");
            sgender=res.getString("性别");
            sbanji=res.getString("班级");
            zhuanye=res.getString("所属专业组成");
        }
        connection.close();
    }catch(Exception e){
        System.out.println(e);
    }
%>
<form action="sufinish.jsp" method="post" target="_self">
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <input type="hidden" value="<%=id%>" name="id">
            <td>姓名</td>
            <td><input type="text" name="sname" value="<%=sname%>"></td>
        </tr>
        <tr>
            <td>性别</td>
            <td><input type="text" name="sgender" value="<%=sgender%>"></td>
        </tr>
        <tr>
            <td>班级</td>
            <td><input type="text" name="sbanji" value="<%=sbanji%>"></td>
        </tr>
        <tr>
            <td>所属专业组成</td>
            <td><input type="text" name="zhuanye" value="<%=zhuanye%>"></td>
        </tr>
        <tr>
            <td colspan=2>
                <input type="submit" value="修改">
            </td>
        </tr>
    </table>
</form>
</body>
</html>

修改成功:

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改成功</title>
</head>
<body>
<%
    String banji=request.getParameter("sbanji");
    String id=request.getParameter("id");
    String name=request.getParameter("sname");
    String gender=request.getParameter("sgender");
    String zhuanye=request.getParameter("zhuanye");

    try{
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2.使用我自己的数据库 test 获取链接
        String url = "jdbc:mysql://localhost:3306/test";
        String username = "root";
        String password = "123456";
        Connection connection = DriverManager.getConnection(url, username, password);
        //获取执行sql的对象statement
        Statement statement = connection.createStatement();

        String sql="update student set 姓名 = '"+name+"' ,性别 = '"+gender+"' ,班级 = '"+banji+"' ,所属专业组成 = '"+zhuanye+"'  where 学号 = '"+id+"'";
        PreparedStatement ps1=connection.prepareStatement(sql);
        ps1.executeUpdate();
        ps1.close();
        connection.close();
    }catch(Exception e){
        System.out.println(e);
    }
%>
<form action="student.jsp" method="post" target="_self">
    <table  align="center" >
        <tr>
            <td>
                <input type="submit"style=" background-color: aqua" value="返回"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

学生操作2,浏览课程信息:

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>浏览课程信息</title>
</head>
<body>
<form action="student.jsp" method="post" target="_self">
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <td>任课教师</td>
            <td>课程编号</td>
            <td>课程名称</td>
            <td>选课人数</td>
        </tr>
        <tr>
            <%
                String id=request.getParameter("id");
                try{
                    Class.forName("com.mysql.cj.jdbc.Driver");
                    // 2.使用我自己的数据库 test 获取链接
                    String url = "jdbc:mysql://localhost:3306/test";
                    String username = "root";
                    String password = "123456";
                    Connection connection = DriverManager.getConnection(url, username, password);
                    //获取执行sql的对象statement
                    Statement statement = connection.createStatement();
                    Statement stat = connection.createStatement();

                    String sql2="select * from 选课信息 where 学号 = '"+id+"'";
                    ResultSet res=statement.executeQuery(sql2);
                    while(res.next()) {
                        String sclass=res.getString("课程编号");
                        String sql="select * from class where 课程编号 = '"+sclass+"'";
                        ResultSet res2=stat.executeQuery(sql);
                        while(res2.next()){
                            String classname=res2.getString("课程名称");
                            String tname=res2.getString("任课教师");
                            int num=res2.getInt("选课人数");
                            pageContext.setAttribute("p1",classname);


            %>
            <input type="hidden" name="tname" value="<%=tname%>">
            <td><a href="find.jsp"><%=tname%></a></td>
            <td><%=sclass%></td>
            <td>${p1}</td>
            <td><%=num%>></td>
            <%
                        }
                    }
                    connection.close();
                }catch(Exception e){
                    System.out.println(e);
                }
            %>
        </tr>
        <tr>
            <td>
                <input type="submit"style=" background-color: aqua" value="返回"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

点击老师名字查看老师信息界面(超链接跳转):

<%--
  Created by IntelliJ IDEA.
  User: 惠普
  Date: 2023/11/14
  Time: 21:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>老师信息</title>
</head>
<body>
<%
    String tname=request.getParameter("tname");
    String tid = "";
    String tgen = "";
    String txueyuan = "";
    String tzhicheng = "";
    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2.使用我自己的数据库 test 获取链接
        String url = "jdbc:mysql://localhost:3306/test";
        String username = "root";
        String password = "123456";
        Connection connection = DriverManager.getConnection(url, username, password);
        //获取执行sql的对象statement
        Statement statement = connection.createStatement();

        String sql = "select * from teacher where 教师姓名 = '" + tname + "'";
        ResultSet res = statement.executeQuery(sql);

        while (res.next()) {
            tid = res.getString("教师工号");
            tgen = res.getString("教师性别");
            txueyuan = res.getString("教师所在学院");
            tzhicheng = res.getString("职称");
        }
    }catch (Exception e){
        System.out.println(e);
    }
%>
<form action="student.jsp" method="post" target="_self">
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <td>教师工号</td>
            <td><%=tid%></td>
        </tr>
        <tr>
            <td>教师姓名</td>
            <td><%=tname%></td>
        </tr>
        <tr>
            <td>教师性别</td>
            <td><%=tgen%></td>
        </tr>
        <tr>
            <td>教师所在学院</td>
            <td><%=txueyuan%></td>
        </tr>
        <tr>
            <td>职称</td>
            <td><%=tzhicheng%></td>
        </tr>
        <tr>
            <td colspan=2><input type="submit" value="返回"></td>
        </tr>
    </table>
</form>
</body>
</html>

 

学生操作3,选课:

<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>选课</title>
</head>
<body>

<form action="classin.jsp" method="post" target="_self">
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">

            <%
                String id=request.getParameter("id");

                //1.注册驱动
                Class.forName("com.mysql.cj.jdbc.Driver");
                // 2.使用我自己的数据库 test 获取链接
                String url = "jdbc:mysql://localhost:3306/test";
                String username = "root";
                String password = "123456";
                Connection connection = DriverManager.getConnection(url, username, password);
                //获取执行sql的对象statement
                Statement statement = connection.createStatement();

                String sql="select * from class";
                ResultSet res=statement.executeQuery(sql);
                while(res.next()){
                    int num=res.getInt("选课人数");
                    String name=res.getString("课程名称");
                    String cid=res.getString("课程编号");

                    if(num<100){
                        pageContext.setAttribute("p1",name);
                        pageContext.setAttribute("p2",id);
%>
        <tr>
            <input type="hidden" value="${p2}" name="id">
            <input type="hidden" value="<%=cid%>" name="cid">
            <td><input type="submit" value="${p1}" name="cname"></td>
        </tr>
            <%
                    }
                }

            %>
    </table>
</form>
</body>
</html>

选择课程:

<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>课程信息</title>
</head>
<body>
<form action="ccfinish.jsp" method="post" target="_self">
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <th colspan=2>课程信息</th>
        </tr>
        <%
            String cname=request.getParameter("cname");
            String id=request.getParameter("id");
            int cnum=0;
            try {
                Class.forName("com.mysql.cj.jdbc.Driver");
                // 2.使用我自己的数据库 test 获取链接
                String url = "jdbc:mysql://localhost:3306/test";
                String username = "root";
                String password = "123456";
                Connection connection = DriverManager.getConnection(url, username, password);
                //获取执行sql的对象statement
                Statement statement = connection.createStatement();
                Statement stat = connection.createStatement();

                String sql = "select * from class where 课程名称 = '" + cname + "'";
                ResultSet res = statement.executeQuery(sql);
                while (res.next()) {
                    String cteacher = res.getString("任课教师");
                    String cid = res.getString("课程编号");
                    cnum = res.getInt("选课人数");
                    System.out.println(cnum);
                    pageContext.setAttribute("p1", cteacher);
                    pageContext.setAttribute("p2", cid);
                    String sql3 = "select * from teacher where 教师姓名 = '" + cteacher + "'";
                    ResultSet res2 = stat.executeQuery(sql3);
                    while(res2.next()) {
                        String tid = res2.getString("教师工号");
                        String n=""+cnum;
                        %>

        <input type="hidden" value="<%=cid%>" name="cid">
        <input type="hidden" value="<%=n%>" name="cnum">
        <input type="hidden" value="<%=tid%>" name="tid">
        <%
                    }
                }

            }catch (Exception e){
                System.out.println(e);
            }
        %>
        <tr>
            <input type="hidden" value="<%=id%>" name="id">
            <input type="hidden" value="<%=cname%>" name="cname">
            <td>
                任课教师
            </td>
            <td>${p1}</td>
        </tr>
        <tr>
            <td>
                课程编号
            </td>
            <td>${p2}</td>
        </tr>
        <tr>
            <td>
                选课人数
            </td>
            <td><%=cnum%></td>
        </tr>
        <tr>
            <td colspan=2><input type="submit" value="选课"></td>
        </tr>
    </table>
</form>
</body>
</html>

选课完成:

<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>选课成功</title>
</head>
<body>
<%
    String id=request.getParameter("id");
    String cid=request.getParameter("cid");
    String tid=request.getParameter("tid");
    int num=Integer.valueOf(request.getParameter("cnum"));
    num+=1;
    System.out.println(num);
    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2.使用我自己的数据库 test 获取链接
        String url = "jdbc:mysql://localhost:3306/test";
        String username = "root";
        String password = "123456";
        Connection connection = DriverManager.getConnection(url, username, password);
        //获取执行sql的对象statement
        Statement statement = connection.createStatement();

        String sql = "update class set 选课人数 = " + num + "  where 课程编号 = '" + cid + "'";
        PreparedStatement ps1 = connection.prepareStatement(sql);
        ps1.executeUpdate();
        String sql2 = "insert into 选课信息(课程编号,教师编号,学号) value(?,?,?)";
        PreparedStatement ps2 = connection.prepareStatement(sql2);
        ps2.setString(1, cid);
        ps2.setString(2, tid);
        ps2.setString(3, id);
        ps2.executeUpdate();
    }catch (Exception e){
        System.out.println(e);
    }
%>
<form action="student.jsp" method="post" target="_self">
    <table  align="center" >
        <tr>
            <td>
                <input type="submit"style=" background-color: aqua" value="返回"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

至此,学生部分完成,管理员部分:

管理员登录:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>管理员登录</title>
</head>
<body>
<form action="guanli.jsp" method="post" target="_self">
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <th colspan=2>登录</th>
        </tr>
        <tr>
            <td>帐号</td>
            <td><input type="text" name="tid"></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="password" name="tpass"></td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit"style=" background-color: aqua" value="登录"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

管理员操作界面:

<%--
  Created by IntelliJ IDEA.
  User: 惠普
  Date: 2023/11/13
  Time: 14:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>管理员功能页</title>
</head>
<body>
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <th colspan=2>操作</th>
        </tr>
        <form action="addteacher.jsp" method="post" target="_self">
            <tr>
                <td>添加教师信息</td>
                <td>
                    <input type="submit" value="跳转">
                </td>
            </tr>
        </form>
        <form action="addstudent.jsp" method="post" target="_self">
            <tr>
                <td>添加学生信息</td>
                <td>
                    <input type="submit" value="跳转">
                </td>
            </tr>
    </form>
        <form action="index.jsp" method="post" target="_self">
            <tr>
                <td colspan=2>
                    <input type="submit" value="返回">
                </td>
            </tr>
        </form>
    </table>

</body>
</html>

管理员操作1,添加教师信息:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加教师信息</title>
</head>
<body>
<form action="finishat.jsp" method="post" target="_self">
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <th colspan=2>添加教师信息</th>
        </tr>
        <tr>
            <td>教师工号</td>
            <td><input type="text" name="sid"></td>
        </tr>
        <tr>
            <td>教师姓名</td>
            <td><input type="text" name="sname"></td>
        </tr>
        <tr>
            <td>教师性别</td>
            <td><input type="text" name="sgen"></td>
        </tr>
        <tr>
            <td>教师所在学院</td>
            <td><input type="text" name="sbanji"></td>
        </tr>
        <tr>
            <td>职称</td>
            <td><input type="text" name="szhuanye"></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="text" name="spass"></td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit"style=" background-color: aqua" value="添加"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

添加教师信息完成:

<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加成功</title>
</head>
<body>
<%
    String gen=request.getParameter("sgen");
    String id=request.getParameter("sid");
    String name=request.getParameter("sname");
    String banji=request.getParameter("sbanji");
    String zhuanye=request.getParameter("szhuanye");
    String pass=request.getParameter("spass");

    try{
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2.使用我自己的数据库 test 获取链接
        String url = "jdbc:mysql://localhost:3306/test";
        String username = "root";
        String password = "123456";
        Connection connection = DriverManager.getConnection(url, username, password);
        //获取执行sql的对象statement
        Statement statement = connection.createStatement();


        String sql="insert into teacher(教师工号,教师姓名,教师性别,教师所在学院,职称,密码) value(?,?,?,?,?,?)";
        PreparedStatement ps1=connection.prepareStatement(sql);
        ps1.setString(1,id);
        ps1.setString(2,name);
        ps1.setString(3,gen);
        ps1.setString(4,banji);
        ps1.setString(5,zhuanye);
        ps1.setString(6,pass);
        ps1.executeUpdate();
        ps1.close();
        connection.close();
    }catch(Exception e){
        System.out.println(e);
    }
%>
<form action="guanli.jsp" method="post" target="_self">
    <table  align="center" >
        <tr>
            <td>
                <input type="submit"style=" background-color: aqua" value="返回"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

管理员操作2,添加学生信息:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加学生信息</title>
</head>
<body>
<form action="finishas.jsp" method="post" target="_self">
    <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10"  style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500">
        <tr>
            <th colspan=2>添加学生信息</th>
        </tr>
        <tr>
            <td>学号</td>
            <td><input type="text" name="sid"></td>
        </tr>
        <tr>
            <td>姓名</td>
            <td><input type="text" name="sname"></td>
        </tr>
        <tr>
            <td>性别</td>
            <td><input type="text" name="sgen"></td>
        </tr>
        <tr>
            <td>班级</td>
            <td><input type="text" name="sbanji"></td>
        </tr>
        <tr>
            <td>所属专业组成</td>
            <td><input type="text" name="szhuanye"></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="text" name="spass"></td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit"style=" background-color: aqua" value="添加"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

添加完成:

<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加成功</title>
</head>
<body>
<%
    String gen=request.getParameter("sgen");
    String id=request.getParameter("sid");
    String name=request.getParameter("sname");
    String banji=request.getParameter("sbanji");
    String zhuanye=request.getParameter("szhuanye");
    String pass=request.getParameter("spass");

    try{
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2.使用我自己的数据库 test 获取链接
        String url = "jdbc:mysql://localhost:3306/test";
        String username = "root";
        String password = "123456";
        Connection connection = DriverManager.getConnection(url, username, password);
        //获取执行sql的对象statement
        Statement statement = connection.createStatement();


        String sql="insert into student(学号,姓名,性别,班级,所属专业组成,密码) value(?,?,?,?,?,?)";
        PreparedStatement ps1=connection.prepareStatement(sql);
        ps1.setString(1,id);
        ps1.setString(2,name);
        ps1.setString(3,gen);
        ps1.setString(4,banji);
        ps1.setString(5,zhuanye);
        ps1.setString(6,pass);
        ps1.executeUpdate();
        ps1.close();
        connection.close();
    }catch(Exception e){
        System.out.println(e);
    }
%>
<form action="guanli.jsp" method="post" target="_self">
    <table  align="center" >
        <tr>
            <td>
                <input type="submit"style=" background-color: aqua" value="返回"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

 

标签:11,教师,name,选课,信息,学生,添加,源代码
From: https://www.cnblogs.com/jiajiayu/p/17832769.html

相关文章

  • 20231114打卡
    今天学习了数据结构练习了最小生成树算法kruskal和最短路径dijkstra和floyd算法#defineMAX10000000#include<iostream>usingnamespacestd;structGraph{ int**arc; char*vex; intvexnum; intarcnum;};structEdge{ intstart,end,weight;};Edge*cre......
  • 2023.11.14
    CLYZ联考。鉴定为FJOI。A问\(\{1,2,\dots,n\}\)有多少子集的\(\gcd=G\),\(\operatorname{lcm}=L\)。另外地,多次询问若子集包含\(x\)的方案数。答案模\(998244853\)。\(1\len,G,L\le10^8\),\(1\leq\le5000\),\(1\lex\len\)。\(\mathrm{TL}=6\mathrm{s}\)。先解决......
  • 11.14打卡
    1.最小覆盖字串(76)给你一个字符串 s 、一个字符串 t 。返回 s 中涵盖 t 所有字符的最小子串。如果 s 中不存在涵盖 t 所有字符的子串,则返回空字符串 "" 。classSolution{publicStringminWindow(Strings,Stringt){intn=s.length();......
  • 11 14 lombok的使用和注册接口与登录接口细节
      先导入lombok的依赖,加上@Data注解  这是pojo包下的result,使用的两个注解是无参构造和有参构造controller:书写 service接口书写: serviceImol书写: 其中@Service把把该类注入到容器中,@Autowired注解是依赖注入,Md5Util是一个工具类,其中的getMD5String(string)......
  • 11.14 衔花
    垫底好心情,从我做起也只能我了昨天改的GNUK改坏了,今天重改妈的模拟赛垫了,现在完全不会计数。好多技巧都忘光光了。幸好很快就要结束了。再见呢朋友们。http://www.ccgp-hebei.gov.cn/sjz/sjz/cggg/zhbggAAAS/202311/t20231114_1910631.htmlS2新购买了三块显卡,一款古......
  • 81st 2023/11/13 NOIP Day-4
    本次的出题人是OP小总结下T1就算切不了,也能拿很高的部分分,赛时就应该认真思考完每一部分的分看看能不能拿毕竟这里不是改题,赛时认真思考拿不到的分,认了,较劲也没什么用也不能因此而放掉这一道题,应该去看看有没有什么部分分能拿这样就算切不了题,分数也不会太难看这次T2很能说......
  • 80th 2023/11/12 NOIP Day-5
    停课训练的第一天,还有六天NOIP抓紧训练记录下今晚小小的思考,有部分偏于思维漏洞用栈模拟一类题,就是一串数中删掉中间一部分数,然后若要将两边重新连上,之前要么花大时间重新赋值,要么用链表导致失去直接用数组\(O(1)\)访问的功能,现在发现还可以用栈,若没有在线修改,那么可以从左往......
  • 79th 2023/11/4 模拟赛总结57
    这次是多校集训赛题目难,一道题都不会T2有奇怪的小思路,但有时候算不出答案赛时是看完题后,先手玩了一会T1,发现没什么思路后,对T2起了兴趣然后就试图在用代数式去算最大值取值,然后发现为保证正确性,只能\(O(n^2)\)去打,还要防止取到负数于是先打了T1暴力,然后打T2,一开始没发现它正确......
  • 2023.11.14 总结
    T1题意:已知\(P=10^{18}+31\)为质数且存在原根\(g=42\),记\(A_0\)为\(795484359100928850\),\(A_k=f(A_{k-1})\),其中\(0<f(x)<P\)且满足\(g^{f(x)}\equivx(modP)\),可证明这样\(f(x)\)唯一存在,每次查询一点\(f(x)\)的取值,\(1\lex\le10^5\)。事实上,此......
  • 大二打卡(11.13)
    今天做了什么:今天周一,没有工程实训,没有早八,开心,一觉睡到九点12,刚醒墩儿,手机一震,建民老师发布消息,下午分级测试,以为上周说的每周一套题,就单单是个练习,没想到还是考试,难顶,但是上午的时候还是没怎么放在心上,下午开始测试了,才发觉这玩意工作量这么大,没好好练,根本写不完,才三个小时,我估......