当前位置:   article > 正文

基于javaweb+mysql的jsp+servlet选课管理系统(java+jsp+servlet+javascript+mysql)_课程管理系统servlet

课程管理系统servlet

基于javaweb+mysql的jsp+servlet选课管理系统(java+jsp+servlet+javascript+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的JSP+Servlet选课管理系统(java+jsp+servlet+javascript+mysql)

项目介绍

一款简单的Servlet + mysql + jsp的选课系统,主要有三大模块,管理员模块,教师模块,学生模块。管理员模块主要功能模块有系统管理,课程管理,教师管理,课表管理,学生管理;教师模块和学生模块的主要功能模块有个人信息和课表信息的查询,其中学生包括选课的功能。

软件架构

Servlet、mysql5.7、jsp、jdk1.8、tomcat8.0

安装教程

1.导入数据库xuanke.sql 2.导入项目,找到文件中util下的DB.java,修改你自己数据库的帐号和密码

@RequestMapping("/login")

public String login(){

return "login";

@GetMapping("/")

public String index() {

return "success";

@GetMapping("/manager")

@PreAuthorize("hasAuthority('admin')")

public String manager(){

return "manager";

//@RequestMapping("/error")

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

UserService userService;

@RequestMapping("/login")

public String login(){

return "login";

@GetMapping("/")

public String index() {

return "success";

@GetMapping("/manager")

@PreAuthorize("hasAuthority('admin')")

public String manager(){

return "manager";

//@RequestMapping("/error")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

public class UserController{

@Autowired

UserService userService;

/**

* 获取全部用户

* @param page

* @param limit

* @return

*/

@PostMapping("getUsers")

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

return "login";

@GetMapping("/")

public String index() {

return "success";

@GetMapping("/manager")

@PreAuthorize("hasAuthority('admin')")

public String manager(){

return "manager";

//@RequestMapping("/error")

//public String error(){
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
public class LoginController{

@Autowired

AdminService adminService;

@Autowired

UserService userService;

@RequestMapping("/login")

public String login(){

return "login";

@GetMapping("/")

public String index() {

return "success";

@GetMapping("/manager")

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

@GetMapping("/getCode")

@ResponseBody

public Object getCode(HttpServletRequest request) {

/* 生成验证码字符串 */

String verifyCode = VerifyCodeUtil.generateVerifyCode(4);

String uuid = UUIDUtil.GeneratorUUIDOfSimple();

HttpSession session = request.getSession();

session.setAttribute(uuid,verifyCode); //将验证码与生成的uuid绑定在一起

System.out.println("生成的验证码为:" + verifyCode);

int width = 111,height = 36;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

@GetMapping("/info")

@PreAuthorize("hasAuthority('student')")

public String info(){

return "studentInfo";

@GetMapping("/getCode")

@ResponseBody

public Object getCode(HttpServletRequest request) {

/* 生成验证码字符串 */

String verifyCode = VerifyCodeUtil.generateVerifyCode(4);

String uuid = UUIDUtil.GeneratorUUIDOfSimple();

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

用户管理控制层:

@RestController

@RequestMapping("user")

@Api

public class UserController{

@Autowired

UserService userService;

/**

* 获取全部用户

* @param page

* @param limit

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
* Excel表格导出接口

* http://localhost:8080/ExcelDownload

* @param response response对象

*/

@GetMapping("/ExcelDownload")

@PreAuthorize("hasAuthority('admin')")

public void excelDownload(HttpServletResponse response) throws IOException{

adminService.excelOut(response);

/**

* 课程管理

* @return

*/

@GetMapping("/courseManage")

@PreAuthorize("hasAnyAuthority('admin')")

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

map.put("totalCount" , pageInfo.getTotal());  //总条数

map.put("currentPage" , page);  //当前页数。

map.put("data" , pageInfo.getList()); //获得的数据量

return JSON.toJSON(map);

管理员管理控制层:

@Controller

@Api

public class AdminController{

@Autowired

AdminService adminService;

/**

* Excel表格导出接口

* http://localhost:8080/ExcelDownload

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

public String info(){

return "studentInfo";

@GetMapping("/getCode")

@ResponseBody

public Object getCode(HttpServletRequest request) {

/* 生成验证码字符串 */

String verifyCode = VerifyCodeUtil.generateVerifyCode(4);

String uuid = UUIDUtil.GeneratorUUIDOfSimple();

HttpSession session = request.getSession();

session.setAttribute(uuid,verifyCode); //将验证码与生成的uuid绑定在一起

System.out.println("生成的验证码为:" + verifyCode);

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

map.put("currentPage" , page);  //当前页数。

map.put("data" , pageInfo.getList()); //获得的数据量

return JSON.toJSON(map);

管理员管理控制层:

@Controller

@Api

public class AdminController{

@Autowired

AdminService adminService;

/**

* Excel表格导出接口

* http://localhost:8080/ExcelDownload

* @param response response对象

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
@Autowired

UserService userService;

/**

* 获取全部用户

* @param page

* @param limit

* @return

*/

@PostMapping("getUsers")

@PreAuthorize("hasAuthority('admin')")

public Object getAll(@RequestParam(value = "page", defaultValue = "1") int page ,
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

@Autowired

UserService userService;

/**

* 获取全部用户

* @param page

* @param limit

* @return

*/

@PostMapping("getUsers")

@PreAuthorize("hasAuthority('admin')")

public Object getAll(@RequestParam(value = "page", defaultValue = "1") int page ,

@RequestParam(value = "limit", defaultValue = "10") int limit ){

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

return "addCourse";

登录管理控制层:

@Controller

@Api

public class LoginController{

@Autowired

AdminService adminService;

@Autowired

UserService userService;

@RequestMapping("/login")

public String login(){
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

List<User> list = userService.selectAll();

if(list == null){

return Msg.fail();

//System.out.println("=="+username+"==");

PageInfo<User> pageInfo = new PageInfo<>(list);

map.put("totalPage" , pageInfo.getPages());  //总页数

map.put("totalCount" , pageInfo.getTotal());  //总条数

map.put("currentPage" , page);  //当前页数。

map.put("data" , pageInfo.getList()); //获得的数据量

return JSON.toJSON(map);

管理员管理控制层:

@Controller

@Api

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
return "studentInfo";

@GetMapping("/getCode")

@ResponseBody

public Object getCode(HttpServletRequest request) {

/* 生成验证码字符串 */

String verifyCode = VerifyCodeUtil.generateVerifyCode(4);

String uuid = UUIDUtil.GeneratorUUIDOfSimple();

HttpSession session = request.getSession();

session.setAttribute(uuid,verifyCode); //将验证码与生成的uuid绑定在一起

System.out.println("生成的验证码为:" + verifyCode);

int width = 111,height = 36;

try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {

VerifyCodeUtil.outputImage(width, height, stream, verifyCode);

return Msg.msg("data",new ImgVO("data:image/gif;base64,"+ Base64Utils.encodeToString(stream.toByteArray()),uuid));

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

@GetMapping("/")

public String index() {

return "success";

@GetMapping("/manager")

@PreAuthorize("hasAuthority('admin')")

public String manager(){

return "manager";

//@RequestMapping("/error")

//public String error(){

//    return "error";

//}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
@Api

public class LoginController{

@Autowired

AdminService adminService;

@Autowired

UserService userService;

@RequestMapping("/login")

public String login(){

return "login";

@GetMapping("/")

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

public void excelDownload(HttpServletResponse response) throws IOException{

adminService.excelOut(response);

/**

* 课程管理

* @return

*/

@GetMapping("/courseManage")

@PreAuthorize("hasAnyAuthority('admin')")

public String courseManage(){

return "courseManage";

/**

* 添加课程

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

PageInfo<User> pageInfo = new PageInfo<>(list);

map.put("totalPage" , pageInfo.getPages());  //总页数

map.put("totalCount" , pageInfo.getTotal());  //总条数

map.put("currentPage" , page);  //当前页数。

map.put("data" , pageInfo.getList()); //获得的数据量

return JSON.toJSON(map);

管理员管理控制层:

@Controller

@Api

public class AdminController{

@Autowired

AdminService adminService;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

@PreAuthorize("hasAnyAuthority('admin')")

public String courseManage(){

return "courseManage";

/**

* 添加课程

* @return

*/

@GetMapping("/addCourse")

@PreAuthorize("hasAuthority('admin')")

public String addCourse(){

return "addCourse";

登录管理控制层:

@Controller

@Api
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

//}

@GetMapping("/info")

@PreAuthorize("hasAuthority('student')")

public String info(){

return "studentInfo";

@GetMapping("/getCode")

@ResponseBody

public Object getCode(HttpServletRequest request) {

/* 生成验证码字符串 */

String verifyCode = VerifyCodeUtil.generateVerifyCode(4);

String uuid = UUIDUtil.GeneratorUUIDOfSimple();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
* 获取全部用户

* @param page

* @param limit

* @return

*/

@PostMapping("getUsers")

@PreAuthorize("hasAuthority('admin')")

public Object getAll(@RequestParam(value = "page", defaultValue = "1") int page ,

@RequestParam(value = "limit", defaultValue = "10") int limit ){

Map<String,Object> map = new HashMap<>();

PageHelper.startPage(page , limit);

List<User> list = userService.selectAll();

if(list == null){

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

public Object getAll(@RequestParam(value = "page", defaultValue = "1") int page ,

@RequestParam(value = "limit", defaultValue = "10") int limit ){

Map<String,Object> map = new HashMap<>();

PageHelper.startPage(page , limit);

List<User> list = userService.selectAll();

if(list == null){

return Msg.fail();

//System.out.println("=="+username+"==");

PageInfo<User> pageInfo = new PageInfo<>(list);

map.put("totalPage" , pageInfo.getPages());  //总页数

map.put("totalCount" , pageInfo.getTotal());  //总条数

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

@PreAuthorize("hasAuthority('admin')")

public void excelDownload(HttpServletResponse response) throws IOException{

adminService.excelOut(response);

/**

* 课程管理

* @return

*/

@GetMapping("/courseManage")

@PreAuthorize("hasAnyAuthority('admin')")

public String courseManage(){

return "courseManage";

/**

* 添加课程

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/41541
推荐阅读
相关标签
  

闽ICP备14008679号