基于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
Classes classes = classesImpl.query("cla_id",
request.getParameter("cla_id")).get(0);
Teacher teacher = teacherImpl.query("tec_id",
request.getParameter("tec_id")).get(0);
list_student = studentImpl.query("cla_id", classes.getId() + "");
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 {
/**
.getId()
+ "_" + search_value);
} else {
countPage = scoreImpl.getCountPage("stu_tec_name", student
.getId()
+ "_" + search_value);
}
}
// 直接将数字写入的话会报错?
response.getWriter().write(countPage + "");
}
}
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
// 获取总页数
TeacherImpl teacherImpl = new TeacherImpl();
StudentImpl studentImpl = new StudentImpl();
SubjectImpl subjectImpl = new SubjectImpl();
Operator operator;
Student student;
Teacher teacher;
int countPage = 0;
session.setAttribute("operator_me", operator);
session.setAttribute("teacher_me", teacher);
response.sendRedirect("pages/info_teacher.jsp");
}
}
public class SearchTeacherClassServlet 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 {
StudentImpl studentImpl = new StudentImpl();
ClassesImpl classesImpl = new ClassesImpl();
TeacherImpl teacherImpl = new TeacherImpl();
Operator operator;
Classes classes;
List<Student> list_student;
HttpSession session = request.getSession();
// 裁判员老师查找自己的班级学生运动员
operator = (Operator) request.getSession().getAttribute("log_operator");
Teacher teacher = teacherImpl.query("ope_id", operator.getId() + "")
.get(0);
if (classesImpl.query("cla_tec", teacher.getName()).size() <= 0) {
response.sendRedirect("pages/noclass.jsp");
} else {
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 SearchTeacherClassServlet extends HttpServlet {
File file = sm.getFiles().getFile(0);
if (!file.isMissing())
{
delete(servletConfig, request, response, student);
upload(file, student);
}
} catch (Exception e)
{
}
}
// 删除旧照片
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)
{
}
}
}
break;
case 1:
label = new Label(j, i + 2
- (pg * sheetSize), bean
.getStudent().getName(),
cell_format);
break;
case 2:
label = new Label(j, i + 2
- (pg * sheetSize), bean
.getSubject().getName(),
cell_format);
break;
case 3:
number = new Number(j, i + 2
- (pg * sheetSize),
bean.getDaily(), cell_format);
break;
case 4:
number = new Number(j, i + 2
- (pg * sheetSize), bean.getExam(),
cell_format);
break;
default:
number = new Number(j, i + 2
- (pg * sheetSize),
bean.getCount(), cell_format);
}
if (j == 0 || j == 1 || j == 2)
ws.addCell(label);
else
ws.addCell(number);
}
} else {
break;
}
}
}
book.write();
book.close();
os.close();
} catch (RowsExceededException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
response.sendRedirect("/jspyundonghuimanager/PlanAddCla2SubSevlet");
}
}
public class AddTeacherServlet 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 {
// TODO Auto-generated method stub
Operator operator = new Operator();
Teacher teacher = new Teacher();
RoleImpl roleImpl = new RoleImpl();
TeacherImpl teacherImpl = new TeacherImpl();
OperatorImpl operatorImpl = new OperatorImpl();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
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 AddCla2SubServlet extends HttpServlet {
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")) {
countPage = studentImpl.getCountPage("cla_name", search_value
+ "");
} else if (search_type.equals("maj_name")) {
countPage = studentImpl.getCountPage("maj_name", search_value
+ "");
}
} else {
break;
}
}
}
book.write();
book.close();
os.close();
} catch (RowsExceededException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
}
}
}
}
}
public class AddStudentServlet extends HttpServlet {
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));
label = new Label(i, 1, title[i], f2);
ws.addCell(label);
ws.setColumnView(i, 15);
}
for (int i = 0; i < list_cla2Sub.size(); i++) {
label = new Label(0, i + 2, list_cla2Sub.get(i).getClasses()
.getName(), f3);
ws.addCell(label);
label = new Label(1, i + 2, list_cla2Sub.get(i).getSubject()
.getName(), f3);
ws.addCell(label);
label = new Label(2, i + 2, list_cla2Sub.get(i).getTeacher()
.getName(), f3);
ws.addCell(label);
ws.setRowView(i + 2, 400);
}
wwb.write();
wwb.close();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
log_operator = new Operator();
try {
conn = DB.getConn();
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);
@SuppressWarnings("deprecation")
public class ReportScoreServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private TeacherImpl teacherImpl = new TeacherImpl();
private ScoreImpl scoreImpl = new ScoreImpl();
private ClassesImpl classesImpl=new ClassesImpl();
private Teacher teacher;
private List<Score>beans = null;
private List<Classes> cla_list;
private Label label=null;
private Number number = null;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
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();
ScoreImpl scoreImpl = new ScoreImpl();
Operator operator;
Student student;
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 = 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
public class SearchSubjectServlet 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 {
// AJAX异步查询比赛项目
TeacherImpl teacherImpl = new TeacherImpl();
StudentImpl studentImpl = new StudentImpl();
SubjectImpl subjectImpl = new SubjectImpl();
Operator operator;
Student student;
Teacher teacher;
List<Subject> list_subject;
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_subject = new ArrayList<Subject>();
if (ope_rol_id == 1) {
// 管理员的查询
if (search_type.equals("stu_all"))
list_subject = subjectImpl.query("all", search_value, page);
else
list_subject = subjectImpl.query(search_type, search_value,
page);
} else if (ope_rol_id == 2) {
// 裁判员老师的查询
teacher = teacherImpl.query("ope_id", operator.getId() + "").get(0);
if (search_type.equals("stu_all")) {
list_subject = subjectImpl.query("tec_stu_all", teacher.getId()
+ "", page);
} else if (search_type.equals("sub_name")) {
list_subject = subjectImpl.query("tec_sub_name", teacher
.getId()
+ "_" + search_value, page);
} else if (search_type.equals("cla_name")) {
list_subject = subjectImpl.query("tec_cla_name", teacher
.getId()
+ "_" + search_value, page);
} else if (search_type.equals("stu_name")) {
list_subject = subjectImpl.query("tec_stu_name", teacher
.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();
}
}
}