IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统

目录

一、系统介绍

1.开发环境

2.技术选型

3.系统功能

4.数据库文件

5.工程截图

二、系统展示

1.登录系统

2.管理员-主页面

3.管理员-学生管理-查看所有

4.管理员-学生管理-添加学生

5.管理员-教师管理-查看所有

6.管理员-教师管理-添加教师

7.管理员-课程管理-课程查询

8.管理员-课程管理-课程审核

9.管理员-系统维护-添加公告

10.管理员-系统维护-查看公告

11.管理员-系统维护-教师功能开关

12.管理员-系统维护-学生功能开关

13.教师-主页面

14.教师-个人中心-修改资料

15.教师-课题管理-所有课题

16.教师-课题管理-我的课题

17.教师-课题管理-添加课题

18.学生-主页面

19.学生-个人中心-修改资料

20.学生-个人中心-我的选题

21.学生-开始选题-选题列表

22.学生-开始选题-选题明细

三、部分代码

StudentManager

TeacherManager

TopicManager

DB

Login.jsp

index.jsp

news.jsp

四、其他

1.更多系统

Java+JSP系统系列实现

Java+Servlet系统系列实现

Java+SSM系统系列实现

Java+SSH系统系列实现

Java+Springboot系统系列实现

2.源码下载

3.运行项目

4.备注

5.支持博主


一、系统介绍

1.开发环境

开发工具:IDEA2018

JDK版本:Jdk1.8

Mysql版本:8.0.13

2.技术选型

Java+Jsp+Mysql

3.系统功能

1.管理员登录系统,管理学生信息,管理教师信息,管理课题信息,系统维护功能;

2.教师登录系统,修改个人信息,添加课题,查看课题;

3.学生登录系统,修改个人信息,查看选题,选择课题;

4.数据库文件

