基于javaweb+mysql的jsp+servlet校园运动会管理系统(java+jsp+servlet+javabean+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet校园运动会管理系统(java+jsp+servlet+javabean+mysql)
项目介绍
本项目包含三种角色:运动员、裁判员、管理员;
运动员角色包含以下功能:
运动员登录,个人信息修改,运动成绩查询,比赛项目查询等功能。
裁判员角色包含以下功能: 登录界面,查看运动员,运动成绩查看,录入运动成绩,比赛项目查询等功能。
管理员角色包含以下功能: 登录页面,管理员首页,运动员管理,裁判员管理,运动成绩查询,比赛类型管理等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:否;
技术栈
JSP+Servlet+JavaBean+MySQL+css+javascript
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中src/util/DB.java配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/jspyundonghuimanager/ 登录 注:tomcat中配置项目路径必须为jspyundonghuimanager,否则会有异常 管理员账号/密码:admin/admin 学生运动员角色账号/密码:student/123456 裁判老师角色账号/密码:teacher/123456
public class GetCountPageServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doPost(req, resp);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
StudentImpl studentImpl = new StudentImpl();
TeacherImpl teacherImpl = new TeacherImpl();
Operator operator;
Teacher teacher;
// 获取总页数
int countPage = 0;
operator = (Operator) request.getSession().getAttribute("log_operator");
int ope_rol_id = operator.getRole().getId();
String search_type = request.getParameter("search_type");
String search_value = java.net.URLDecoder.decode(request
.getParameter("value"), "UTF-8");
if (ope_rol_id == 1) {
// 管理员的查询
if (search_type.equals("stu_all")) {
countPage = studentImpl.getCountPage("stu_all", search_value
+ "");
} else if (search_type.equals("stu_no")) {
countPage = studentImpl.getCountPage("stu_no", search_value
+ "");
} else if (search_type.equals("stu_name")) {
countPage = studentImpl.getCountPage("stu_name", search_value
+ "");
} else if (search_type.equals("cla_name")) {
if (i == 1) {
request.getSession().setAttribute("message", "添加裁判员老师成功!");
} else {
request.getSession().setAttribute("message", "添加裁判员老师失败!");
}
response.sendRedirect("pages/add_teacher.jsp");
}
}
public class UpdateTeacherServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doPost(req, resp);
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 更新裁判员老师信息
HttpSession session = request.getSession();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
OperatorImpl operatorImpl = new OperatorImpl();
TeacherImpl teacherImpl = new TeacherImpl();
Teacher teacher = teacherImpl.query("tec_id",
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 更新裁判员老师信息
HttpSession session = request.getSession();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
OperatorImpl operatorImpl = new OperatorImpl();
TeacherImpl teacherImpl = new TeacherImpl();
Teacher teacher = teacherImpl.query("tec_id",
request.getParameter("tec_id")).get(0);
Operator operator = teacher.getOperator();
try {
teacher.setBirth(sdf.parse((request.getParameter("tec_birth"))));
} catch (ParseException e) {
e.printStackTrace();
}
teacher.setSex((request.getParameter("tec_sex")).equals("male") ? "男"
: "女");
teacher.setName(request.getParameter("tec_name"));
teacher.setMajor(request.getParameter("tec_major"));
teacher.setPhone(request.getParameter("tec_phone"));
operator.setName(request.getParameter("ope_name"));
operator.setPwd(request.getParameter("ope_pwd"));
operatorImpl.update(operator);
teacherImpl.update(teacher);
session.setAttribute("operator_me", operator);
session.setAttribute("teacher_me", teacher);
response.sendRedirect("pages/info_teacher.jsp");
}
}
public class UpdateTeacherServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doPost(req, resp);
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 更新裁判员老师信息
HttpSession session = request.getSession();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
OperatorImpl operatorImpl = new OperatorImpl();
TeacherImpl teacherImpl = new TeacherImpl();
Teacher teacher = teacherImpl.query("tec_id",
request.getParameter("tec_id")).get(0);
Operator operator = teacher.getOperator();
try {
teacher.setBirth(sdf.parse((request.getParameter("tec_birth"))));
} catch (ParseException e) {
e.printStackTrace();
}
teacher.setSex((request.getParameter("tec_sex")).equals("male") ? "男"
: "女");
teacher.setName(request.getParameter("tec_name"));
teacher.setMajor(request.getParameter("tec_major"));
teacher.setPhone(request.getParameter("tec_phone"));
operator.setName(request.getParameter("ope_name"));
operator.setPwd(request.getParameter("ope_pwd"));
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doPost(req, resp);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
OperatorImpl operatorImpl = new OperatorImpl();
PictureImpl pictureImpl = new PictureImpl();
StudentImpl studentImpl = new StudentImpl();
ClassesImpl classesImpl = new ClassesImpl();
SubjectImpl subjectImpl = new SubjectImpl();
ScoreImpl scoreImpl = new ScoreImpl();
RoleImpl roleImpl = new RoleImpl();
// 添加新学生运动员
try {
SmartUpload sm = new SmartUpload();
sm.initialize(getServletConfig(), request, response);
sm.upload();
Student student = new Student();
Operator operator = new Operator();
// 为学生运动员添加操作员信息记录
operator.setName(sm.getRequest().getParameter("ope_name"));
operator.setPwd(sm.getRequest().getParameter("ope_pwd"));
operator.setRole(roleImpl.query("rol_id", "3").get(0));
operator = operatorImpl.add(operator);
// 将学生运动员添加到学生运动员表
student.setOperator(operator);
student.setNo(sm.getRequest().getParameter("no"));
student.setName(sm.getRequest().getParameter("name"));
student
.setSex(sm.getRequest().getParameter("sex").equals("male") ? "男"
: "女");
student.setBirth(sdf.parse(sm.getRequest().getParameter("birth")));
student.setClasses(classesImpl.query("cla_id",
sm.getRequest().getParameter("cla_id")).get(0));
pictureImpl.check(getServletConfig(), request, response, sm,
student);
int i = studentImpl.add(student);
student = studentImpl.query("ope_id", operator.getId() + "").get(0);
if (i == 1) {
request.getSession().setAttribute("message", "添加学生运动员成功!");
} else {
request.getSession().setAttribute("message", "添加学生运动员失败!");
}
int ope_rol_id = operator.getRole().getId();
String search_type = request.getParameter("search_type");
String search_value = java.net.URLDecoder.decode(request
.getParameter("value"), "UTF-8");
if (ope_rol_id == 1) {
// 管理员的查询
if (search_type.equals("stu_all"))
countPage = scoreImpl.getCountPage("all", search_value);
else
countPage = scoreImpl.getCountPage(search_type, search_value);
} else if (ope_rol_id == 2) {
// 裁判员老师的查询
teacher = teacherImpl.query("ope_id", operator.getId() + "").get(0);
if (search_type.equals("stu_all")) {
countPage = scoreImpl.getCountPage("tec_stu_all", teacher
.getName()
+ "");
} else if (search_type.equals("stu_no")) {
countPage = scoreImpl.getCountPage("tec_stu_no", teacher
.getName()
+ "_" + search_value);
} else if (search_type.equals("stu_name")) {
countPage = scoreImpl.getCountPage("tec_stu_name", teacher
.getName()
+ "_" + search_value);
} else if (search_type.equals("sub_name")) {
countPage = scoreImpl.getCountPage("tec_sub_name", teacher
.getName()
+ "_" + search_value);
} else if (search_type.equals("cla_name")) {
countPage = scoreImpl.getCountPage("tec_cla_name", teacher
.getName()
+ "_" + search_value);
}
} else {
// 学生运动员查询
student = studentImpl.query("ope_id", operator.getId() + "").get(0);
if (search_type.equals("stu_all")) {
countPage = scoreImpl.getCountPage("stu_all", student.getId()
+ "");
} else if (search_type.equals("sub_name")) {
countPage = scoreImpl.getCountPage("stu_sub_name", student
.getId()
// 更新学生运动员信息
try {
SmartUpload sm = new SmartUpload();
sm.initialize(getServletConfig(), request, response);
sm.upload();
Student student_my = studentImpl.query("stu_id",
request.getParameter("stu_id") + "").get(0);
Operator operator_my = operatorImpl.query("ope_id",
student_my.getOperator().getId() + "").get(0);
student_my.setNo(sm.getRequest().getParameter("no"));
student_my.setName(sm.getRequest().getParameter("name"));
operator_my.setName(sm.getRequest().getParameter("log_name"));
operator_my.setPwd(sm.getRequest().getParameter("log_pwd"));
student_my.setSex(sm.getRequest().getParameter("sex")
.equals("male") ? "男" : "女");
student_my.setBirth(sdf
.parse(sm.getRequest().getParameter("birth")));
Classes new_classes = classesImpl.query("cla_id",
sm.getRequest().getParameter("cla_id")).get(0);
if (new_classes.getId() != student_my.getClasses().getId()) {
// 班级变动了,删除以前的全部成绩
list_score = scoreImpl.query("stu_id", student_my.getId() + "");
for (Score sco : list_score)
scoreImpl.delete(sco);
// 添加新的成绩
list_subject = subjectImpl.query("cla_id", new_classes.getId()
+ "");
for (Subject subject : list_subject) {
Score score = new Score();
score.setStudent(student_my);
score.setSubject(subject);
scoreImpl.add(score);
}
}
student_my.setClasses(new_classes);
student_my.setOperator(operator_my);
public class ExportCal_subServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doPost(req, resp);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
try {
resp.setContentType("text/html");
resp.setContentType("application/vnd.ms-excel");
Cla2SubImpl cla2SubImpl = new Cla2SubImpl();
String search_type = req.getParameter("search_type");
String search_value = java.net.URLDecoder.decode(req
int i = teacherImpl.add(teacher);
if (i == 1) {
request.getSession().setAttribute("message", "添加裁判员老师成功!");
} else {
request.getSession().setAttribute("message", "添加裁判员老师失败!");
}
response.sendRedirect("pages/add_teacher.jsp");
}
}
public class UpdateTeacherServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doPost(req, resp);
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 更新裁判员老师信息
HttpSession session = request.getSession();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
OperatorImpl operatorImpl = new OperatorImpl();
TeacherImpl teacherImpl = new TeacherImpl();
Teacher teacher = teacherImpl.query("tec_id",
pst = conn
.prepareStatement("SELECT * FROM operator WHERE ope_name = ?");
pst.setString(1, operator.getName());
rs = pst.executeQuery();
if (!rs.next()) {
checkResult = "账户不存在,请重新输入!";
session.setAttribute("isLogin", "false");
} else {
if (!operator.getPwd().equals(rs.getString(3))) {
checkResult = "您输入的密码不正确,请重新输入!";
session.setAttribute("isLogin", "false");
} else {
// 登录成功
session.setAttribute("isLogin", "true");
// 获得该用户的完整信息
log_operator.setId(rs.getInt(1));
log_operator.setName(rs.getString(2));
log_operator.setPwd(rs.getString(3));
log_operator.setRole(roleImpl.query("rol_id",
rs.getString(4)).get(0));
session.setAttribute("log_operator", log_operator);
// 根据用户,获取对应的角色对应的权限
list_privilege = privilegeImpl.query("rol_id", log_operator
.getRole().getId()
+ "");
List<Privilege> list = new ArrayList<Privilege>();
list.add(list_privilege.get(0));
for (int i = 1; i < list_privilege.size(); i++) {
int y=0;
for(int x=0;x<list.size();x++){
if(!list.get(x).getMenu_name().equals(
list_privilege.get(i).getMenu_name())){
y++;
}
}
if (y==list.size()) {
list.add(list_privilege.get(i));
}
}
session.setAttribute("list", list);
session.setAttribute("list_privilege", list_privilege);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DB.close(conn, pst, rs);
}
String[] sub_ids = request.getParameterValues("sub_ids");
for (String id : sub_ids) {
Subject subject = subjectImpl.query("sub_id", id).get(0);
Cla2Sub cla2Sub = new Cla2Sub();
cla2Sub.setClasses(classes);
cla2Sub.setSubject(subject);
cla2Sub.setTeacher(teacher);
int i = cla2SubImpl.add(cla2Sub);
// 为该班级的学生运动员添加该运动项目的成绩
for (Student stu : list_student) {
Score score = new Score();
score.setStudent(stu);
score.setSubject(subject);
score.setCla2sub(cla2SubImpl.findCla2sub(classes.getId(),
teacher.getId(), subject.getId()));
scoreImpl.add(score);
}
if (i == 1) {
request.getSession().setAttribute("message", "添加比赛项目成功!");
} else {
request.getSession().setAttribute("message", "添加比赛项目失败!");
}
}
response.sendRedirect("/jspyundonghuimanager/PlanAddCla2SubSevlet");
}
}
public class AddTeacherServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
list_score = scoreImpl.query("stu_all", student.getId() + "",
page);
} else if (search_type.equals("sub_name")) {
list_score = scoreImpl.query("stu_sub_name", student.getId()
+ "_" + search_value, page);
} else {
list_score = scoreImpl.query("stu_tec_name", student.getId()
+ "_" + search_value, page);
}
}
response.getWriter()
.write(JSONSerializer.toJSON(list_score).toString());
} catch (Exception e) {
// TODO Auto-generated catch block
}
}
}
public class SearchStudentServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doPost(req, resp);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
StudentImpl studentImpl = new StudentImpl();
TeacherImpl teacherImpl = new TeacherImpl();
request.getParameter("stu_id") + "").get(0);
Operator operator_my = operatorImpl.query("ope_id",
student_my.getOperator().getId() + "").get(0);
student_my.setNo(sm.getRequest().getParameter("no"));
student_my.setName(sm.getRequest().getParameter("name"));
operator_my.setName(sm.getRequest().getParameter("log_name"));
operator_my.setPwd(sm.getRequest().getParameter("log_pwd"));
student_my.setSex(sm.getRequest().getParameter("sex")
.equals("male") ? "男" : "女");
student_my.setBirth(sdf
.parse(sm.getRequest().getParameter("birth")));
Classes new_classes = classesImpl.query("cla_id",
sm.getRequest().getParameter("cla_id")).get(0);
if (new_classes.getId() != student_my.getClasses().getId()) {
// 班级变动了,删除以前的全部成绩
list_score = scoreImpl.query("stu_id", student_my.getId() + "");
for (Score sco : list_score)
scoreImpl.delete(sco);
// 添加新的成绩
list_subject = subjectImpl.query("cla_id", new_classes.getId()
+ "");
for (Subject subject : list_subject) {
Score score = new Score();
score.setStudent(student_my);
score.setSubject(subject);
scoreImpl.add(score);
}
}
student_my.setClasses(new_classes);
student_my.setOperator(operator_my);
pictureImpl.check(getServletConfig(), request, response, sm,
student_my);
studentImpl.update(student_my);
operatorImpl.update(operator_my);
session.setAttribute("student_me", student_my);
response.sendRedirect("pages/info_student.jsp");
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class SearchClassesServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doPost(req, resp);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
// AJAX异步查询班级,管理员
ClassesImpl classesImpl = new ClassesImpl();
MajorImpl majorImpl = new MajorImpl();
List<Classes> list_classes;
List<Object> data = new ArrayList<Object>();
List<Major> list_major = new ArrayList<Major>();
String search_type = request.getParameter("search_type");
String search_value = java.net.URLDecoder.decode(request
.getParameter("value"), "UTF-8");
System.out.println(search_value);
int page = Integer.parseInt(request.getParameter("page"));
list_classes = classesImpl.query(search_type, search_value, page);
for (Classes classes : list_classes) {
list_major.add(majorImpl.query("cla_id", classes.getId() + "").get(
0));
}
for (int i = 0; i < list_classes.size(); i++) {
List<Object> list = new ArrayList<Object>();
list.add(list_classes.get(i));
list.add(list_major.get(i));
data.add(list);
}
response.getWriter().write(JSONSerializer.toJSON(data).toString());
}
}
// 删除旧照片
public void delete(ServletConfig servletConfig, HttpServletRequest request, HttpServletResponse response, Student student)
{
String pic_old = student.getPic();
if (pic_old != null && !pic_old.equals("") && !pic_old.equals("../image/person.png"))
{
String temp1 = new java.io.File(servletConfig.getServletContext().getRealPath(request.getRequestURI())).getParent();
java.io.File of = new java.io.File(temp1.substring(0, temp1.length() - 8) + pic_old.substring(2));
if (of.isFile()){
//of.delete();
}
}
}
// 上传新照片
public void upload(File file, Student student)
{
try
{
java.io.File file2 = new java.io.File(this.getClass().getResource("/").getPath()+"/upload/");
if (!file2.exists()) {
file2.mkdirs();
}
String pic = "upload/" + student.getNo() + "." + file.getFileExt().toLowerCase();
student.setPic("../" + pic);
file.saveAs(pic);
} catch (Exception e)
{
}
}
}
// 根据用户,获取对应的角色对应的权限
list_privilege = privilegeImpl.query("rol_id", log_operator
.getRole().getId()
+ "");
List<Privilege> list = new ArrayList<Privilege>();
list.add(list_privilege.get(0));
for (int i = 1; i < list_privilege.size(); i++) {
int y=0;
for(int x=0;x<list.size();x++){
if(!list.get(x).getMenu_name().equals(
list_privilege.get(i).getMenu_name())){
y++;
}
}
if (y==list.size()) {
list.add(list_privilege.get(i));
}
}
session.setAttribute("list", list);
session.setAttribute("list_privilege", list_privilege);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DB.close(conn, pst, rs);
}
return checkResult;
}
}
public class SearchStudentServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doPost(req, resp);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
StudentImpl studentImpl = new StudentImpl();
TeacherImpl teacherImpl = new TeacherImpl();
Operator operator;
Teacher teacher;
List<Student> list_student;
// AJAX异步查询学生运动员
operator = (Operator) request.getSession().getAttribute("log_operator");
int ope_rol_id = operator.getRole().getId();
String search_type = request.getParameter("search_type");
String search_value = java.net.URLDecoder.decode(request
.getParameter("value"), "UTF-8");
int page = Integer.parseInt(request.getParameter("page"));
list_student = new ArrayList<Student>();
if (ope_rol_id == 1) {
// 管理员的查询
if (search_type.equals("stu_all")) {
public class ExportCal_subServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doPost(req, resp);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
try {
resp.setContentType("text/html");
resp.setContentType("application/vnd.ms-excel");
Cla2SubImpl cla2SubImpl = new Cla2SubImpl();
String search_type = req.getParameter("search_type");
String search_value = java.net.URLDecoder.decode(req
.getParameter("value"), "UTF-8");
List<Cla2Sub> list_cla2Sub = cla2SubImpl.query(search_type,
search_value);
String classes_name = list_cla2Sub.get(0).getClasses().getName();
String fileName = classes_name + ".xls";
resp.setHeader("Content-Disposition", "attachment;" + " filename="
+ new String(fileName.getBytes(), "ISO-8859-1"));
OutputStream os = resp.getOutputStream();
WritableWorkbook wwb = Workbook.createWorkbook(os);
WritableSheet ws = wwb.createSheet(classes_name + "比赛项目表", 0);
WritableFont title_big = new WritableFont(WritableFont.ARIAL, 16,
WritableFont.BOLD);
WritableFont title_little = new WritableFont(WritableFont.ARIAL,
12, WritableFont.BOLD);
WritableCellFormat f1 = new WritableCellFormat(title_big);
f1.setAlignment(Alignment.CENTRE);
f1.setVerticalAlignment(VerticalAlignment.CENTRE);
f1.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
WritableCellFormat f2 = new WritableCellFormat(title_little);
f2.setAlignment(Alignment.CENTRE);