test石家庄铁道大学学生选课管理系统
石家庄铁道大学学生选课管理系统
2017级《JAVA语言程序设计》
上机考试试题
2019.01.10
考试要求
一、本试卷为2017级《JAVA语言程序设计》上机考试试卷;
二. 注意编程规范:
(1)通过Eclipse添加类的方式建立类;
(2)程序开头部分注释班级、作者、学号、日期;
(3)注意程序代码中必要的空格与缩进;
(4)注意类、变量、方法的命名原则;
三. 考试结束后,将整个项目工程文件夹中的文件源代码和数据库备份文件放入文件夹,以“班级学号姓名”方式命名,并压缩成同名的压缩包文件,考试结束后提交给课代表统一上交。
石家庄铁道大学学生选课管理系统(50分)
1、项目需求:
石家庄铁道大学为了提高教务处的工作效率,方便用户之间信息的交流,简化学生选课的流程,使选课管理工作更规范化,系统化,程序化,提高信息处理的速度和准确性,能够及时、准确、有效的查询和修改选课排课相关信息。在学校内部的现有局域网这个网络环境下,信息由各用户在规定的权限下在各自的工作站上录入,信息上网后各用户可查询,选课,修改,管理,实现信息共享。
2.系统要求与功能设计
2.1 页面要求
(1)系统可以通过浏览器直接访问;(1分)
(2)各个功能页面整体风格统一;(2分)
(3)首页为用户登录页面,管理员、教师、学生三种角色用户登录后,进入相应的功能页,只能看到角色允许访问功能模块;(3分)
图1 学生选课系统功能结构图
(5)学生功能页:共包括查看个人信息、修改个人基本信息、修改个人密码、查询课程信息、自助选课、查询个人课表六项功能模块。
(6)教师功能页:包括查看教师个人信息、修改个人基本信息、修改个人密码、修改个人所教授课程部分信息,查询个人课表五项功能模块;
(7)管理员功能页:新添学生基本信息、修改学生基本信息、删除学生基本信息、新添教师基本信息,修改教师基本信息、删除教师基本信息、新添课程基本信息、修改教师基本信息、删除基本信息,密码重置十项功能模块。
2.2 功能要求
(1)新添学生基本信息:新添一名新学生基本个人信息,学生基本信息包括;学号(数据库中学号保持唯一、由系统自动生成、生成规则:学号由八位数字组成、开头以“2019XXXX”XXXX为四位依次递增的数字序号例如:“20190001、20190002……”)、姓名、性别(限定为“男”或“女”两个选项)、年龄、专业(要求限定在“计算机科学与技术”、“软件工程”、“网络工程”、“数字媒体技术”四个选项)、班级六项基本信息。(5分)
(2)修改学生基本信息(等同于学生功能页中修改个人信息):学号不允许修改,姓名、性别、年龄、专业、班级可以按照要求进行修改,不符合录入格式的,提交时不允许修改,并提示错误信息类型,返回修改界面。(2分)
(3)删除学生基本信息:管理员可以从系统中删除学生基本信息。(1分)
(4)新添教师基本信息:新增一名教师基本信息,教师基本信息包括:教师工号(唯一,六位数字组成,前两位表示学院代码“01表示信息、02表示土木、03表示机械、04、表示电气、05表示交通”,后四位为依次递增的数字序号,提交时应验证工号的正确性,如有误,则提示错误,反馈界面,不允许提交保存)、姓名、职称(职称限定在“助教”、“讲师”、“副教授”、“教授”四个选项)、所属学院(取值限定在“信息、土木、机械、电气、交通”五个选项,并与教师工号前两位形成校验关系);(5分)
(5)修改教师基本信息(等同于教师功能页中修改个人信息):可以修改教师工号,姓名、职称、所属学院,教师工号前两位与所属学院关联,修改任何一项,必须关联修改另外一项,修改提交时须验证是否符合录入格式的,不符合不允许修改,提示错误信息类型,返回修改界面。(2分)
(6)删除教师基本信息:管理员可以从系统中删除教师基本信息,但是如果教师已经承担相应课程,系统不允许删除。(1分)
(7)新添课程基本信息:管理员可以增加一门课程基本信息,课程基本信息包括:课程编号(唯一,六位数字序号,系统自动生成依次递增),课程名称、开课时间(取值限定在“星期一、星期二、星期三、星期四、星期五”),开课节次(取值限定在“1-2节、3-4节、5-6节、7-8节、9-10节”)所属学院(取值限定在“信息、土木、机械、电气、交通”五个选项),任课教师工号,任课教师名称,选课限制人数。(5分)
(8)修改课程基本信息:可以修改课程开课时间、开课节次、所属学院(取值限定在“信息、土木、机械、电气、交通”五个选项),任课教师工号,任课教师名称,选课限制人数六项基本信息,课程编号、课程名称不允许修改。(2分)
(9)删除课程基本信息:管理员可以删除课程基本信息,但如果该课程有学生已经选课,提示错误信息“该课程已经被选,不允许删除”,不允许删除该课程基本信息。(1分)
(10) 自助选课管理:学生登录后可以浏览相关的课程信息列表,并查看课程的详细信息,点击“选课”按钮操作,系统判断该课程是否已超过选课人数,如果超过选课人数限制提示“该课程已经超过选课人数限制,选课失败”,回到选课界面,如果成功,提示“选课成功”。(5分)
(11)查询课表:教师或学生登录系统后均可查询个人课表,学生按照选课结果显示开课时间、开课节次、课程名称,教师按照承担课程显示开课时间、开课节次、课程名称,选课人数;(3分)
(12)修改个人所教授课程部分信息:教师登录后,可以修改个人承担课程的选课人数一项基本信息,其余信息不允许修改;(2分)
(13)个人密码修改:教师或学生用户登录后,可以输入旧密码、新密码、新密码确认修改个人密码,需要判断旧密码是否正确,新密码和新密码确认是否一致;(2分)
(14)重置密码:管理员可以修改教师或学生的个人密码,先按照教师工号或学生学号查询,显示出基本信息后,点击密码重置,将教师或个人密码统一修改为“123456”。(2分)
(15)数据库评分标准:按照题目要求创建教师基本信息表、学生基本信息表、课程基本信息表,选课结果表(4分),实现数据库连接正常(2分)。
一、
二、代码
使用mybatis+Mapper代理来实现功能
使用到的jar包:mybatis、jQuery(进行js校验)、mysql
配置文件
1.mysql.properties
driver=com.mysql.cj.jdbc.Driver url=jdbc:mysql://127.0.0.1:3306/course?serverTimezone=UTC&useSSL=false&characterEncoding=UTF-8 username=root password=123456
2.mybatis-config.xml
<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- properties 标签中的配置可以供整个配置文件使用,在任何位置都可以引入其中配置的值。 properties 标签可以通过子标签 property 标签来配置一些子元素信息,也可以配置外部的动态文件。 --> <properties resource="mysql.properties"/> <!-- 也可以配置 url,但是 url和resource只能存在一个 --> <!-- 类型别名 --> <!-- <typeAliases>--> <!-- <typeAlias type="com.xxxx.entity.User" alias="User"/>--> <!-- </typeAliases>--> <!-- 对事物的管理和连接池的配置 --> <environments default="development"> <environment id="development"> <transactionManager type="JDBC"/> <!--连接池信息--> <dataSource type="POOLED"> <property name="driver" value="${driver}"/> <property name="url" value="${url}"/> <property name="username" value="${username}"/> <property name="password" value="${password}"/> </dataSource> </environment> </environments> <!--mappers映射器--> <mappers> <!--映射文件方式1.一个一个的配置--> <!-- <mapper resource="com/xxxx/mapper/UserMapper.xml"/>--> <!-- <mapper class="com.xxxx.mapper.UserMapper"/>--> <!--映射文件方式2.自动扫描包内的Mapper接口和配置文件--> <package name="com.xxxx.mapper"/> </mappers> </configuration>
实体类
3.Cla.java(课程类)

