基于javaweb+mysql的jsp+servlet学生在线选课系统(管理员、教师、学生)(java+jsp+servlet+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
内容:源码+数据库脚本+word报告文档
管理员:个人信息、学生、老师、学生、课程等管理
教师:个人信息、成绩、选课管理、教室查看
学生:个人信息、成绩查看、选课和查看
eclipse或MyEclipse或idea
管理员
学生
教师
技术框架
CSS JavaScript JSP Servlet JDBC MySQL
基于javaweb+mysql的JSP+Servlet学生在线选课系统(管理员、教师、学生)(java+jsp+servlet+mysql)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("error", "deleteSuccess");
request.getRequestDispatcher("Index.jsp").forward(request, response);
// String no=request.getParameter("aid");
// AdminService adminService=new AdminService();
// boolean result=adminService.deleteByAid(no);
// if(!result) { //删除失败
// request.setAttribute("error", "deleteError");
// request.getRequestDispatcher("adminIndex.jsp").forward(request, response);
// }
// else { //删除成功
// request.setAttribute("error", "deleteSuccess");
// request.getRequestDispatcher("Index.jsp").forward(request, response);
// }
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
@WebServlet("/AdminUpdateServlet")
public class AdminUpdateServlet extends HttpServlet {
}
}
@WebServlet("/AdminUpdateServlet")
public class AdminUpdateServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String no=request.getParameter("aid");
String pass1=request.getParameter("pass1");
String pass2=request.getParameter("pass2");
if(pass1.equals(pass2)) {
AdminService adminService=new AdminService();
boolean result=adminService.updateByAid(no, pass1);
if(!result) { //修改失败
request.setAttribute("error", "updateError");
}
else { //修改成功
request.setAttribute("error", "updateSuccess");
}
}
else {//两密码不一致
request.setAttribute("error", "unlike");
}
request.getRequestDispatcher("adminMod.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
request.getRequestDispatcher("gradeIns.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
@WebServlet("/StuDeleteServlet")
public class StuDeleteServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("error", "deleteSuccess");
request.getRequestDispatcher("Index.jsp").forward(request, response);
// String no=request.getParameter("sid");
// StudentService studentService=new StudentService();
// boolean result=studentService.deleteBySid(no);
// if(!result) { //删除失败
// request.setAttribute("error", "deleteError");
// request.getRequestDispatcher("studentIndex.jsp").forward(request, response);
// }
// else { //删除成功
// request.setAttribute("error", "deleteSuccess");
// request.getRequestDispatcher("Index.jsp").forward(request, response);
// }
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
@WebServlet("/TeaDeleteServlet")
public class TeaDeleteServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("error", "deleteSuccess");
@WebServlet("/TeaUpdateServlet")
public class TeaUpdateServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String no=request.getParameter("tid");
String pass1=request.getParameter("pass1");
String pass2=request.getParameter("pass2");
if(pass1.equals(pass2)) {
TeacherService teacherService=new TeacherService();
boolean result=teacherService.updateByTid(no, pass1);
if(!result) { //修改失败
request.setAttribute("error", "updateError");
}
else { //修改成功
request.setAttribute("error", "updateSuccess");
}
}
else {//两密码不一致
request.setAttribute("error", "unlike");
}
request.getRequestDispatcher("teacherMod.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
@WebServlet("/TeaAddGradeServlet")
public class TeaAddGradeServlet extends HttpServlet {
else {//两密码不一致
request.setAttribute("error", "unlike");
}
request.getRequestDispatcher("teacherMod.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
@WebServlet("/TeaAddGradeServlet")
public class TeaAddGradeServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sid=request.getParameter("sid");
String cid=request.getParameter("cid");
float grade=Float.parseFloat(request.getParameter("ack"));
Grade score=new Grade(cid,sid,grade); //封装到实体类
TeacherService teacherService=new TeacherService();
boolean result=teacherService.addGrade(score);
if(!result) { //添加失败
request.setAttribute("error", "addError");
}
else { //添加成功
request.setAttribute("error", "addSuccess");
}
request.getRequestDispatcher("gradeIns.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
@WebServlet("/StuCourseAddServlet")
public class StuCourseAddServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sid=request.getParameter("sid");
String cid=request.getParameter("cid");
Score score=new Score(sid,cid,"0"); //封装到实体类
StudentService studentService=new StudentService();
boolean result=studentService.addChooseCourse(score);
if(!result) { //添加失败
request.setAttribute("error", "addError");
}
else { //添加成功
request.setAttribute("error", "addSuccess");
}
request.getRequestDispatcher("StuCourseQueryServlet").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
doGet(request, response);
}
}
@WebServlet("/CourseAllStuQueryServlet")
public class CourseAllStuQueryServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String no=request.getParameter("cid");
TeacherService teacherService=new TeacherService();
List<Student> students=teacherService.studentQuery(no);
request.setAttribute("cid", no);
request.setAttribute("students", students);
request.getRequestDispatcher("gradestu.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
@WebServlet("/CourseAllStuQueryServlet")
public class CourseAllStuQueryServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String no=request.getParameter("cid");
TeacherService teacherService=new TeacherService();
List<Student> students=teacherService.studentQuery(no);
request.setAttribute("cid", no);
request.setAttribute("students", students);
request.getRequestDispatcher("gradestu.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
@WebServlet("/TeaLookcourseQueryServlet")
public class TeaLookcourseQueryServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String no=request.getParameter("tid");
TeacherService teacherService=new TeacherService();
response.sendRedirect("StudentQueryAllServlet");
}
else {
out.println("注册失败,该学生已存在,请检查学号是否正确!");
}*/
if(!result) { //注册失败
request.setAttribute("error", "addError");
}
else { //注册成功
request.setAttribute("error", "addSuccess");
}
request.getRequestDispatcher("addteacher.jsp").forward(request, response); //StudentQueryAllServlet直接转发给StudentInfoList.jsp,不需要进行处理
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
/**
* Servlet implementation class CourseAddServlet
*/
@WebServlet("/CourseAddServlet")
@WebServlet("/TeaLookcourseQueryServlet")
public class TeaLookcourseQueryServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String no=request.getParameter("tid");
TeacherService teacherService=new TeacherService();
List<LookCourse> courses=teacherService.lookcourseQuery(no);
request.setAttribute("courses", courses);
request.getRequestDispatcher("lookcourse.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
/**
* Servlet implementation class AllStuQueryServlet
*/
@WebServlet("/AllStuQueryServlet")
public class AllStuQueryServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public AllStuQueryServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
AdminService adminService=new AdminService();
List<Student> students=adminService.allstudentQuery();
request.setAttribute("students", students);
request.getRequestDispatcher("selstudent.jsp").forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
@WebServlet("/StuCourseAddServlet")
public class StuCourseAddServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sid=request.getParameter("sid");
String cid=request.getParameter("cid");
Score score=new Score(sid,cid,"0"); //封装到实体类
StudentService studentService=new StudentService();
boolean result=studentService.addChooseCourse(score);
if(!result) { //添加失败
request.setAttribute("error", "addError");
}
else { //添加成功
request.setAttribute("error", "addSuccess");
}
request.getRequestDispatcher("StuCourseQueryServlet").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
@WebServlet("/StuCourseDelServlet")
public class StuCourseDelServlet extends HttpServlet {
//功能:查询某学生的所有课程
public class StuCourseQueryServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String no=request.getParameter("sid");
StudentService studentService=new StudentService();
List<Course> courses=studentService.courseQuery(no);
request.setAttribute("courses", courses);
request.getRequestDispatcher("courseSelAndDel.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
@WebServlet("/AllTeaQueryServlet")
public class AllTeaQueryServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
AdminService adminService=new AdminService();
List<Teacher> teachers=adminService.allteacherQuery();
request.setAttribute("teachers", teachers);
request.getRequestDispatcher("selteacher.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
@WebServlet("/TeaAddGradeServlet")
public class TeaAddGradeServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sid=request.getParameter("sid");
String cid=request.getParameter("cid");
float grade=Float.parseFloat(request.getParameter("ack"));
Grade score=new Grade(cid,sid,grade); //封装到实体类
TeacherService teacherService=new TeacherService();
boolean result=teacherService.addGrade(score);
if(!result) { //添加失败
request.setAttribute("error", "addError");
}
else { //添加成功
request.setAttribute("error", "addSuccess");
}
request.getRequestDispatcher("gradeIns.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
@WebServlet("/StuDeleteServlet")
public class StuDeleteServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("error", "deleteSuccess");
request.getRequestDispatcher("Index.jsp").forward(request, response);
if(pass1.equals(pass2)) {
TeacherService teacherService=new TeacherService();
boolean result=teacherService.updateByTid(no, pass1);
if(!result) { //修改失败
request.setAttribute("error", "updateError");
}
else { //修改成功
request.setAttribute("error", "updateSuccess");
}
}
else {//两密码不一致
request.setAttribute("error", "unlike");
}
request.getRequestDispatcher("teacherMod.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
@WebServlet("/TeaAddGradeServlet")
public class TeaAddGradeServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sid=request.getParameter("sid");
String cid=request.getParameter("cid");
float grade=Float.parseFloat(request.getParameter("ack"));
Grade score=new Grade(cid,sid,grade); //封装到实体类
TeacherService teacherService=new TeacherService();
boolean result=teacherService.addGrade(score);
if(!result) { //添加失败
request.setAttribute("error", "addError");
}
else { //添加成功
request.setAttribute("error", "addSuccess");
}
request.getRequestDispatcher("gradeIns.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
* Servlet implementation class AdminDeleteServlet
*/
@WebServlet("/AdminDeleteServlet")
public class AdminDeleteServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("error", "deleteSuccess");
request.getRequestDispatcher("Index.jsp").forward(request, response);
// String no=request.getParameter("aid");
// AdminService adminService=new AdminService();
// boolean result=adminService.deleteByAid(no);
// if(!result) { //删除失败
// request.setAttribute("error", "deleteError");
// request.getRequestDispatcher("adminIndex.jsp").forward(request, response);
// }
// else { //删除成功
// request.setAttribute("error", "deleteSuccess");
// request.getRequestDispatcher("Index.jsp").forward(request, response);
// }
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
request.setAttribute("error", "addError");
}
else { //添加成功
request.setAttribute("error", "addSuccess");
}
request.getRequestDispatcher("StuCourseQueryServlet").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
@WebServlet("/StuCourseDelServlet")
public class StuCourseDelServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sid=request.getParameter("sid");
String cid=request.getParameter("cid");
request.setAttribute("sid", sid); //转发时使用
StudentService studentService=new StudentService();
boolean result=studentService.courseDelete(sid,cid);
if(!result) { //删除失败
request.setAttribute("error", "deleteError");
}
else { //删除成功
request.setAttribute("error", "deleteSuccess");
}
request.getRequestDispatcher("StuCourseQueryServlet").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
/**
* Servlet implementation class TeacherAddServlet
*/
@WebServlet("/TeacherAddServlet")
public class TeacherAddServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public TeacherAddServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String tId=request.getParameter("tId");
String tName=request.getParameter("tName");
String tPass=request.getParameter("tPass");
String dId=request.getParameter("dId");
String tSex=request.getParameter("tSex");
String tAge=request.getParameter("tAge");
String tEdu=request.getParameter("tEdu");
String tTitle=request.getParameter("tTitle");
String tSch=request.getParameter("tSch");
String tHealth=request.getParameter("tHealth");
Teacher teacher=new Teacher(tId,tName,tPass,dId,tSex,tAge,tEdu,tTitle,tSch,tHealth); //封装到实体类
AdminService adminService=new AdminService();
boolean result=adminService.addTeacher(teacher);
//PrintWriter out=response.getWriter();
/*if(result) {
out.println("注册成功!");
response.sendRedirect("StudentQueryAllServlet");
}
else {
out.println("注册失败,该学生已存在,请检查学号是否正确!");
}*/