/*
 Navicat Premium Data Transfer

 Source Server         : MYSQL
 Source Server Type    : MySQL
 Source Server Version : 80013
 Source Host           : localhost:3306
 Source Schema         : jsp_select_topic

 Target Server Type    : MySQL
 Target Server Version : 80013
 File Encoding         : 65001

 Date: 12/04/2022 09:04:43
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for msg
-- ----------------------------
DROP TABLE IF EXISTS `msg`;
CREATE TABLE `msg`  (
  `title` varchar(100) CHARACTER SET gb2312 COLLATE gb2312_chinese_ci NOT NULL,
  `text` varchar(1000) CHARACTER SET gb2312 COLLATE gb2312_chinese_ci NULL DEFAULT NULL,
  PRIMARY KEY (`title`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = gb2312 COLLATE = gb2312_chinese_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of msg
-- ----------------------------
INSERT INTO `msg` VALUES ('毕业设计选题系统初步完成', '整个系统流程大致为:老师发布课题,管理员审核\r\n\r\n课题,学生选题,学生完成设计');
INSERT INTO `msg` VALUES ('学生相关功能', '请各位学生登录系统,给自己选择一个课题!');

-- ----------------------------
-- Table structure for student_info
-- ----------------------------
DROP TABLE IF EXISTS `student_info`;
CREATE TABLE `student_info`  (
  `sno` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `sname` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `ssex` varchar(2) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `sclass` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `stel` varchar(11) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `semail` varchar(50) CHARACTER SET gbk COLLATE gbk_chinese_ci NULL DEFAULT NULL,
  `sgroup` varchar(1) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `spassword` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL COMMENT '6-10位字符',
  PRIMARY KEY (`sno`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = gbk COLLATE = gbk_chinese_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of student_info
-- ----------------------------
INSERT INTO `student_info` VALUES ('1001', '张三', '男', '4', '15523457667', '[email protected]', '2', '123456');
INSERT INTO `student_info` VALUES ('1002', '李四', '男', '2', '14456789876', '[email protected]', '2', '123456');
INSERT INTO `student_info` VALUES ('1003', '王五', '男', '3', '14456789876', '[email protected]', '3', '123456');
INSERT INTO `student_info` VALUES ('1004', '赵六', '男', '3', '14456789876', '[email protected]', '3', 'admin');

-- ----------------------------
-- Table structure for teacher_info
-- ----------------------------
DROP TABLE IF EXISTS `teacher_info`;
CREATE TABLE `teacher_info`  (
  `tno` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `tname` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `tsex` varchar(2) CHARACTER SET gbk COLLATE gbk_chinese_ci NULL DEFAULT NULL,
  `tdept` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `tdegree` varchar(8) CHARACTER SET gbk COLLATE gbk_chinese_ci NULL DEFAULT NULL,
  `ttitle` varchar(4) CHARACTER SET gbk COLLATE gbk_chinese_ci NULL DEFAULT NULL,
  `tright` bit(1) NOT NULL,
  `ttel` varchar(11) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `temail` varchar(50) CHARACTER SET gbk COLLATE gbk_chinese_ci NULL DEFAULT NULL,
  `tgroup` varchar(1) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `tpassword` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  PRIMARY KEY (`tno`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = gbk COLLATE = gbk_chinese_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of teacher_info
-- ----------------------------
INSERT INTO `teacher_info` VALUES ('101', 'admin', '男', '计算机科学与技术系', '硕士', '教授', b'0', '15315614829', '[email protected]', '4', 'admin');
INSERT INTO `teacher_info` VALUES ('102', '王老师', '男', '计算机科学与技术系', '硕士', '教授', b'1', '15315614829', '[email protected]', '4', '123456');
INSERT INTO `teacher_info` VALUES ('103', '李老师', '男', '计算机科学与技术系', '硕士', '助教', b'1', '13456789876', '[email protected]', '4', 'admin');

-- ----------------------------
-- Table structure for topic_info
-- ----------------------------
DROP TABLE IF EXISTS `topic_info`;
CREATE TABLE `topic_info`  (
  `hno` varchar(5) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `hname` varchar(50) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `htype` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `hkind` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `hsource` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `hstatus` varchar(5) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `hcontent` varchar(200) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `hresult` varchar(50) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `direction` varchar(200) CHARACTER SET gbk COLLATE gbk_chinese_ci NULL DEFAULT NULL,
  `tno` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  `sno` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NULL DEFAULT NULL,
  PRIMARY KEY (`hno`) USING BTREE,
  INDEX `FK_topicinfo`(`sno`) USING BTREE,
  INDEX `FK_topicinfo1`(`tno`) USING BTREE,
  CONSTRAINT `FK_topicinfo` FOREIGN KEY (`sno`) REFERENCES `student_info` (`sno`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  CONSTRAINT `FK_topicinfo1` FOREIGN KEY (`tno`) REFERENCES `teacher_info` (`tno`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = gbk COLLATE = gbk_chinese_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of topic_info
-- ----------------------------
INSERT INTO `topic_info` VALUES ('10001', '计算机技术体系研究', '毕业设计', '理论研究', '结合科研', 'true', '计算机技术体系研究', 'SCI发表相应论文', '无', '102', '1001');
INSERT INTO `topic_info` VALUES ('10002', '软件工程体系研究', '毕业设计', '软件研究', '结合科研', 'true', '软件工程体系研究', 'SCI发表论文', '无', '102', '1002');

SET FOREIGN_KEY_CHECKS = 1;

5.工程截图

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第1张图片

二、系统展示

1.登录系统

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第2张图片

2.管理员-主页面

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第3张图片

3.管理员-学生管理-查看所有

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第4张图片

4.管理员-学生管理-添加学生

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第5张图片

5.管理员-教师管理-查看所有

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第6张图片

6.管理员-教师管理-添加教师

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第7张图片

7.管理员-课程管理-课程查询

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第8张图片

8.管理员-课程管理-课程审核

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第9张图片

9.管理员-系统维护-添加公告

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第10张图片

10.管理员-系统维护-查看公告

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第11张图片

11.管理员-系统维护-教师功能开关

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第12张图片

12.管理员-系统维护-学生功能开关

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第13张图片

13.教师-主页面

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第14张图片

14.教师-个人中心-修改资料

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第15张图片

15.教师-课题管理-所有课题

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第16张图片

16.教师-课题管理-我的课题

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第17张图片

17.教师-课题管理-添加课题

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第18张图片

18.学生-主页面

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第19张图片

19.学生-个人中心-修改资料

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第20张图片

20.学生-个人中心-我的选题

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第21张图片

21.学生-开始选题-选题列表

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第22张图片

22.学生-开始选题-选题明细

IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统_第23张图片

三、部分代码

StudentManager

学生信息管理类,实现学生信息的增加,查看,删除。

package com.sjsq.service;

import com.sjsq.model.Student;
import com.sjsq.util.DB;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class StudentManager {
    /**
     * 添加新的单个Student信息到数据库中
     * @param stu 存有学生信息的Student对象
     * @return 保存成功返回true否则返回false
     */
    public static boolean save(Student stu) {
        Connection conn = DB.getConn();
        String sql = null;
        boolean b = false;
        sql = "insert into student_info values (?, ?, ?, ?, ?, ?, ?, ?)";
        PreparedStatement pstmt = DB.prepare(conn, sql);//预编译插入语句
        try {
            /*
             * 将stu中保存的信息分别放到数据库中对应表的对应列上
             */
            pstmt.setString(1, stu.getNumber());
            pstmt.setString(2, stu.getName());
            pstmt.setString(3, stu.getSex());
            pstmt.setString(4, stu.getSclass());
            pstmt.setString(5, stu.getPhone());
            pstmt.setString(6, stu.getEmail());
            pstmt.setString(7, stu.getGroup());
            pstmt.setString(8, stu.getPassword());
            pstmt.execute();
            b = true;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(pstmt);
            DB.close(conn);
        }
        return b;
    }


    /**
     * 获取所以学生信息
     * @param students 存放所以学生信息
     * @param pageNo 分页时的,当前页号
     * @param pageSize  每页显示学生的个数
     * @return 返回一共有多少页
     */
    public static int getStudents(List students, int pageNo,
                                  int pageSize) {

        int totalRecords = -1;

        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from student_info limit " + (pageNo - 1) * pageSize
                + "," + pageSize;
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);

        Statement stmtCount = DB.getStatement(conn);
        ResultSet rsCount = null;
        rsCount = DB.getResultSet(stmtCount,
                "select count(*) from student_info");

        try {
            rsCount.next();
            totalRecords = rsCount.getInt(1);//得到结果集中一共有多少条记录

            while (rs.next()) {
                Student student = new Student();
                student.setEmail(rs.getString("semail"));
                student.setGroup(rs.getString("sgroup"));
                student.setName(rs.getString("sname"));
                student.setNumber(rs.getString("sno"));
                student.setPassword(rs.getString("spassword"));
                student.setPhone(rs.getString("stel"));
                student.setSclass(rs.getString("sclass"));
                student.setSex(rs.getString("ssex"));
                students.add(student);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rsCount);
            DB.close(stmtCount);
            DB.close(rs);
            DB.close(stmt);
            DB.close(conn);
        }

        return totalRecords;
    }
    /**
     * 按学号删除学生
     * @param id 要删除学生的学号
     * @return 删除成功返回true否则返回false
     */
    public static boolean deleteBySno(String id) {
        boolean b = false;
        Connection conn = DB.getConn();
        String sql = null;
        sql = "delete from student_info where sno = '" + id + "'";
        Statement stmt = DB.getStatement(conn);
        try {
            DB.executeUpdate(stmt, sql);
            b = true;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DB.close(stmt);
            DB.close(conn);
        }
        return b;
    }
    /**
     * 检查登录时学号和密码是否真确
     * @param num 学号
     * @param password 密码
     * @return 正确返回true否则返回false
     * @throws UserNotFoundException 抛出学号不存在的异常
     * @throws PasswordNotCorrectException 抛出密码错误的异常
     */
    public static Student check(String num, String password)
            throws UserNotFoundException, PasswordNotCorrectException {
        Student student = null;
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from student_info where sno = '" + num + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        try {
            if (!rs.next()) {
                throw new UserNotFoundException("用户不存在:" + num);
            } else {
                if (!password.equals(rs.getString("spassword"))) {
                    throw new PasswordNotCorrectException("密码不正确!");
                }
            }
            student = new Student();
            student.setEmail(rs.getString("semail"));
            student.setGroup(rs.getString("sgroup"));
            student.setName(rs.getString("sname"));
            student.setNumber(rs.getString("sno"));
            student.setPassword(rs.getString("spassword"));
            student.setPhone(rs.getString("stel"));
            student.setSclass(rs.getString("sclass"));
            student.setSex(rs.getString("ssex"));
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(stmt);
            DB.close(conn);
        }
        return student;
    }
    /**
     * 按学号获得学生信息
     * @param num 学号
     * @return 返回该学号的学生对象
     */
    public static Student getBySno(String num) {
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from student_info where sno='" + num + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Student student = null;
        try {
            if (rs.next()) {
                student = new Student();
                student.setEmail(rs.getString("semail"));
                student.setGroup(rs.getString("sgroup"));
                student.setName(rs.getString("sname"));
                student.setNumber(rs.getString("sno"));
                student.setPassword(rs.getString("spassword"));
                student.setPhone(rs.getString("stel"));
                student.setSclass(rs.getString("sclass"));
                student.setSex(rs.getString("ssex"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(conn);
        }
        return student;
    }
    /**
     * 更新学生stu的相关信息(学号不能更新)
     * @param stu 存有新信息的学生对象
     * @return 更新成功返回true否则返回false
     */
    public static boolean update(Student stu) {
        Connection conn = DB.getConn();
        String sql = null;
        boolean b = false;
        sql = "update student_info set spassword=?, sgroup=?, sname=?, ssex=?, stel=?, semail=?, sclass=?  where sno = ?";
        PreparedStatement pstmt = DB.prepare(conn, sql);
        try {
            pstmt.setString(1, stu.getPassword());
            pstmt.setString(2, stu.getGroup());
            pstmt.setString(3, stu.getName());
            pstmt.setString(4, stu.getSex());
            pstmt.setString(5, stu.getPhone());
            pstmt.setString(6, stu.getEmail());
            pstmt.setString(7, stu.getSclass());
            pstmt.setString(8, stu.getNumber());
            pstmt.executeUpdate();
            b = true;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(pstmt);
            DB.close(conn);
        }
        return b;
    }
    /**
     * 按指定的条件获得所有符合条件的学生信息
     * @param students 存放符合条件的学生信息的List
     * @param pageNo 分页显示时,当前的页号
     * @param pageSize 每页显示学生信息的数量
     * @param sclass 学生所在的班级
     * @param num 学号
     * @param name 学生姓名
     * @return 返回符合条件的学生列表
     */
    public static int query(List students, int pageNo, int pageSize,
                            String sclass, String num, String name) {
        int totalRecords = -1;

        Connection conn = DB.getConn();
        String sql = null;
        /*
         * 如何有些条件为空的进行如下处理,否则模糊查询时可能会报空指针异常
         */
        if (sclass == null)
            sclass = "";
        if (name == null)
            name = "";
        if (num == null)
            num = "";
        /*
         * 模糊查寻
         */
        sql = "select * from student_info where sclass like '%" + sclass
                + "%' and sname like '%" + name + "%' and sno like '%" + num
                + "%'";
        sql += "limit " + (pageNo - 1) * pageSize + "," + pageSize;
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);

        Statement stmtCount = DB.getStatement(conn);
        ResultSet rsCount = null;
        rsCount = DB.getResultSet(stmtCount,
                "select count(*) from student_info where sclass like '%"
                        + sclass + "%' and sname like '%" + name
                        + "%' and sno like '%" + num + "%'");
        try {
            rsCount.next();
            totalRecords = rsCount.getInt(1);

            while (rs.next()) {
                Student student = new Student();
                student.setEmail(rs.getString("semail"));
                student.setGroup(rs.getString("sgroup"));
                student.setName(rs.getString("sname"));
                student.setNumber(rs.getString("sno"));
                student.setPassword(rs.getString("spassword"));
                student.setPhone(rs.getString("stel"));
                student.setSclass(rs.getString("sclass"));
                student.setSex(rs.getString("ssex"));
                students.add(student);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rsCount);
            DB.close(stmtCount);
            DB.close(rs);
            DB.close(stmt);
            DB.close(conn);
        }
        return totalRecords;
    }
    /**
     * 批量导入excel表中学生的信息到数据库中(用到组件jxl.jar)
     * @param file excel表所在的相对路径或绝对路径(包括文件完整的名字)
     * @return 返回那些学号在数据库中已经存在的学号
     */
    public static List adds(String file) {
        Connection conn = DB.getConn();
        List snumber = new ArrayList();
        Workbook info;//定义工作簿
        String sql = "insert into student_info values (?, ?, ?, ?, ?, ?, ?, ?)";
        try {
            info = Workbook.getWorkbook(new FileInputStream(file));
            Sheet   sheet   =   info.getSheet(0);//获得工作薄中表单对象
            int   size   =   sheet.getRows(); //获得表单的行数
            for(int   i   =   1;i   <   size;i++){
                Cell c = sheet.getCell(0,i);//获得表单的i行0列的单元格即学号
                /*
                 * 查看学号是否已经存在
                 */
                if(StudentManager.getBySno(c.getContents().trim())!=null) {
                    snumber.add(c.getContents().trim());
                    continue;
                }
                PreparedStatement pstmt = DB.prepare(conn, sql);
                for(int j=0; j<8; j++) {
                    c   =   sheet.getCell(j,i);
                    pstmt.setString(j+1, c.getContents().trim());
                }
                pstmt.execute();
            }
        } catch (BiffException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IndexOutOfBoundsException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return snumber;
    }
}

TeacherManager

教师信息管理类,实现教师信息的增加,查看,删除。

package com.sjsq.service;

import com.sjsq.model.Teacher;
import com.sjsq.util.DB;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class TeacherManager {

    public static boolean save(Teacher te) {
        Connection conn = DB.getConn();
        String sql = null;
        boolean b = false;
        sql = "insert into teacher_info values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        PreparedStatement pstmt = DB.prepare(conn, sql);
        try {
            pstmt.setString(1, te.getNumber());
            pstmt.setString(2, te.getName());
            pstmt.setString(3, te.getSex());
            pstmt.setString(4, te.getDept());
            pstmt.setString(5, te.getDegree());
            pstmt.setString(6, te.getTitle());
            pstmt.setShort(7, te.getRight());
            pstmt.setString(8, te.getPhone());
            pstmt.setString(9, te.getEmail());
            pstmt.setString(10, te.getGroup());
            pstmt.setString(11, te.getPassword());
            pstmt.execute();
            b = true;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(pstmt);
            DB.close(conn);
        }
        return b;
    }


    public static int getTeachers(List teachers, int pageNo,
                                  int pageSize) {

        int totalRecords = -1;

        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from teacher_info limit " + (pageNo - 1) * pageSize
                + "," + pageSize;
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);

        Statement stmtCount = DB.getStatement(conn);
        ResultSet rsCount = null;
        rsCount = DB.getResultSet(stmtCount,
                "select count(*) from teacher_info");

        try {
            rsCount.next();
            totalRecords = rsCount.getInt(1);

            while (rs.next()) {
                Teacher teacher = new Teacher();
                teacher.setEmail(rs.getString("temail"));
                teacher.setGroup(rs.getString("tgroup"));
                teacher.setName(rs.getString("tname"));
                teacher.setNumber(rs.getString("tno"));
                teacher.setPassword(rs.getString("tpassword"));
                teacher.setPhone(rs.getString("ttel"));
                teacher.setDept(rs.getString("tdept"));
                teacher.setSex(rs.getString("tsex"));
                teacher.setDegree(rs.getString("tdegree"));
                teacher.setRight(rs.getShort("tright"));
                teacher.setTitle(rs.getString("ttitle"));
                teachers.add(teacher);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rsCount);
            DB.close(stmtCount);
            DB.close(rs);
            DB.close(stmt);
            DB.close(conn);
        }

        return totalRecords;
    }

    public static boolean deleteByTno(String id) {
        boolean b = false;
        Connection conn = DB.getConn();
        String sql = null;
        sql = "delete from teacher_info where tno = '" + id + "'";
        Statement stmt = DB.getStatement(conn);
        try {
            DB.executeUpdate(stmt, sql);
            b = true;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DB.close(stmt);
            DB.close(conn);
        }
        return b;
    }

    public static Teacher check(String num, String password)
            throws UserNotFoundException, PasswordNotCorrectException {
        Teacher teacher = null;
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from teacher_info where tno = '" + num + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        try {
            if (!rs.next()) {
                throw new UserNotFoundException("用户不存在:" + num);
            } else {
                if (!password.equals(rs.getString("tpassword"))) {
                    throw new PasswordNotCorrectException("密码不正确!");
                }
            }
            teacher = new Teacher();
            teacher.setEmail(rs.getString("temail"));
            teacher.setGroup(rs.getString("tgroup"));
            teacher.setName(rs.getString("tname"));
            teacher.setNumber(rs.getString("tno"));
            teacher.setPassword(rs.getString("tpassword"));
            teacher.setPhone(rs.getString("ttel"));
            teacher.setDept(rs.getString("tdept"));
            teacher.setSex(rs.getString("tsex"));
            teacher.setDegree(rs.getString("tdegree"));
            teacher.setRight(rs.getShort("tright"));
            teacher.setTitle(rs.getString("ttitle"));
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(stmt);
            DB.close(conn);
        }
        return teacher;
    }

    public static Teacher getByTno(String num) {
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from teacher_info where tno='" + num + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Teacher teacher = null;
        try {
            if (rs.next()) {
                teacher = new Teacher();
                teacher.setEmail(rs.getString("temail"));
                teacher.setGroup(rs.getString("tgroup"));
                teacher.setName(rs.getString("tname"));
                teacher.setNumber(rs.getString("tno"));
                teacher.setPassword(rs.getString("tpassword"));
                teacher.setPhone(rs.getString("ttel"));
                teacher.setDept(rs.getString("tdept"));
                teacher.setSex(rs.getString("tsex"));
                teacher.setDegree(rs.getString("tdegree"));
                teacher.setRight(rs.getShort("tright"));
                teacher.setTitle(rs.getString("ttitle"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(conn);
        }
        return teacher;
    }

    public static boolean update(Teacher te) {
        Connection conn = DB.getConn();
        String sql = null;
        boolean b = false;
        sql = "update teacher_info set tpassword=?, tgroup=?, tname=?, tsex=?, ttel=?, temail=?, tdept=?, ttitle=?, tright=?,  tdegree=? where tno = ?";
        PreparedStatement pstmt = DB.prepare(conn, sql);
        try {
            pstmt.setString(1, te.getPassword());
            pstmt.setString(2, te.getGroup());
            pstmt.setString(3, te.getName());
            pstmt.setString(4, te.getSex());
            pstmt.setString(5, te.getPhone());
            pstmt.setString(6, te.getEmail());
            pstmt.setString(7, te.getDept());
            pstmt.setString(8, te.getTitle());
            pstmt.setShort(9, te.getRight());
            pstmt.setString(10, te.getDegree());
            pstmt.setString(11, te.getNumber());
            pstmt.executeUpdate();
            b = true;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(pstmt);
            DB.close(conn);
        }
        return b;
    }

    public static int query(List teachers, int pageNo, int pageSize,
                            String dept, String num, String name) {
        int totalRecords = -1;

        Connection conn = DB.getConn();
        String sql = null;
        if (dept == null)
            dept = "";
        if (name == null)
            name = "";
        if (num == null)
            num = "";
        sql = "select * from teacher_info where tdept like '%" + dept
                + "%' and tname like '%" + name + "%' and tno like '%" + num
                + "%'";
        sql += "limit " + (pageNo - 1) * pageSize + "," + pageSize;
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);

        Statement stmtCount = DB.getStatement(conn);
        ResultSet rsCount = null;
        rsCount = DB.getResultSet(stmtCount,
                "select count(*) from teacher_info where tdept like '%" + dept
                        + "%' and tname like '%" + name + "%' and tno like '%"
                        + num + "%'");
        try {
            rsCount.next();
            totalRecords = rsCount.getInt(1);

            while (rs.next()) {
                Teacher teacher = new Teacher();
                teacher.setEmail(rs.getString("temail"));
                teacher.setGroup(rs.getString("tgroup"));
                teacher.setName(rs.getString("tname"));
                teacher.setNumber(rs.getString("tno"));
                teacher.setPassword(rs.getString("tpassword"));
                teacher.setPhone(rs.getString("ttel"));
                teacher.setDept(rs.getString("tdept"));
                teacher.setSex(rs.getString("tsex"));
                teacher.setDegree(rs.getString("tdegree"));
                teacher.setRight(rs.getShort("tright"));
                teacher.setTitle(rs.getString("ttitle"));
                teachers.add(teacher);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rsCount);
            DB.close(stmtCount);
            DB.close(rs);
            DB.close(stmt);
            DB.close(conn);
        }

        return totalRecords;
    }

    public static List adds(String file) {
        Connection conn = DB.getConn();
        Workbook info;
        List tnumber = new ArrayList();
        String sql = "insert into teacher_info values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        try {
            info = Workbook.getWorkbook(new FileInputStream(file));
            Sheet sheet = info.getSheet(0);
            int size = sheet.getRows();
            for (int i = 1; i < size; i++) {
                Cell c = sheet.getCell(0, i);
                if (TeacherManager.getByTno(c.getContents().trim()) != null) {
                    tnumber.add(c.getContents().trim());
                    continue;
                }
                PreparedStatement pstmt = DB.prepare(conn, sql);
                for (int j = 0; j < 11; j++) {
                    c = sheet.getCell(j, i);
                    if (j != 6) {
                        pstmt.setString(j + 1, c.getContents().trim());
                    } else
                        pstmt.setShort(j + 1, Short.parseShort(c.getContents()));
                }
                pstmt.execute();
            }
        } catch (BiffException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IndexOutOfBoundsException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return tnumber;
    }
}


TopicManager

选题信息管理,实现选题新的增加,修改,查看,删除。

package com.sjsq.service;

import com.sjsq.model.Topic;
import com.sjsq.util.DB;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class TopicManager {

    public static boolean save(Topic t) {
        Connection conn = DB.getConn();
        String sql = null;
        boolean b = false;
        sql = "insert into topic_info values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        PreparedStatement pstmt = DB.prepare(conn, sql);
        try {
            pstmt.setString(1, t.getNumber());
            pstmt.setString(2, t.getName());
            pstmt.setString(3, t.getType());
            pstmt.setString(4, t.getKind());
            pstmt.setString(5, t.getSource());
            pstmt.setString(6, t.getStatus());
            pstmt.setString(7, t.getContent());
            pstmt.setString(8, t.getResult());
            pstmt.setString(9, t.getDirection());
            pstmt.setString(10, t.getTnumber());
            pstmt.setString(11, t.getSnumber());
            pstmt.execute();
            b = true;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(pstmt);
            DB.close(conn);
        }
        return b;
    }

    public static int getTopics(List topics, int pageNo,
                                int pageSize) {

        int totalRecords = -1;

        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from topic_info limit " + (pageNo - 1) * pageSize
                + "," + pageSize;
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);

        Statement stmtCount = DB.getStatement(conn);
        ResultSet rsCount = null;
        rsCount = DB
                .getResultSet(stmtCount, "select count(*) from topic_info");

        try {
            rsCount.next();
            totalRecords = rsCount.getInt(1);

            while (rs.next()) {
                Topic topic = new Topic();
                topic.setContent(rs.getString("hcontent"));
                topic.setDirection(rs.getString("direction"));
                topic.setKind(rs.getString("hkind"));
                topic.setName(rs.getString("hname"));
                topic.setNumber(rs.getString("hno"));
                topic.setResult(rs.getString("hresult"));
                topic.setSnumber(rs.getString("sno"));
                topic.setSource(rs.getString("hsource"));
                topic.setStatus(rs.getString("hstatus"));
                topic.setType(rs.getString("htype"));
                topic.setTnumber(rs.getString("tno"));
                topics.add(topic);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rsCount);
            DB.close(stmtCount);
            DB.close(rs);
            DB.close(stmt);
            DB.close(conn);
        }

        return totalRecords;
    }

    public static boolean deleteByHno(String hno) {
        boolean b = false;
        Connection conn = DB.getConn();
        String sql = null;
        sql = "delete from topic_info where hno = '" + hno + "'";
        Statement stmt = DB.getStatement(conn);
        try {
            DB.executeUpdate(stmt, sql);
            b = true;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DB.close(stmt);
            DB.close(conn);
        }
        return b;
    }

    public static boolean check(String tno, String hname) {
        boolean b = false;
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from topic_info where tno = '" + tno + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        try {
            if (rs.next()) b = true;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(stmt);
            DB.close(conn);
        }
        return b;
    }

    public static boolean update(Topic t) {
        Connection conn = DB.getConn();
        String sql = null;
        boolean b = false;
        sql = "update topic_info set htype=?, tno=?, hname=?, hsource=?, hkind=?, hstatus=?, hresult=?, sno=?, direction=?,  hcontent=? where hno = ?";
        PreparedStatement pstmt = DB.prepare(conn, sql);
        try {
            pstmt.setString(1, t.getType());
            pstmt.setString(2, t.getTnumber());
            pstmt.setString(3, t.getName());
            pstmt.setString(4, t.getSource());
            pstmt.setString(5, t.getKind());
            pstmt.setString(6, t.getStatus());
            pstmt.setString(7, t.getResult());
            pstmt.setString(8, t.getSnumber());
            pstmt.setString(9, t.getDirection());
            pstmt.setString(10, t.getContent());
            pstmt.setString(11, t.getNumber());
            pstmt.executeUpdate();
            b = true;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(pstmt);
            DB.close(conn);
        }
        return b;
    }

    public static Topic getByNum(String num) {
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from topic_info where hno='" + num + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Topic topic = null;
        try {
            if (rs.next()) {
                topic = new Topic();
                topic.setContent(rs.getString("hcontent"));
                topic.setDirection(rs.getString("direction"));
                topic.setKind(rs.getString("hkind"));
                topic.setName(rs.getString("hname"));
                topic.setNumber(rs.getString("hno"));
                topic.setResult(rs.getString("hresult"));
                topic.setSnumber(rs.getString("sno"));
                topic.setSource(rs.getString("hsource"));
                topic.setStatus(rs.getString("hstatus"));
                topic.setType(rs.getString("htype"));
                topic.setTnumber(rs.getString("tno"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(conn);
        }
        return topic;
    }

    public static List getByTno(String num) {
        Connection conn = DB.getConn();
        String sql = null;
        List topics = new ArrayList();
        sql = "select * from topic_info where tno='" + num + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Topic topic = null;
        try {
            while (rs.next()) {
                topic = new Topic();
                topic.setContent(rs.getString("hcontent"));
                topic.setDirection(rs.getString("direction"));
                topic.setKind(rs.getString("hkind"));
                topic.setName(rs.getString("hname"));
                topic.setNumber(rs.getString("hno"));
                topic.setResult(rs.getString("hresult"));
                topic.setSnumber(rs.getString("sno"));
                topic.setSource(rs.getString("hsource"));
                topic.setStatus(rs.getString("hstatus"));
                topic.setType(rs.getString("htype"));
                topic.setTnumber(rs.getString("tno"));
                topics.add(topic);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(conn);
        }
        return topics;
    }

    public static int query(List topics, int pageNo, int pageSize, String str, String kind, String name) {
        int totalRecords = -1;

        Connection conn = DB.getConn();
        String sql = null;
        if (str == null)
            str = "";
        if (kind == null)
            kind = "";
        if (name == null)
            name = "";

        sql = "select * from topic_info where hname like '%" + name
                + "%' and htype like '%" + str + "%' and hkind like '%" + kind + "%'";
        sql += "limit " + (pageNo - 1) * pageSize + "," + pageSize;

        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);

        Statement stmtCount = DB.getStatement(conn);
        ResultSet rsCount = null;
        rsCount = DB
                .getResultSet(stmtCount, "select count(*) from topic_info where hname like '%" + name
                        + "%' and htype like '%" + str + "%' and hkind like '%" + kind + "%'");

        try {
            if (rsCount != null) rsCount.next();
            totalRecords = rsCount.getInt(1);

            while (rs.next()) {
                Topic topic = new Topic();
                topic.setContent(rs.getString("hcontent"));
                topic.setDirection(rs.getString("direction"));
                topic.setKind(rs.getString("hkind"));
                topic.setName(rs.getString("hname"));
                topic.setNumber(rs.getString("hno"));
                topic.setResult(rs.getString("hresult"));
                topic.setSnumber(rs.getString("sno"));
                topic.setSource(rs.getString("hsource"));
                topic.setStatus(rs.getString("hstatus"));
                topic.setType(rs.getString("htype"));
                topic.setTnumber(rs.getString("tno"));
                topics.add(topic);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rsCount);
            DB.close(stmtCount);
            DB.close(rs);
            DB.close(stmt);
            DB.close(conn);
        }

        return totalRecords;
    }

    public static List getByStatus(String num) {
        Connection conn = DB.getConn();
        List topics = new ArrayList();
        String sql = null;
        sql = "select * from topic_info where hstatus='" + num + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Topic topic = null;
        try {
            while (rs.next()) {
                topic = new Topic();
                topic.setContent(rs.getString("hcontent"));
                topic.setDirection(rs.getString("direction"));
                topic.setKind(rs.getString("hkind"));
                topic.setName(rs.getString("hname"));
                topic.setNumber(rs.getString("hno"));
                topic.setResult(rs.getString("hresult"));
                topic.setSnumber(rs.getString("sno"));
                topic.setSource(rs.getString("hsource"));
                topic.setStatus(rs.getString("hstatus"));
                topic.setType(rs.getString("htype"));
                topic.setTnumber(rs.getString("tno"));
                topics.add(topic);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(conn);
        }
        return topics;
    }

    public static Topic getBySnum(String num) {
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from topic_info where sno='" + num + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Topic topic = null;
        try {
            if (rs.next()) {
                topic = new Topic();
                topic.setContent(rs.getString("hcontent"));
                topic.setDirection(rs.getString("direction"));
                topic.setKind(rs.getString("hkind"));
                topic.setName(rs.getString("hname"));
                topic.setNumber(rs.getString("hno"));
                topic.setResult(rs.getString("hresult"));
                topic.setSnumber(rs.getString("sno"));
                topic.setSource(rs.getString("hsource"));
                topic.setStatus(rs.getString("hstatus"));
                topic.setType(rs.getString("htype"));
                topic.setTnumber(rs.getString("tno"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(conn);
        }
        return topic;
    }

    public static Topic getByTnumAndHname(String tnum, String hname) {
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from topic_info where tno='" + tnum + "' and hname='" + hname + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Topic topic = null;
        try {
            if (rs.next()) {
                topic = new Topic();
                topic.setContent(rs.getString("hcontent"));
                topic.setDirection(rs.getString("direction"));
                topic.setKind(rs.getString("hkind"));
                topic.setName(rs.getString("hname"));
                topic.setNumber(rs.getString("hno"));
                topic.setResult(rs.getString("hresult"));
                topic.setSnumber(rs.getString("sno"));
                topic.setSource(rs.getString("hsource"));
                topic.setStatus(rs.getString("hstatus"));
                topic.setType(rs.getString("htype"));
                topic.setTnumber(rs.getString("tno"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(conn);
        }
        return topic;
    }
}


DB

数据库连接类

package com.sjsq.util;
import java.sql.*;
/**
 *
 * 对数据库连接的封装
 *
 */
public class DB {
	/**
	 * 获得对要用的数据库的连接
	 * @return 返回数据库的连接
	 */
	public static Connection getConn() {
		Connection conn = null;
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");//数据库的驱动类 若数据库为sqlserver 应为: ("com.microsoft.sqlserver.jdbc.SQLServerDriver")
			conn = DriverManager.getConnection("jdbc:mysql://localhost/jsp_select_topic?serverTimezone=UTC","root","admin");
			//jdbc:myseql数据库的类型  localhost:3306本机3306端口 select_course 数据库名 user=root 用户名为root password=root 用户密码为root
			// 若是sqlserver应为("jdbc:sqlserver://localhst:1422;databaseName=select_course", "root", "root");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
	/**
	 * 获得多数据库的预编译的 SQL 语句的对象
	 * @param conn 数据库的连接
	 * @param sql 要执行的SQL语句
	 * @return 返回预编译的 SQL 语句的对象
	 */
	public static PreparedStatement prepare(Connection conn,  String sql) {
		PreparedStatement pstmt = null;
		try {
			if(conn != null) {
				pstmt = conn.prepareStatement(sql);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return pstmt;
	}
	/**
	 *
	 * @param conn 数据库的连接
	 * @return 返回执行静态 SQL 语句对象
	 */
	public static Statement getStatement(Connection conn) {
		Statement stmt = null;
		try {
			if(conn != null) {
				stmt = conn.createStatement();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return stmt;
	}
	/**
	 *
	 * @param stmt 执行静态SQl语句的对象
	 * @param sql 要执行的SQL语句
	 * @return 执行后的结果集
	 */
	public static ResultSet getResultSet(Statement stmt, String sql) {
		ResultSet rs = null;
		try {
			if(stmt != null) {
				rs = stmt.executeQuery(sql);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rs;
	}

	/**
	 *
	 * @param stmt 静态执行sql语句的对象
	 * @param sql 要执行的SQL语句
	 */

	public static void executeUpdate(Statement stmt, String sql) {
		try {
			if(stmt != null) {
				stmt.executeUpdate(sql);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 关闭数据库的连接
	 * @param conn 数据库的连接
	 */

	public static void close(Connection conn) {
		try {
			if(conn != null) {
				conn.close();
				conn = null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 关闭Statement
	 * @param stmt
	 */
	public static void close(Statement stmt) {
		try {
			if(stmt != null) {
				stmt.close();
				stmt = null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 关闭ResultSet
	 * @param rs
	 */
	public static void close(ResultSet rs) {
		try {
			if(rs != null) {
				rs.close();
				rs = null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}


Login.jsp

登录前端页面,实现用户登录,判断用户类型,调用登录函数。

<%@ page language="java" import="com.sjsq.model.Student" pageEncoding="UTF-8" %>
<%@ page import="com.sjsq.model.Teacher" %>
<%@ page import="com.sjsq.service.PasswordNotCorrectException" %>
<%@ page import="com.sjsq.service.StudentManager" %>
<%@ page import="com.sjsq.service.TeacherManager" %>
<%@ page import="com.sjsq.service.UserNotFoundException" %>
<%
    String username = request.getParameter("user_no").trim();
    String password = request.getParameter("user_pass").trim();
    int type = Integer.parseInt(request.getParameter("u_type").trim());
    try {
        if (type == 1) {
            Student student = StudentManager.check(username, password);
            session.setAttribute("user", student);
            session.setAttribute("type", type);
            response.sendRedirect("student/student.jsp");
        }
        if (type == 2) {
            Teacher teacher = TeacherManager.check(username, password);
            session.setAttribute("user", teacher);
            session.setAttribute("type", type);
            response.sendRedirect("teacher/teacher.jsp");
        }
        if (type == 3) {
            Teacher teacher = TeacherManager.check(username, password);
            if (teacher.getRight() == 0) {
                session.setAttribute("user", teacher);
                session.setAttribute("type", type);
                response.sendRedirect("admin/admin.jsp");
            } else {
                out.println("您没有管理员权限!");
                return;
            }
        }
    } catch (UserNotFoundException e) {
        out.println(e.getMessage());
        return;
    } catch (PasswordNotCorrectException e) {
        out.println(e.getMessage());
        return;
    }
%>


index.jsp

用户登录界面

<%@page pageEncoding="UTF-8" %>
<%@page import="com.sjsq.service.MsgManager" %>



    
    毕业设计选题系统-用户登录
    
    

    
    
        
    


 




毕业设计选题系统
 
   
<% String[] title = MsgManager.getTitles(); for (int i = 0; title[i] != null; i++) { %>

<%=title[i]%>

<% } %>
用户编号:
<%--title="姓名或编号(学生为学号)">提示--%>
用户密码:
<%--提示--%>
用户类型:


news.jsp

新闻公告界面

<%@page pageEncoding="UTF-8" import="com.sjsq.service.MsgManager" %>



    
    
    公告详情




 公告详情

<% String number = new String(request.getParameter("id").getBytes("UTF-8"), "UTF-8"); String text = MsgManager.getTexts(number); %>
 
标题:
<%=number%>
 
内容:
<%=text%>

四、其他

1.更多系统

Java+JSP系统系列实现

Java+JSP实现学生图书管理系统

Java+JSP实现学生信息管理系统

Java+JSP实现用户信息管理系统

Java+JSP实现教师信息管理系统

Java+JSP实现学生宿舍管理系统

Java+JSP实现商品信息管理系统

Java+JSP实现宠物信息管理系统

Java+JSP实现学生成绩管理系统

Java+Servlet系统系列实现

Java+Servlet+JSP实现航空订票系统

Java+Servlet+JSP实现新闻发布系统

Java+Servlet+JSP学生宿舍管理系统

Java+Servlet+JSP实现图书管理系统

Java+Servlet+JSP实现停车场管理系统

Java+Servlet+JSP实现房屋租赁管理系统

Java+Servlet+JSP实现学生信息管理系统

Java+Servlet+JSP实现学生选课管理系统

Java+Servlet+JSPl实现学生选课签到系统

Java+Servlet+JSP实现宠物诊所管理系统

Java+Servlet+JSP实现学生成绩管理系统-1

Java+Servlet+JSP实现学生成绩管理系统-2

Java+SSM系统系列实现

J​​​ava+SSM+JSP实现网上考试系统

Java+SSM+JSP实现宠物商城系统

Java+SSM+JSP实现超市管理系统

Java+SSM+JSP实现学生成绩管理系统

Java+SSM+JSP实现学生信息管理系统

Java+SSM+JSP实现药品信息管理系统

Java+SSM+JSP实现汽车信息管理系统

Java+SSM+Jspl实现商品信息管理系统

Java+SSM+JSP+Maven实现网上书城系统

Java+SSM+JSP+Maven实现学校教务管理系统

Java+SSH系统系列实现

Java+SSH+JSP实现在线考试系统

Java+SSH+JSP实现医院在线挂号系统

Java+Springboot系统系列实现

Java+Springboot+H-ui+Maven实现营销管理系统

Java+Springboot+Bootstrap+Maven实现网上商城系统

Java+Springboot+Bootstrap+Maven实现景区旅游管理系统

1.更多JavaWeb系统请关注专栏。

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

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

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

2.源码下载

sql在sql文件夹下面

系统账号信息

1.管理员 

账号:101  密码:admin

2.教师

账号:102  密码:123456

3.学生

账号:1001 密码:123456

Java+Jsp+Mysql实现Web毕业设计选题系统

3.运行项目

关注B站:水坚石青

后期有更多干货视频推出!!!

IDEA如何导入JavaWeb项目超详细视频教程

4.备注

如有侵权请联系我删除。

5.支持博主

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

你可能感兴趣的:(JavaWeb实战,java,intellij-idea,mysql,tomcat,jsp)