package com.xxxx.entity; public class Cla { private int id;//课程编号 private String name;//课程名称 private String time;//开课时间星期几 private String ci;//上课时间1-2节 private String yuan;//开课院系 private String tea;//任课老师名字 private int teaid;//老师id private int people;//限制人数 private int xuan=0;//已选人数默认为0 public int getId() { return id; } public int getXuan() { return xuan; } public void setXuan(int xuan) { this.xuan = xuan; } public Cla(int id, String name, String time, String ci, String yuan, String tea, int teaid, int people, int xuan) { this.id = id; this.name = name; this.time = time; this.ci = ci; this.yuan = yuan; this.tea = tea; this.teaid = teaid; this.people = people; this.xuan = xuan; } public Cla(String name, String time, String ci, String yuan, String tea, int teaid, int people) { this.name = name; this.time = time; this.ci = ci; this.yuan = yuan; this.tea = tea; this.teaid = teaid; this.people = people; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getTime() { return time; } public void setTime(String time) { this.time = time; } public String getCi() { return ci; } public void setCi(String ci) { this.ci = ci; } public String getYuan() { return yuan; } public void setYuan(String yuan) { this.yuan = yuan; } public String getTea() { return tea; } public void setTea(String tea) { this.tea = tea; } public int getTeaid() { return teaid; } public void setTeaid(int teaid) { this.teaid = teaid; } public int getPeople() { return people; } public void setPeople(int people) { this.people = people; } public Cla() { } public Cla(int id, String name, String time, String ci, String yuan, String tea, int teaid, int people) { this.id = id; this.name = name; this.time = time; this.ci = ci; this.yuan = yuan; this.tea = tea; this.teaid = teaid; this.people = people; } }
4.Login.java(登录类)

package com.xxxx.entity; public class Login { private String uname; private String upwd; public String getUname() { return uname; } public void setUname(String uname) { this.uname = uname; } public String getUpwd() { return upwd; } public void setUpwd(String upwd) { this.upwd = upwd; } public Login() { } public Login(String uname, String upwd) { this.uname = uname; this.upwd = upwd; } }
5.Stu.java(学生类)

package com.xxxx.entity; public class Stu { private int id;//学号 private String name;//姓名 private String sex;//性别 private int age;//年龄 private String pro;//专业 private String cla;//班级 private int claid;//已选课程id public int getClaid() { return claid; } public void setClaid(int claid) { this.claid = claid; } public Stu(int id, String name, String sex, int age, String pro, String cla, int claid) { this.id = id; this.name = name; this.sex = sex; this.age = age; this.pro = pro; this.cla = cla; this.claid = claid; } public int getId() { return id; } public Stu(String name, String sex, int age, String pro, String cla) { this.name = name; this.sex = sex; this.age = age; this.pro = pro; this.cla = cla; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getPro() { return pro; } public void setPro(String pro) { this.pro = pro; } public String getCla() { return cla; } public void setCla(String cla) { this.cla = cla; } public Stu() { } public Stu(int id, String name, String sex, int age, String pro, String cla) { this.id = id; this.name = name; this.sex = sex; this.age = age; this.pro = pro; this.cla = cla; } }
6.Tea(教师类)

package com.xxxx.entity; public class Tea { private int id;//工号 private String name;//姓名 private String pro;//职位 private String yuan;//所属院 public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPro() { return pro; } public void setPro(String pro) { this.pro = pro; } public String getYuan() { return yuan; } public void setYuan(String yuan) { this.yuan = yuan; } public Tea(int id, String name, String pro, String yuan) { this.id = id; this.name = name; this.pro = pro; this.yuan = yuan; } public Tea() { } }
Mapper接口
7.ClaMapper.java(ClaMapper接口类)

package com.xxxx.mapper; import com.xxxx.entity.Cla; import org.apache.ibatis.annotations.Param; public interface ClaMapper { void add(Cla cla); Cla[] selectAll(); void update(Cla cla); Cla selectByTeaname(String teaname); void deleteById(int id); Cla selectByid(int claid); void updateXuan(@Param("id") int id,@Param("num") int num); Cla[] selectByteaname(String name); }
8.ClaMapper.xml

<?xml version="1.0" encoding="UTF-8"?> <!--<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"--> <!-- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--> <!-- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"--> <!-- version="4.0">--> <!--</web-app>--> <!DOCTYPE mapper PUBLIC "-//mybatis.org/DTD Mapper 3.0" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!--namespace:命名空间--> <mapper namespace = "com.xxxx.mapper.ClaMapper"> <insert id="add"> insert into cla (name,time,ci,yuan,tea,teaid,people) values (#{name},#{time},#{ci},#{yuan},#{tea},#{teaid},#{people}); </insert> <update id="update"> update cla set time=#{time},ci=#{ci},yuan=#{yuan},tea=#{tea},teaid=#{teaid},people=#{people} where id=#{id}; </update> <update id="updateXuan"> update cla set xuan=#{num} where id=#{id}; </update> <delete id="deleteById"> delete from cla where id=#{id}; </delete> <select id="selectAll" resultType="com.xxxx.entity.Cla"> select * from cla; </select> <select id="selectByTeaname" resultType="com.xxxx.entity.Cla"> select * from cla where tea=#{teaname}; </select> <select id="selectByid" resultType="com.xxxx.entity.Cla"> select * from cla where id=#{claid}; </select><select id="selectByteaname" resultType="com.xxxx.entity.Cla"> select * from cla where tea=#{name}; </select> </mapper>
9.LoginMapper.java(LoginMapper接口类)

package com.xxxx.mapper; import com.xxxx.entity.Login; import org.apache.ibatis.annotations.Param; public interface LoginMapper { Login selectByUname(String uname); void updateByuname(String uname); void updateByUname(@Param("uname") String uname,@Param("upwd") String upwd); }
10.LoginMapper.xml

<?xml version="1.0" encoding="UTF-8"?> <!--<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"--> <!-- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--> <!-- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"--> <!-- version="4.0">--> <!--</web-app>--> <!DOCTYPE mapper PUBLIC "-//mybatis.org/DTD Mapper 3.0" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!--namespace:命名空间--> <mapper namespace = "com.xxxx.mapper.LoginMapper"> <update id="updateByuname"> update login set upwd ="123456" where uname=#{uname}; </update> <update id="updateByUname"> update login set upwd =#{upwd} where uname=#{uname}; </update> <select id="selectByUname" resultType="com.xxxx.entity.Login"> select * from login where uname=#{uname}; </select> </mapper>
11.StuMapper.java(StuMapper接口类)

package com.xxxx.mapper; import com.xxxx.entity.Stu; import org.apache.ibatis.annotations.Param; import javax.servlet.annotation.WebServlet; public interface StuMapper { void add(Stu stu); void update(Stu stu); Stu[] selectAll(); Stu selectByid(int id); void deleteById(String id); Stu selectByName(String uname); void updateCla(@Param("stuid") int stuid,@Param("claid") int claid); }
12.StuMapper.xml

<?xml version="1.0" encoding="UTF-8"?> <!--<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"--> <!-- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--> <!-- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"--> <!-- version="4.0">--> <!--</web-app>--> <!DOCTYPE mapper PUBLIC "-//mybatis.org/DTD Mapper 3.0" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!--namespace:命名空间--> <mapper namespace = "com.xxxx.mapper.StuMapper"> <insert id="add"> insert into stu01(name,sex,age,pro,cla) values (#{name},#{sex},#{age},#{pro},#{cla}); </insert> <update id="update"> update stu01 set name=#{name},sex=#{sex},age=#{age},pro=#{pro},cla=#{cla} where id=#{id}; </update> <update id="updateCla"> update stu01 set claid=#{claid} where id=#{stuid}; </update> <delete id="deleteById"> delete from stu01 where id=#{id}; </delete> <select id="selectAll" resultType="com.xxxx.entity.Stu"> select * from stu01; </select> <select id="selectByid" resultType="com.xxxx.entity.Stu"> select * from stu01 where id=#{id}; </select> <select id="selectByName" resultType="com.xxxx.entity.Stu"> select * from stu01 where name=#{uname}; </select> </mapper>
13.TeaMapper.java(TeaMapper接口类)

package com.xxxx.mapper; import com.xxxx.entity.Tea; import org.apache.ibatis.annotations.Param; public interface TeaMapper { void add(Tea tea); Tea[] selectAll(); void updateByeid(@Param("tea") Tea tea, @Param("eid") int eid); Tea selectByid(int id); void deleteById(String id); Tea selectByname(String uname); }
14.TeaMapper.xml

<?xml version="1.0" encoding="UTF-8"?> <!--<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"--> <!-- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--> <!-- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"--> <!-- version="4.0">--> <!--</web-app>--> <!DOCTYPE mapper PUBLIC "-//mybatis.org/DTD Mapper 3.0" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!--namespace:命名空间--> <mapper namespace = "com.xxxx.mapper.TeaMapper"> <insert id="add"> insert into tea01 (id,name,pro,yuan) values (#{id},#{name},#{pro},#{yuan}); </insert> <delete id="deleteById"> delete from tea01 where id=#{id}; </delete> <select id="selectAll" resultType="com.xxxx.entity.Tea"> select * from tea01; </select> <select id="selectByid" resultType="com.xxxx.entity.Tea"> select * from tea01 where id=#{id}; </select> <select id="selectByname" resultType="com.xxxx.entity.Tea"> select * from tea01 where name=#{uname}; </select> <update id="updateByeid"> update tea01 set id=#{tea.id},name=#{tea.name},pro=#{tea.pro},yuan=#{tea.yuan} where id=#{eid}; </update> </mapper>
Servlet层
15.addclaServlet.java(管理员添加课程)

package com.xxxx.servlet; import com.xxxx.entity.Cla; import com.xxxx.entity.Tea; import com.xxxx.mapper.ClaMapper; import com.xxxx.mapper.TeaMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; 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("/addclaServlet") public class addclaServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); String name=request.getParameter("name");//课程名称 String time=request.getParameter("time");//开课时间星期几 String ci =request.getParameter("ci");//上课时间1-2节 String yuan=request.getParameter("yuan");//开课院系 String tea =request.getParameter("tea");//任课老师名字 int teaid = Integer.parseInt(request.getParameter("teaid"));//老师id int people = Integer.parseInt(request.getParameter("people"));//限制人数 Cla cla=new Cla(name,time,ci,yuan,tea,teaid,people); SqlSession sqlSession = GetSqlSession.CreateSqlSession(); ClaMapper claMapper = sqlSession.getMapper(ClaMapper.class); claMapper.add(cla); response.getWriter().write("添加成功"); response.getWriter().close(); sqlSession.close(); } }
16.addstuServlet.java(管理员添加学生信息)

package com.xxxx.servlet; import com.xxxx.entity.Stu; import com.xxxx.mapper.StuMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; 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("/addstuServlet") public class addstuServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); String name=request.getParameter("name"); ;//姓名 String sex=request.getParameter("sex"); ;//性别 int age= Integer.parseInt(request.getParameter("age")); ;//年龄 String pro=request.getParameter("pro"); ;//专业 String cla=request.getParameter("cla"); ;//班级 Stu stu=new Stu(name,sex,age,pro,cla); SqlSession sqlSession = GetSqlSession.CreateSqlSession(); StuMapper stuMapper = sqlSession.getMapper(StuMapper.class); stuMapper.add(stu); response.getWriter().write("添加成功"); response.getWriter().close(); sqlSession.close(); } }
17.addteaServlet(管理员添加教师信息)

package com.xxxx.servlet; import com.xxxx.entity.Tea; import com.xxxx.mapper.TeaMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; 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("/addteaServlet") public class addteaServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); int id = Integer.parseInt(request.getParameter("id"));//工号 String name=request.getParameter("name") ;//姓名 String pro =request.getParameter("pro") ;//职位 String yuan=request.getParameter("yuan") ;//所属院 Tea tea=new Tea(id,name,pro,yuan); SqlSession sqlSession = GetSqlSession.CreateSqlSession(); TeaMapper teaMapper = sqlSession.getMapper(TeaMapper.class); teaMapper.add(tea); response.getWriter().write("添加成功"); response.getWriter().close(); sqlSession.close(); } }
18.declaServlet(管理员删除课程信息)

package com.xxxx.servlet; import com.xxxx.mapper.ClaMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; 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("/declaServlet") public class declaServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); int id= Integer.parseInt(request.getParameter("id"));//课程id int xuan= Integer.parseInt(request.getParameter("xuan"));//已选人数 if(xuan!=0){ response.getWriter().write("该课程已经被选择,无法删除"); response.getWriter().close(); } else{ SqlSession sqlSession = GetSqlSession.CreateSqlSession(); ClaMapper claMapper = sqlSession.getMapper(ClaMapper.class); claMapper.deleteById(id); response.getWriter().write("课程删除成功"); response.getWriter().close(); sqlSession.close(); } } }
19.destuServlet(管理员删除学生信息)

package com.xxxx.servlet; import com.xxxx.mapper.StuMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; 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("/destuServlet") public class destuServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); String id=request.getParameter("id"); SqlSession sqlSession = GetSqlSession.CreateSqlSession(); StuMapper stuMapper = sqlSession.getMapper(StuMapper.class); stuMapper.deleteById(id); response.getWriter().write("删除成功"); response.getWriter().close(); sqlSession.close(); } }
20.deteaServlet(管理员删除教师信息)

package com.xxxx.servlet; import com.xxxx.entity.Cla; import com.xxxx.mapper.ClaMapper; import com.xxxx.mapper.StuMapper; import com.xxxx.mapper.TeaMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; 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("/deteaServlet") public class deteaServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); String id=request.getParameter("id"); String teaname=request.getParameter("teaname");//这个需要多传一个name值 SqlSession sqlSession = GetSqlSession.CreateSqlSession(); //先查看这个教师是否承担教学任务cla ClaMapper claMapper=sqlSession.getMapper(ClaMapper.class); Cla cla=claMapper.selectByTeaname(teaname);//如果cla不等于空,就说明承担了课程 if(cla==null){//为空 TeaMapper stuMapper = sqlSession.getMapper(TeaMapper.class); stuMapper.deleteById(id); response.getWriter().write("删除成功"); response.getWriter().close(); } else{ response.getWriter().write("删除失败,该教师承担了课程任务"); response.getWriter().close(); } sqlSession.close(); } }
21.selectupwdServlet(管理员重置密码前查询信息)

package com.xxxx.servlet; import com.xxxx.entity.Stu; import com.xxxx.entity.Tea; import com.xxxx.mapper.StuMapper; import com.xxxx.mapper.TeaMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; 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; /** * 重置密码前查询信息 * 先看要修改的是学生还是教师(这一步是为了看要查教师表还是学生表,为了查到账号名:为教师/学生的姓名; * 如果直接设置账号名为id号,则可以直接查login登录表,不用这么麻烦) * 存在->可以进入修改页面 * 不存在则返回,提示错误信息(需要回显:域对象) */ @WebServlet("/selectupwdServlet") public class selectupwdServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); int id= Integer.parseInt(request.getParameter("id"));//获取id String type=request.getParameter("type");//获取身份 System.out.println(type); if(type.equals("学生")){ //重置学生密码 SqlSession sqlSession = GetSqlSession.CreateSqlSession(); StuMapper stuMapper = sqlSession.getMapper(StuMapper.class); Stu stu=stuMapper.selectByid(id); if(stu==null){ request.setAttribute("msg","学生id不存在"); request.getRequestDispatcher("selectupwd.jsp").forward(request,response); } else{ request.getSession().setAttribute("type","1");//设1为学生,2为老师 request.getSession().setAttribute("stu" ,stu);//把学生全部信息传到重置密码页面 response.sendRedirect("upupwd.jsp"); } sqlSession.close(); } else{ //重置老师密码 SqlSession sqlSession = GetSqlSession.CreateSqlSession(); TeaMapper teaMapper = sqlSession.getMapper(TeaMapper.class); Tea tea=teaMapper.selectByid(id); if(tea==null){ request.setAttribute("msg","教师id不存在"); request.getRequestDispatcher("selectupwd.jsp").forward(request,response); } else{ request.getSession().setAttribute("type","2");//设1为学生,2为老师 request.getSession().setAttribute("tea" ,tea);//把学生全部信息传到重置密码页面 response.sendRedirect("upupwd.jsp"); } sqlSession.close(); } } }
22.stupwdServlet(修改密码:学生和教师共用)

package com.xxxx.servlet; import com.xxxx.entity.Login; import com.xxxx.mapper.LoginMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; 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("/stupwdServlet") public class stupwdServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); String uname= (String) request.getSession().getAttribute("uname"); String upwd=request.getParameter("upwd"); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); LoginMapper loginMapper=sqlSession.getMapper(LoginMapper.class); Login login=loginMapper.selectByUname(uname); if(login.getUpwd().equals(upwd)){ request.getSession().setAttribute("msg","密码不能和原来的密码一样"); request.getRequestDispatcher("stupwd.jsp").forward(request,response); } else{ loginMapper.updateByUname(uname,upwd); response.getWriter().write("修改密码成功"); response.getWriter().close(); } sqlSession.close(); } }
23.stuxuanServlet(学生自助选课)

package com.xxxx.servlet; import com.xxxx.entity.Cla; import com.xxxx.entity.Stu; import com.xxxx.mapper.ClaMapper; import com.xxxx.mapper.StuMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; 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("/stuxuanServlet") public class stuxuanServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); int claid= Integer.parseInt(request.getParameter("claid")); int stuid= Integer.parseInt(request.getParameter("stuid")); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); ClaMapper claMapper=sqlSession.getMapper(ClaMapper.class); Cla cla=claMapper.selectByid(claid);//找到原本的已选人数 if(cla.getXuan()==cla.getPeople()){ request.setAttribute("msg","选课人数已满"); request.getRequestDispatcher("stuxuan.jsp").forward(request,response); } else { StuMapper stuMapper = sqlSession.getMapper(StuMapper.class); stuMapper.updateCla(stuid, claid);//更新学生表中的选课信息 claMapper.updateXuan(cla.getId(), cla.getXuan()+1);//更改已选人数 response.getWriter().write("选课成功"); response.getWriter().close(); sqlSession.close(); } } }
24.teaclaServlet(教师对授课的人数进行修改)

package com.xxxx.servlet; import com.xxxx.mapper.ClaMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; 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("/teaclaServlet") public class teaclaServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); int id= Integer.parseInt(request.getParameter("id"));//获取课程id int xuan= Integer.parseInt(request.getParameter("xuan"));//获取已选人数 SqlSession sqlSession= GetSqlSession.CreateSqlSession(); ClaMapper claMapper=sqlSession.getMapper(ClaMapper.class); claMapper.updateXuan(id,xuan-1); response.getWriter().write("修改课程已选人数成功"); response.getWriter().close(); sqlSession.close(); } }
25.upclaServlet(管理员修改课程信息)

package com.xxxx.servlet; import com.xxxx.entity.Cla; import com.xxxx.entity.Stu; import com.xxxx.mapper.ClaMapper; import com.xxxx.mapper.StuMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; 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("/upclaServlet") public class upclaServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); int id= Integer.valueOf((String) request.getSession().getAttribute("id"));//获取要修改的id写int会出错** // String name=request.getParameter("name");//课程名称 String time=request.getParameter("time");//开课时间星期几 String ci =request.getParameter("ci");//上课时间1-2节 String yuan=request.getParameter("yuan");//开课院系 String tea =request.getParameter("tea");//任课老师名字 int teaid = Integer.parseInt(request.getParameter("teaid"));//老师id int people = Integer.parseInt(request.getParameter("people"));//限制人数 Cla cla=new Cla(); cla.setId(id);cla.setTime(time);cla.setCi(ci);cla.setYuan(yuan);cla.setTea(tea);cla.setTeaid(teaid);cla.setPeople(people); SqlSession sqlSession = GetSqlSession.CreateSqlSession(); ClaMapper claMapper = sqlSession.getMapper(ClaMapper.class); claMapper.update(cla); response.getWriter().write("修改成功"); response.getWriter().close(); sqlSession.close(); } }
26.upstuServlet(管理员修改学生信息)

package com.xxxx.servlet; import com.xxxx.entity.Stu; import com.xxxx.mapper.StuMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; 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("/upstuServlet") public class upstuServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); int id= Integer.valueOf((String) request.getSession().getAttribute("id"));//获取要修改的id写int会出错** String name=request.getParameter("name"); //姓名 String sex=request.getParameter("sex"); //性别 int age= Integer.parseInt(request.getParameter("age")); //年龄 String pro=request.getParameter("pro"); //专业 String cla=request.getParameter("cla"); //班级 Stu stu=new Stu(id,name,sex,age,pro,cla); SqlSession sqlSession = GetSqlSession.CreateSqlSession(); StuMapper stuMapper = sqlSession.getMapper(StuMapper.class); stuMapper.update(stu); response.getWriter().write("修改成功"); response.getWriter().close(); sqlSession.close(); } }
27.upteaServlet(管理员修改教师信息)

package com.xxxx.servlet; import com.xxxx.entity.Stu; import com.xxxx.entity.Tea; import com.xxxx.mapper.StuMapper; import com.xxxx.mapper.TeaMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; 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("/upteaServlet") public class upteaServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); int eid= Integer.valueOf((String) request.getSession().getAttribute("eid"));//获取要修改的id写int会出错**接收先前的id int id = Integer.parseInt(request.getParameter("id"));//工号 String name =request.getParameter("name");//姓名 String pro =request.getParameter("pro");//职位 String yuan =request.getParameter("yuan");//所属院 Tea tea=new Tea(id,name,pro,yuan); SqlSession sqlSession = GetSqlSession.CreateSqlSession(); TeaMapper teaMapper = sqlSession.getMapper(TeaMapper.class); teaMapper.updateByeid(tea,eid); response.getWriter().write("修改成功"); response.getWriter().close(); sqlSession.close(); } }
28.upupwdServlet(管理员重置密码)

package com.xxxx.servlet; import com.xxxx.mapper.LoginMapper; import com.xxxx.mapper.StuMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; 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("/upupwdServlet") public class upupwdServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); String uname= (String) request.getSession().getAttribute("uname"); SqlSession sqlSession = GetSqlSession.CreateSqlSession(); LoginMapper loginMapper = sqlSession.getMapper(LoginMapper.class); loginMapper.updateByuname(uname); response.getWriter().write("重置密码成功"); response.getWriter().close(); sqlSession.close(); } }
29.yemianServlet(用于登录的时候判断密码是否正确、用户名是否存在)

package com.xxxx.servlet; import com.xxxx.entity.Login; import com.xxxx.mapper.LoginMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; 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; /** * 账户存在-->比较密码: * 正确-->判断登录身份-->进入对应身份的显示页面(重定向:session) * 错误-->回去刚刚的登录页面(跳转) */ @WebServlet("/yemianServlet") public class yemianServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); String uname=request.getParameter("uname");//账号 String upwd=request.getParameter("upwd");//密码 String logintype=request.getParameter("logintype");//登录身份 SqlSession sqlSession = GetSqlSession.CreateSqlSession(); LoginMapper loginMapper = sqlSession.getMapper(LoginMapper.class); Login login=loginMapper.selectByUname(uname); if(login!=null){ if(!upwd.equals(login.getUpwd())){ request.setAttribute("msg","密码错误"); request.getRequestDispatcher("yemian.jsp").forward(request,response); } else { request.getSession().setAttribute("uname",uname);//设置域对象,范围:**session** if(logintype.equals("学生")) response.sendRedirect("stu.jsp"); else if(logintype.equals("教师")) response.sendRedirect("tea.jsp"); else response.sendRedirect("admin.jsp"); } } else{ request.setAttribute("msg","用户不存在"); request.getRequestDispatcher("yemian.jsp").forward(request,response); } sqlSession.close();//关闭资源 } }
工具类层
30.GetSqlSession(用于获取sqlsession对象)

package com.xxxx.util; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import java.io.IOException; import java.io.InputStream; public class GetSqlSession { /** * 获取SqlSession对象 */ public static SqlSession CreateSqlSession() throws IOException { String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); //获取SqlSession对象 SqlSession sqlSession = sqlSessionFactory.openSession(true);//关闭事物,否则要手动提交事务 return sqlSession; } }
JSP代码
31.yemian.jsp(总页面:选择登录身份+登录页面)

<%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/13 Time: 0:22 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <%-- 选择登录界面:学生、教师、管理员,并且输入账号密码 --%> <head> <title>选择登录</title> </head> <body> <form method="post" action="yemianServlet"> <h2>石家庄铁道大学学生选课管理系统</h2> 账号:<input name="uname" type="text" id="uname"><br> 密码:<input name="upwd" type="password" id="upwd"><br> 选择登录身份:<input type="radio" name="logintype" value="学生" checked>学生 <input type="radio" name="logintype" value="教师">教师 <input type="radio" name="logintype" value="管理员">管理员<br> <button>登录</button><span style="font-size: 15px;color: red" id="msg">${msg}</span> </form> </body> </html>
32.addcla.jsp(管理员添加课程)

<%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/13 Time: 1:16 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>addscla.jsp</title> </head> <body> <h2 align="center">添加课程信息</h2> <table align="center" width="800" border="1"> <form method="post" action="addclaServlet"> <tr> <td>课程编号</td> <td>系统自动生成</td> </tr> <tr> <td>课程名称</td> <td><input type="text" name="name"></td> </tr> <tr> <td>开课时间</td> <td> <select name="time"> <option value="星期一" selected>星期一</option> <option value="星期二">星期二</option> <option value="星期三">星期三</option> <option value="星期四">星期四</option> <option value="星期五">星期五</option> </select> </td> </tr> <tr> <td>开课节次</td> <td> <select name="ci"> <option value="1-2节" selected>1-2节</option> <option value="3-4节">3-4节</option> <option value="5-6节">5-6节</option> <option value="7-8节">7-8节</option> <option value="9-10节">9-10节</option> </select> </td> </tr> <tr> <td>所属学院</td> <td> <select name="yuan" id="yuan"> <option value="信息" >信息</option> <option value="土木" >土木</option> <option value="机械" >机械</option> <option value="电气" >电气</option> <option value="交通" >交通</option> </select> </td> </tr> <tr> <td>任课教师工号</td> <td><input type="text" name="teaid"></td> </tr> <tr> <td>任课教师名称</td> <td><input type="text" name="tea"></td> </tr> <tr> <td>选课限制人数</td> <td><input type="text" name="people"></td> </tr> <tr align="center"> <td colspan="2"><button>添加</button></td> </tr> </form> </table> </body> </html>
33.addstu.jsp(管理员添加学生)

<%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/13 Time: 1:16 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>addstu.jsp</title> </head> <body> <h2 align="center">添加学生信息</h2> <table align="center" width="800" border="1"> <form method="post" action="addstuServlet"> <tr> <td>学号</td> <td>系统自动生成</td> </tr> <tr> <td>姓名</td> <td><input type="text" name="name" id="name"></td> </tr> <tr> <td>性别</td> <td> <input type="radio" name="sex" value="男" checked>男 <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="pro" value="计算机科学与技术" checked>计算机科学与技术<br> <input type="radio" name="pro" value="软件工程">软件工程<br> <input type="radio" name="pro" value="网络工程">网络工程<br> <input type="radio" name="pro" value="数字媒体技术">数字媒体技术<br> </td> </tr> <tr> <td>班级</td> <td><input type="text" name="cla" id="cla"></td> </tr> <tr align="center"> <td colspan="2"><button>添加</button></td> </tr> </form> </table> </body> </html>
34.addtea.jsp(管理员添加教师)

<%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/13 Time: 1:16 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>addtea.jsp</title> </head> <%--工号和院需要校验 不要忘记return!! <td colspan="2"><button type="button" id="addBtn">添加</button></td>注意要写type,不然自动提交 --%> <body> <h2 align="center">添加教师信息</h2> <table align="center" width="800" border="1"> <form method="post" action="addteaServlet" id="addForm"> <tr> <td>工号</td> <td><input type="text" name="id" id="id"><span id="msg1" style="font-size: 16px;color: red"></span> </td> </tr> <tr> <td>姓名</td> <td><input type="text" name="name" id="name"></td> </tr> <tr> <td>职称</td> <td> <input type="radio" name="pro" value="助教">助教<br> <input type="radio" name="pro" value="讲师">讲师<br> <input type="radio" name="pro" value="副教授">副教授<br> <input type="radio" name="pro" value="教授">教授<br> </td> </tr> <tr> <td>所属学院</td> <td> <select name="yuan" id="yuan"> <option value="信息" >信息</option> <option value="土木" >土木</option> <option value="机械" >机械</option> <option value="电气" >电气</option> <option value="交通" >交通</option> </select> </td> </tr> <tr align="center"> <td colspan="2"><span id="msg2" style="font-size: 16px;color: red"></span><br><button type="button" id="addBtn">添加</button></td> </tr> </form> </table> <%--使用js校验 先验证工号格式,6位数字,前两位01-05 再看院系和工号是否对应 格式都正确,就提交表单 注意:不要忘记return 问题:如果第一次是工号和院系不匹配,弹出错误信息之后,下一次不刷新进行修改,这个错误信息会一直存在! --%> <script type="text/javascript" src="js/jquery-3.6.1.js"></script> <script type="text/javascript"> $("#addBtn").click(function(){ var id=$("#id").val(); var yuan=$("#yuan").val(); //先验证工号格式,6位数字,前两位01-5 if(isNaN(id)|| id.length!=6){ $("#msg1").html("工号格式错误1");return;//不要忘记return } else{ if(id[0]!='0'||id[1]>5||id[1]<1){//*** //工号错误 $("#msg1").html("工号格式错误2");return; } else { //工号正确了-->判断工号和院系是否对应 if((id[1]==1&&yuan!="信息")||(id[1]==2&&yuan!="土木")||(id[1]==3&&yuan!="机械")||(id[1]==4&&yuan!="电气")||(id[1]==5&&yuan!="交通")){ //工号和院系不匹配 $("#msg2").html("工号和院系不匹配");return; } else{ //所有条件都满足了 $("#addForm").submit(); } } } }); </script> </body> </html>
35.admin.jsp(管理员总页面)

<%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/13 Time: 0:53 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>admin.jsp</title> </head> <%--管理员选择页面:问题:很多会出现重复--%> <body> <h3>欢迎${uname}登录</h3> <a href="addstu.jsp">添加学生基本信息</a> <br> <a href="selectstu.jsp">修改学生基本信息</a><br> <a href="selectstu.jsp">删除学生基本信息</a> <br> <a href="addtea.jsp">添加教师基本信息</a> <br> <a href="selecttea.jsp">修改教师基本信息</a><br> <a href="selecttea.jsp">删除教师基本信息</a><br> <a href="addcla.jsp">新添课程基本信息</a><br> <a href="selectcla.jsp">修改课程基本信息</a><br> <a href="selectcla.jsp">删除课程基本信息</a><br> <a href="selectupwd.jsp">密码重置</a><br> </body> </html>
36.selectcla.jsp(管理员查询课程所有信息,可以进行修改、删除操作)超链接

<%@ page import="com.xxxx.util.GetSqlSession" %> <%@ page import="org.apache.ibatis.session.SqlSession" %> <%@ page import="com.xxxx.mapper.ClaMapper" %> <%@ page import="com.xxxx.entity.Cla" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/15 Time: 10:19 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>selectcla.jsp</title> </head> <%--浏览所有课程信息,方便选择修改信息或者删除信息,超链接--%> <body> <table align="center" border="1" width="800"> <tr> <td>课程编号</td><td>课程名称</td><td>开课时间</td><td>上课时间</td><td>开课院系</td> <td>任课老师</td><td>老师工号</td><td>限制人数</td><td></td> </tr> <% SqlSession sqlSession = GetSqlSession.CreateSqlSession(); ClaMapper claMapper = sqlSession.getMapper(ClaMapper.class); Cla[] clas=claMapper.selectAll(); for (Cla cla:clas) { %> <tr> <td><%=cla.getId()%></td><td><%=cla.getName()%></td><td><%=cla.getTime()%></td><td><%=cla.getCi()%></td> <td><%=cla.getYuan()%></td><td><%=cla.getTea()%></td><td><%=cla.getTeaid()%></td><td><%=cla.getPeople()%></td> <td><a href="upcla.jsp?id=<%=cla.getId()%>&name=<%=cla.getName()%>">修改</a> <a href="declaServlet?id=<%=cla.getId()%>&xuan=<%=cla.getXuan()%>">删除</a> </td> </tr> <% } sqlSession.close(); %> </body> </html>
37.selectstu.jsp(管理员查询所有学生信息,可以进行删除、修改)超链接

<%@ page import="org.apache.ibatis.session.SqlSession" %> <%@ page import="com.xxxx.util.GetSqlSession" %> <%@ page import="com.xxxx.mapper.StuMapper" %> <%@ page import="com.xxxx.entity.Stu" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/14 Time: 23:41 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>selectstu.jsp</title> </head> <%--浏览所有学生,方便选择修改信息或者删除信息,超链接--%> <body> <table align="center" border="1" width="800"> <tr> <td>学生学号</td><td>学生姓名</td><td>性别</td><td>年龄</td><td>专业</td><td>班级</td><td></td> </tr> <% SqlSession sqlSession = GetSqlSession.CreateSqlSession(); StuMapper stuMapper = sqlSession.getMapper(StuMapper.class); Stu[] stus=stuMapper.selectAll(); for (Stu stu:stus) { %> <tr> <td><%=stu.getId()%></td><td><%=stu.getName()%></td><td><%=stu.getSex()%></td><td><%=stu.getAge()%></td><td><%=stu.getPro()%></td><td><%=stu.getCla()%></td> <td><a href="upstu.jsp?id=<%=stu.getId()%>">修改</a> <a href="destuServlet?id=<%=stu.getId()%>">删除</a> </td> </tr> <% } sqlSession.close(); %> </table> </body> </html>
38.selecttea.jsp(管理员查询所有教师信息,可以进行删除、修改)超链接

<%@ page import="com.xxxx.entity.Tea" %> <%@ page import="com.xxxx.mapper.TeaMapper" %> <%@ page import="com.xxxx.util.GetSqlSession" %> <%@ page import="org.apache.ibatis.session.SqlSession" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/15 Time: 10:19 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>selecttea.jsp</title> </head> <%--浏览所有教师,方便选择修改信息或者删除信息,超链接--%> <body> <table align="center" border="1" width="800"> <tr> <td>工号</td><td>姓名</td><td>职位</td><td>所属院</td><td></td> </tr> <% SqlSession sqlSession = GetSqlSession.CreateSqlSession(); TeaMapper teaMapper = sqlSession.getMapper(TeaMapper.class); Tea[] teas=teaMapper.selectAll(); for (Tea tea:teas) { %> <tr> <td><%=tea.getId()%></td><td><%=tea.getName()%></td><td><%=tea.getPro()%></td><td><%=tea.getYuan()%></td> <td><a href="uptea.jsp?id=<%=tea.getId()%>">修改</a> <a href="deteaServlet?id=<%=tea.getId()%>&teaname=<%=tea.getName()%>">删除</a> </td> </tr> <% } sqlSession.close(); %> </body> </html>
39.selectupwd.jsp(管理员通过输入学生、教师id进行密码重置)

<%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/15 Time: 12:36 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>selectupwd</title> </head> <%--管理员重置密码前需要把教师或学生的id输入,先查询再修改--%> <body> <form action="selectupwdServlet" method="post"> 输入id<input type="text" name="id"><br> 被修改用户身份:<input type="radio" name="type" value="教师">教师 <input type="radio" name="type" value="学生">学生<br> <span name="msg" style="font-size: 16px;color: red">${msg}</span>- <button>查询</button> </form> </body> </html>
40.stu.jsp(学生总功能页面)

<%@ page import="com.xxxx.entity.Stu" %> <%@ page import="com.xxxx.mapper.StuMapper" %> <%@ page import="com.xxxx.util.GetSqlSession" %> <%@ page import="org.apache.ibatis.session.SqlSession" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/13 Time: 0:53 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>stu.jsp</title> </head> <%--学生功能页--%> <body> <% String uname= (String) request.getSession().getAttribute("uname");//获取一下uname,方便日后chaxun request.getSession().setAttribute("uname",uname); // request.getSession().setAttribute("type","1");//1为学生,2为教师 // 查找学生的id,因为有了id就可以直接使用管理员修改学生信息页面,不用再写,只需要把id传过去 SqlSession sqlSession = GetSqlSession.CreateSqlSession(); StuMapper stuMapper = sqlSession.getMapper(StuMapper.class); Stu stu=stuMapper.selectByName(uname); request.getSession().setAttribute("stuid",stu.getId()); %> <h3>欢迎${uname}登录</h3> <a href="stuselect.jsp">查询个人信息</a><br> <a href="upstu.jsp?id=<%=stu.getId()%>">修改个人信息</a><br> <a href="stupwd.jsp">修改个人密码</a><br> <a href="stuallcla.jsp">查询课程信息</a><br> <a href="stuxuan.jsp?id=<%=stu.getId()%>">自助选课</a><br> <a href="stucla.jsp">查询个人课表</a> </body> </html>
41.stuallcla.jsp(学生查询学校所有课程信息)

<%@ page import="com.xxxx.entity.Cla" %> <%@ page import="com.xxxx.mapper.ClaMapper" %> <%@ page import="com.xxxx.util.GetSqlSession" %> <%@ page import="org.apache.ibatis.session.SqlSession" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/16 Time: 15:27 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>stuallcla.jsp</title> </head> <%--查询 学校所有 课程信息,可以直接复制selectcla,唯一要修改的是学生没有修改课程的功能,把相应的给删了就好了--%> <body> <table align="center" border="1" width="800"> <tr> <td>课程编号</td><td>课程名称</td><td>开课时间</td><td>上课时间</td><td>开课院系</td> <td>任课老师</td><td>老师工号</td><td>限制人数</td><td>已选人数</td> </tr> <% SqlSession sqlSession = GetSqlSession.CreateSqlSession(); ClaMapper claMapper = sqlSession.getMapper(ClaMapper.class); Cla[] clas=claMapper.selectAll(); for (Cla cla:clas) { %> <tr> <td><%=cla.getId()%></td><td><%=cla.getName()%></td><td><%=cla.getTime()%></td><td><%=cla.getCi()%></td> <td><%=cla.getYuan()%></td><td><%=cla.getTea()%></td><td><%=cla.getTeaid()%></td><td><%=cla.getPeople()%></td> <td><%=cla.getXuan()%> </td> </tr> <% } sqlSession.close(); %> </table> </body> </html>
42.stucla.jsp(学生查询个人课表)

<%@ page import="com.xxxx.entity.Stu" %> <%@ page import="com.xxxx.mapper.StuMapper" %> <%@ page import="org.apache.ibatis.session.SqlSession" %> <%@ page import="com.xxxx.util.GetSqlSession" %> <%@ page import="com.xxxx.mapper.ClaMapper" %> <%@ page import="com.xxxx.entity.Cla" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/16 Time: 15:28 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>stucla.jsp</title> </head> <%--查询个人课表--%> <body> <% String uname= (String)request.getSession().getAttribute("uname"); SqlSession sqlSession = GetSqlSession.CreateSqlSession(); StuMapper stuMapper = sqlSession.getMapper(StuMapper.class); Stu stu=stuMapper.selectByName(uname); ClaMapper claMapper=sqlSession.getMapper(ClaMapper.class); Cla cla=claMapper.selectByid(stu.getClaid()); %> <table align="center" border="1" width="800"> <tr> <td>课程编号</td><td>课程名称</td><td>开课时间</td><td>上课时间</td><td>开课院系</td> <td>任课老师</td><td>老师工号</td><td>限制人数</td> </tr> <tr> <td><%=cla.getId()%></td><td><%=cla.getName()%></td><td><%=cla.getTime()%></td><td><%=cla.getCi()%></td> <td><%=cla.getYuan()%></td><td><%=cla.getTea()%></td><td><%=cla.getTeaid()%></td><td><%=cla.getPeople()%></td> </tr> </table> </body> </html>
43.stupwd.jsp(学生和教师修改个人密码)

<%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/16 Time: 15:27 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>stupwd.jsp</title> </head> <%--修改个人密码--%> <body> <% String uname= (String) request.getSession().getAttribute("uname"); request.getSession().setAttribute("uname",uname); %> <form action="stupwdServlet" method="post"> 账户:<%=uname%><br>密码:<input type="password" name="upwd"><br> <span id="msg" style="color: red;font-size: 16px">${msg}</span> <button>修改</button> </form> </body> </html>
44.stuselect.jsp(学生查询个人信息)

<%@ page import="org.apache.ibatis.session.SqlSession" %> <%@ page import="com.xxxx.util.GetSqlSession" %> <%@ page import="com.xxxx.mapper.StuMapper" %> <%@ page import="com.xxxx.entity.Stu" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/16 Time: 15:25 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>stuselect.jsp</title> </head> <%--查询个人信息--%> <body> <table align="center" border="1" width="800"> <tr> <td>学生学号</td><td>学生姓名</td><td>性别</td><td>年龄</td><td>专业</td><td>班级</td><td>已选课程</td> </tr> <% String uname= (String) request.getSession().getAttribute("uname"); // String type= (String) request.getSession().getAttribute("type"); SqlSession sqlSession = GetSqlSession.CreateSqlSession(); StuMapper stuMapper = sqlSession.getMapper(StuMapper.class); Stu stu=stuMapper.selectByName(uname); %> <tr> <td><%=stu.getId()%></td><td><%=stu.getName()%></td><td><%=stu.getSex()%></td><td><%=stu.getAge()%></td><td><%=stu.getPro()%></td><td><%=stu.getCla()%></td> <td><%=stu.getClaid()%></td> </tr> </table> </body> </html>
45.stuxuan.jsp(学生自助选课)

<%@ page import="org.apache.ibatis.session.SqlSession" %> <%@ page import="com.xxxx.util.GetSqlSession" %> <%@ page import="com.xxxx.mapper.ClaMapper" %> <%@ page import="com.xxxx.entity.Cla" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/16 Time: 15:28 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>stuxuan.jsp</title> </head> <%--学生自助选课,直接复制stuallcla,即浏览课程信息,唯一要变的是添加选课按钮, 然后到Servlet中判断选课人数是否超标,是则返回提示信息,否则就对学生表和课表进行修改--%> <body> <table align="center" border="1" width="800"> <tr> <td>课程编号</td><td>课程名称</td><td>开课时间</td><td>上课时间</td><td>开课院系</td> <td>任课老师</td><td>老师工号</td><td>限制人数</td><td>已选人数</td><td></td> </tr> <% int stuid=(int) request.getSession().getAttribute("stuid"); request.getSession().setAttribute("stuid",stuid); SqlSession sqlSession = GetSqlSession.CreateSqlSession(); ClaMapper claMapper = sqlSession.getMapper(ClaMapper.class); Cla[] clas=claMapper.selectAll(); for (Cla cla:clas) { %> <tr> <td><%=cla.getId()%></td><td><%=cla.getName()%></td><td><%=cla.getTime()%></td><td><%=cla.getCi()%></td> <td><%=cla.getYuan()%></td><td><%=cla.getTea()%></td><td><%=cla.getTeaid()%></td><td><%=cla.getPeople()%></td> <td><%=cla.getXuan()%></td><td><a href="stuxuanServlet?claid=<%=cla.getId()%>&stuid=<%=stuid%>">选课</a></td> </tr> <% } sqlSession.close(); %> <tr align="center"><td colspan="10"> <span style="font-size: 16px;color: red" id="msg">${msg}</span></td></tr> </body> </html>
46.tea.jsp(教师总功能页面)

<%@ page import="org.apache.ibatis.session.SqlSession" %> <%@ page import="com.xxxx.util.GetSqlSession" %> <%@ page import="com.xxxx.mapper.TeaMapper" %> <%@ page import="com.xxxx.entity.Tea" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/13 Time: 0:53 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>tea.jsp</title> </head> <% String uname=(String)request.getSession().getAttribute("uname"); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); TeaMapper teaMapper=sqlSession.getMapper(TeaMapper.class); Tea tea=teaMapper.selectByname(uname); request.getSession().setAttribute("tea",tea); request.getSession().setAttribute("uname",uname);//修改密码需要传递的 sqlSession.close(); %> <body> 欢迎${uname}登录<br> <a href="teaselect.jsp">查看教师个人信息</a><br> <a href="uptea.jsp?id=<%=tea.getId()%>">修改个人信息</a><br> <a href="stupwd.jsp">修改个人密码</a><br> <a href="teacla.jsp">修改个人所授课</a><br> <a href="teacla.jsp">查询个人课表</a><br> </body> </html>
47.teacla.jsp(教师查询授课的课程信息,可以进行修改)超链接

<%@ page import="com.xxxx.entity.Tea" %> <%@ page import="org.apache.ibatis.session.SqlSession" %> <%@ page import="com.xxxx.util.GetSqlSession" %> <%@ page import="com.xxxx.mapper.ClaMapper" %> <%@ page import="com.xxxx.entity.Cla" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/17 Time: 16:31 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>teacla.jsp</title> </head> <%--教师查询到自己的课程信息,可以点击修改进行修改--%> <body> <table align="center" border="1" width="800"> <tr> <td>课程编号</td><td>课程名称</td><td>开课时间</td><td>上课时间</td><td>开课院系</td> <td>任课老师</td><td>老师工号</td><td>限制人数</td><td>已选人数</td> </tr> <% String uname= (String) request.getSession().getAttribute("uname"); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); ClaMapper claMapper=sqlSession.getMapper(ClaMapper.class); Cla[] clas=claMapper.selectByteaname(uname);//查询到该老师的所有课程信息 for (Cla cla:clas) { %> <tr> <td><%=cla.getId()%></td><td><%=cla.getName()%></td><td><%=cla.getTime()%></td><td><%=cla.getCi()%></td> <td><%=cla.getYuan()%></td><td><%=cla.getTea()%></td><td><%=cla.getTeaid()%></td><td><%=cla.getPeople()%></td><td><%=cla.getXuan()%> <a href="teaclaServlet?id=<%=cla.getId()%>&xuan=<%=cla.getXuan()%>">修改</a></td> </tr> <% } %> </table> </body> </html>
48.teaselect.jsp(教师个人信息显示)

<%@ page import="com.xxxx.entity.Tea" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/17 Time: 15:36 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>teaselect.jsp</title> </head> <%--显示教师个人信息--%> <body> <% Tea tea=(Tea)request.getSession().getAttribute("tea"); %> <table align="center" border="1" width="800"> <tr> <td>工号</td><td>姓名</td><td>职位</td><td>所属院</td> </tr> <tr> <td><%=tea.getId()%></td><td><%=tea.getName()%></td><td><%=tea.getPro()%></td><td><%=tea.getYuan()%></td></tr> </table> </body> </html>
49.upcla.jsp(管理员修改课程信息)

<%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/13 Time: 1:16 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>upcla.jsp</title> </head> <% String id=request.getParameter("id");//获取超链接传过来的id(不可修改) request.getSession().setAttribute("id",id);//设置域对象 String name=request.getParameter("name");//(不可修改) %> <body> <h2 align="center">修改课程信息</h2> <table align="center" width="800" border="1"> <form method="post" action="upclaServlet"> <tr> <td>课程编号</td> <td><%=id%> (不可修改)</td> </tr> <tr> <td>课程名称</td> <td><%=name%> (不可修改)</td> </tr> <tr> <td>开课时间</td> <td> <select name="time"> <option value="星期一" selected>星期一</option> <option value="星期二">星期二</option> <option value="星期三">星期三</option> <option value="星期四">星期四</option> <option value="星期五">星期五</option> </select> </td> </tr> <tr> <td>开课节次</td> <td> <select name="ci"> <option value="1-2节" selected>1-2节</option> <option value="3-4节">3-4节</option> <option value="5-6节">5-6节</option> <option value="7-8节">7-8节</option> <option value="9-10节">9-10节</option> </select> </td> </tr> <tr> <td>所属学院</td> <td> <select name="yuan" id="yuan"> <option value="信息" >信息</option> <option value="土木" >土木</option> <option value="机械" >机械</option> <option value="电气" >电气</option> <option value="交通" >交通</option> </select> </td> </tr> <tr> <td>任课教师工号</td> <td><input type="text" name="teaid"></td> </tr> <tr> <td>任课教师名称</td> <td><input type="text" name="tea"></td> </tr> <tr> <td>选课限制人数</td> <td><input type="text" name="people"></td> </tr> <tr align="center"> <td colspan="2"><button>修改</button></td> </tr> </form> </table> </body> </html>
50.upstu.jsp(管理员修改学生信息)

<%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/13 Time: 1:16 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>upstu.jsp</title> </head> <%--不符合*录入格式*,不可修改,,没完成--%> <body> <% String id=request.getParameter("id");//获取超链接传过来的id request.getSession().setAttribute("id",id);//设置域对象 %> <h2 align="center">修改学生信息</h2> <table align="center" width="800" border="1"> <form method="post" action="upstuServlet"> <tr> <td>学号</td> <td><%=id%></td> </tr> <tr> <td>姓名</td> <td><input type="text" name="name" id="name"></td> </tr> <tr> <td>性别</td> <td> <input type="radio" name="sex" value="男" checked>男 <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="pro" value="计算机科学与技术" checked>计算机科学与技术<br> <input type="radio" name="pro" value="软件工程">软件工程<br> <input type="radio" name="pro" value="网络工程">网络工程<br> <input type="radio" name="pro" value="数字媒体技术">数字媒体技术<br> </td> </tr> <tr> <td>班级</td> <td><input type="text" name="cla" id="cla"></td> </tr> <tr align="center"> <td colspan="2"><button>修改</button></td> </tr> </form> </table> </body> </html>
51.uptea.jsp(管理员修改教师信息)

<%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/13 Time: 1:16 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>uptea.jsp</title> </head> <body> <% String eid=request.getParameter("id");//获取超链接传过来的id request.getSession().setAttribute("eid",eid);//设置域对象 %> <h2 align="center">修改教师信息</h2> <table align="center" width="800" border="1"> <form method="post" action="upteaServlet" name="upForm" id="upForm"> <tr> <td>工号</td> <td><input type="text" name="id" id="id"><span id="msg1" style="font-size: 16px;color: red"></span> </td> </tr> <tr> <td>姓名</td> <td><input type="text" name="name" id="name"></td> </tr> <tr> <td>职称</td> <td> <input type="radio" name="pro" value="助教">助教<br> <input type="radio" name="pro" value="讲师">讲师<br> <input type="radio" name="pro" value="副教授">副教授<br> <input type="radio" name="pro" value="教授">教授<br> </td> </tr> <tr> <td>所属学院</td> <td> <select name="yuan" id="yuan"> <option value="信息" >信息</option> <option value="土木" >土木</option> <option value="机械" >机械</option> <option value="电气" >电气</option> <option value="交通" >交通</option> </select> </td> </tr> <tr> <td colspan="2"><span style="font-size: 16px;color:red;" id="msg2"></span> </td> </tr> <tr align="center"> <td colspan="2"><button type="button" id="upBtn">修改</button></td> </tr> </form> </table> </body> <script type="text/javascript" src="js/jquery-3.6.1.js"></script> <script type="text/javascript"> $("#upBtn").click(function(){ var id=$("#id").val(); var yuan=$("#yuan").val(); //先验证工号格式,6位数字,前两位01-5 if(isNaN(id)|| id.length!=6){ $("#msg1").html("工号格式错误1");return;//不要忘记return } else{ if(id[0]!='0'||id[1]>5||id[1]<1){//*** //工号错误 $("#msg1").html("工号格式错误2");return; } else { //工号正确了-->判断工号和院系是否对应 if((id[1]==1&&yuan!="信息")||(id[1]==2&&yuan!="土木")||(id[1]==3&&yuan!="机械")||(id[1]==4&&yuan!="电气")||(id[1]==5&&yuan!="交通")){ //工号和院系不匹配 $("#msg2").html("工号和院系不匹配");return; } else{ //所有条件都满足了 $("#upForm").submit(); } } } }); </script> </html>
52.upupwd.jsp(管理员重置密码)

<%@ page import="com.xxxx.entity.Stu" %> <%@ page import="com.xxxx.entity.Tea" %> <%@ page import="org.apache.ibatis.session.SqlSession" %> <%@ page import="com.xxxx.util.GetSqlSession" %> <%@ page import="com.xxxx.mapper.LoginMapper" %> <%@ page import="com.xxxx.entity.Login" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/13 Time: 1:16 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>upupwd.jsp</title> </head> <%--修改密码,我想直接在js中修改--%> <body> <% String type= (String) request.getSession().getAttribute("type"); SqlSession sqlSession = GetSqlSession.CreateSqlSession(); LoginMapper loginMapper = sqlSession.getMapper(LoginMapper.class); Login login;String uname;//为了后面能调用login if(type.equals("1")){//学生 Stu stu= (Stu) request.getSession().getAttribute("stu"); uname=stu.getName(); login=loginMapper.selectByUname(stu.getName()); } else{//老师 Tea tea=(Tea)request.getSession().getAttribute("tea"); uname=tea.getName(); login=loginMapper.selectByUname(tea.getName()); } request.getSession().setAttribute("uname",uname);//设立域对象 %> <h2 align="center">重置密码</h2> <table align="center" width="800" border="1"> <form method="post" action="upupwdServlet"> <tr> <td>账户</td> <td><%=login.getUname()%></td> </tr> <tr> <td>密码</td> <td><%=login.getUpwd()%></td> </tr> <span id="msg" style="font-size: 16px;color: red"></span> <tr align="center"> <td colspan="2"><button>重置密码</button></td> </tr> </form> </table> </body> </html>
问题:
有很多问题,如学生表中的课程只能是一个课程信息,然后学生表中和教师表应该都要添加一个账号、密码属性供登录......
学生选课系统--管理员--修改信息功能 - yuanse - 博客园 (cnblogs.com)
学生选课系统--管理员--删除功能 - yuanse - 博客园 (cnblogs.com)
学生选课系统--管理员功能实现 - yuanse - 博客园 (cnblogs.com)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!