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

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

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

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

项目介绍

学生选课系统,有学生、老师、管理员三种角色。 学生端权限

学生登录系统 选择课程并提交确认 各科成绩查询 总成绩查询 成绩排名、各科成绩排名

老师端权限

登录系统 课程管理(实现对课程的CURD) 考试成绩录入 各种查询(学生的单科成绩、总成绩、排名) 各种统计(统计及格率、统计80分以上的同学等)

管理端权限

登录系统 实现对学生的CURD 实现对老师的CURD 实现各种查询、统计

学完这个项目后的收获:

掌握项目开发的流程 掌握开发中的简单权限控制 掌握前端页面如何与后端整合 宏观把握一个项目 掌握echarts图表技术

环境需要

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项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目

技术栈

前端基础(Html、css、JavaScript、Jquery) mysql数据库 Web容器(Tomcat) Jsp/Servlet

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,然后运行; 3. 将项目中news.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入localhost:8080/jsp_zxmszssys 管理员账号/密码:admin/123456 老师账号/密码:zhangping/123456 学生账号/密码:0001/123456
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String method = request.getParameter("method");
		if("list".equals(method)) {
			this.list(request, response);
		}else if("add".equals(method)) {
			this.add(request, response);
		}else if("v_add".equals(method)) {
			this.v_add(request, response);
		}else if("edit".equals(method)) {
			this.findById(request, response);
		}else if("editsubmit".equals(method)) {
			this.editsubmit(request, response);
		}else if("delete".equals(method)) {
			this.delete(request, response);
		}
		
	}
	
	private void delete(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		try {
			DaoFactory.getInstance().getCourseDao().delete(Integer.parseInt(id));
			//直接重定向到列表页面
			response.sendRedirect(PathUtils.getBasePath(request)+"course?method=list");
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
	private void editsubmit(HttpServletRequest request, HttpServletResponse response) {
		String cName = request.getParameter("cName");
		Integer cId = getIntParameter(request, "cId");
		//老师ID
		Integer tId = Integer.parseInt(request.getParameter("tId"));
		Course course = new Course();
		course.setcId(cId);
		course.setcName(cName);
		//new一个Teacher对象,然后设置ID,然后再设置course对象的setTeacher关联 一下即可
		Teacher teacher = new Teacher();
		teacher.settId(tId);
		course.setTeacher(teacher);
		try {
			DaoFactory.getInstance().getCourseDao().update(course);
			//直接重定向到列表页面
			response.sendRedirect(PathUtils.getBasePath(request)+"course?method=list");
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		//上一页
		Integer prePage = 0;
		if(pageNo>1) {
			prePage = pageNo-1;
		}else {
			prePage = pageNo;
		}
		boolean isFirstPage = false;
		if(pageNo>1) {
			isFirstPage = false;
		}else {
			isFirstPage = true;
		}
		
		boolean isLastPage = false;
		if(pageNo<totalPage) {
			isLastPage = false;
		}else {
			isLastPage = true;
		}
		try {
			List<Student> list = null;//DaoFactory.getInstance().getStudentDao().list(null,pageNo,pageSize);
			request.setAttribute("list", list);
			request.setAttribute("pageSize", pageSize);
		
			request.setAttribute("isFirstPage", isFirstPage);//是否第一页
			request.setAttribute("isLastPage", isLastPage);//是否最后页
			
			request.setAttribute("totalCount", totalCount);
			request.setAttribute("totalPage",totalPage);
			request.setAttribute("prePage", prePage);
			request.setAttribute("nextPage", nextPage);
			request.setAttribute("pageNo", pageNo);
			request.getRequestDispatcher("page/student/list.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public Integer getIntParameter(HttpServletRequest request,String name) {
			req.getRequestDispatcher("login.jsp").forward(req, resp);
			return;
		}
		HttpSession session = req.getSession();
		if(StringUtils.isNotBlank(type)) {
			try {
				if("0".equals(type)) {
					//学生登录验证
					Student student = DaoFactory.getInstance().getStudentDao().login(userName, MD5.encrypByMd5(MD5.encrypByMd5(password)));
					if(student != null) {
						session.setAttribute("user", student);
						session.setAttribute("type", type);
						resp.sendRedirect("index.jsp");
					}else {
						req.setAttribute("error", "用户名或密码错误!");
						req.getRequestDispatcher("login.jsp").forward(req, resp);
					}
				}else if("1".equals(type)) {
					//老师登录验证
					Teacher teacher = DaoFactory.getInstance().getTeacherDao().login(userName, MD5.encrypByMd5(MD5.encrypByMd5(password)));
					if(teacher != null) {
						session.setAttribute("user", teacher);
						session.setAttribute("type", type);
						resp.sendRedirect("index.jsp");
					}else {
						req.setAttribute("error", "用户名或密码错误!");
						req.getRequestDispatcher("login.jsp").forward(req, resp);
					}
				}else {
					//管理员登录验证
					Admin admin = new Admin();
					admin.setUserName(userName);
					admin.setPwd(MD5.encrypByMd5(MD5.encrypByMd5(password)));
					Admin entity = DaoFactory.getInstance().getAdminDao().login(admin);
					if(entity != null) {
						//执行跳转
						session.setAttribute("user", entity);
						session.setAttribute("type", type);
						resp.sendRedirect("index.jsp");
					}else {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String method = request.getParameter("method");
		if ("query_range".equals(method)) {
			this.query_range(request, response);
		} else if ("query_jgl".equals(method)) {
			this.query_jgl(request, response);
		} else if ("query_teacher".equals(method)) {
			this.query_teacher(request, response);
		}
	}

	public void query_teacher(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		Teacher teacher = (Teacher) request.getSession().getAttribute("user");
		try {
			List<Map<String, Object>> list = DaoFactory.getInstance().getScDao().query_rangeByTid(teacher.gettId());
			request.setAttribute("list1", list);
			List<Map<String, Object>> list2 = DaoFactory.getInstance().getScDao().query_jglByTid(teacher.gettId());
			request.setAttribute("list2", list2);
			request.getRequestDispatcher("page/sc/query_teacher.jsp").forward(request, response);

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void query_range(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		try {
			List<Map<String, Object>> list = DaoFactory.getInstance().getScDao().query_range();
			request.setAttribute("list", list);
			request.getRequestDispatcher("page/sc/query_range.jsp").forward(request, response);

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void query_jgl(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			List<Map<String, Object>> list = DaoFactory.getInstance().getScDao().query_jgl();
			request.setAttribute("list", list);
			request.getRequestDispatcher("page/sc/query_jgl.jsp").forward(request, response);
		} catch (SQLException e) {
			e.printStackTrace();

@WebServlet("/scquery")
public class SCQueryServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String method = request.getParameter("method");
		if ("query_range".equals(method)) {
			this.query_range(request, response);
		} else if ("query_jgl".equals(method)) {
			this.query_jgl(request, response);
		} else if ("query_teacher".equals(method)) {
			this.query_teacher(request, response);
		}
	}

	public void query_teacher(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		Teacher teacher = (Teacher) request.getSession().getAttribute("user");
		try {
			List<Map<String, Object>> list = DaoFactory.getInstance().getScDao().query_rangeByTid(teacher.gettId());
			request.setAttribute("list1", list);
			List<Map<String, Object>> list2 = DaoFactory.getInstance().getScDao().query_jglByTid(teacher.gettId());
			request.setAttribute("list2", list2);
			request.getRequestDispatcher("page/sc/query_teacher.jsp").forward(request, response);
		
		//1、获取老师的session中对象tId
		Teacher teacher =(Teacher)request.getSession().getAttribute("user");
		Integer pageNo = getIntParameter(request, "pageNo");
		Course course = new Course();
		course.setTeacher(teacher);
		PageInfo<Course> pageInfo = new PageInfo<>(pageNo);
		//2、查询所教课程列表
		try {
			pageInfo = DaoFactory.getInstance().getCourseDao().list(course, pageInfo);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		//3、将信息返回到jsp页面
		request.setAttribute("pageInfo", pageInfo);
		request.getRequestDispatcher("page/sc/teacher_course.jsp").forward(request, response);
	}
	
	
	//保存选课
	private void submit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String[] cIds = request.getParameterValues("cId");
		List<Integer> cIdArray = new ArrayList<Integer>();
		for (String string : cIds) {
			cIdArray.add(Integer.parseInt(string));
		}
		Student student = (Student)request.getSession().getAttribute("user");
		try {
			int[] arr = DaoFactory.getInstance().getScDao().add(cIdArray, student.getStuId());
			if(arr.length == 0) {
				response.sendRedirect(PathUtils.getBasePath(request)+"sc?method=select&msg=0");
			}else {
				response.sendRedirect(PathUtils.getBasePath(request)+"sc?method=select&msg=1");
			}
		} catch (SQLException e) {
			response.sendRedirect(PathUtils.getBasePath(request)+"sc?method=select&msg=0");
		}
	}
	//选课跳转
	private void select(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PageInfo<Course> info = new PageInfo<>(1);
		info.setPageSize(1000);
		try {
			info = DaoFactory.getInstance().getCourseDao().list(null, info);
			//获取登录的学生信息
			Student student = (Student)request.getSession().getAttribute("user");
			//获取已选课的课程ID(cId)
			List<Sc> list = DaoFactory.getInstance().getScDao().listByStuId(student.getStuId());
			request.setAttribute("scs",list);
})
public class PermissionFilter implements Filter {

	public static String excludeString ;
	
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		excludeString = filterConfig.getInitParameter("exclude");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest httpServletRequest = (HttpServletRequest)request;
		HttpServletResponse httpServletResponse = (HttpServletResponse)response;
		Object user = httpServletRequest.getSession().getAttribute("user");
		String uri = httpServletRequest.getRequestURI();
		if(isExist(uri) || uri.equals(httpServletRequest.getContextPath()+"/")) {
			chain.doFilter(httpServletRequest, httpServletResponse);
		}else {
			if(user != null) {
				chain.doFilter(httpServletRequest, httpServletResponse);
			}else {
				httpServletResponse.sendRedirect("noprivilige.jsp");
			}
		}
	}
	
	public static boolean isExist(String uri) {
		//最后url的结尾与exclude匹配
		String[] arr = excludeString.split(",");
		boolean flag = false;
		for (String string : arr) {
			if(uri.endsWith(string)) {
				flag = true;
			}
		}
		return flag;
	}
	

	@Override
	public void destroy() {

	}

}
		Integer tId = Integer.parseInt(request.getParameter("tId"));
		Course course = new Course();
		course.setcName(cName);
		//new一个Teacher对象,然后设置ID,然后再设置course对象的setTeacher关联 一下即可
		Teacher teacher = new Teacher();
		teacher.settId(tId);
		course.setTeacher(teacher);
		try {
			DaoFactory.getInstance().getCourseDao().add(course);
			//直接重定向到列表页面
			response.sendRedirect(PathUtils.getBasePath(request)+"course?method=list");
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private void list(HttpServletRequest request, HttpServletResponse response) {
		//当前页码
		Integer pageNo = getIntParameter(request, "pageNo");
		//查询条件
		Integer cId = getIntParameter(request, "cId");
		String cName = request.getParameter("cName");
		String tName = request.getParameter("tName");
		String userName = request.getParameter("userName");
		
		Course course = new Course();
		course.setcId(cId);
		course.setcName(cName);
		Teacher teacher = new Teacher();
		teacher.settName(tName);
		teacher.setUserName(userName);
		course.setTeacher(teacher);
		
		//构造了一个pageInfo对象
		PageInfo<Course> pageInfo = new PageInfo<>(pageNo);
		try {
			pageInfo = DaoFactory.getInstance().getCourseDao().list(course,pageInfo);
		} catch (SQLException e1) {
			e1.printStackTrace();
		}
		try {
			request.setAttribute("pageInfo", pageInfo);
			//回写到页面
			request.setAttribute("course", course);
			request.getRequestDispatcher("page/course/list.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();

@WebServlet("/scquery")
public class SCQueryServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String method = request.getParameter("method");
		if ("query_range".equals(method)) {
			this.query_range(request, response);
		} else if ("query_jgl".equals(method)) {
			this.query_jgl(request, response);
		} else if ("query_teacher".equals(method)) {
			this.query_teacher(request, response);
		}
	}

	public void query_teacher(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		Teacher teacher = (Teacher) request.getSession().getAttribute("user");
		try {
			List<Map<String, Object>> list = DaoFactory.getInstance().getScDao().query_rangeByTid(teacher.gettId());
			request.setAttribute("list1", list);
			List<Map<String, Object>> list2 = DaoFactory.getInstance().getScDao().query_jglByTid(teacher.gettId());
			request.setAttribute("list2", list2);
			request.getRequestDispatcher("page/sc/query_teacher.jsp").forward(request, response);

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void query_range(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		try {

@WebServlet("/scquery")
public class SCQueryServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String method = request.getParameter("method");
		if ("query_range".equals(method)) {
			this.query_range(request, response);
		} else if ("query_jgl".equals(method)) {
			this.query_jgl(request, response);
		} else if ("query_teacher".equals(method)) {
			this.query_teacher(request, response);
		}
	}

@WebServlet("/sc")
public class SCServlet extends HttpServlet {

	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String method = request.getParameter("method");
		if("select".equals(method)) {
			this.select(request, response);
		}else if("submit".equals(method)) {
			this.submit(request, response);
		}else if("tc".equals(method)) {
			this.teacher_course(request, response);
		}else if("cs".equals(method)) {
			this.course_student(request, response);
		}else if("score_submit".equals(method)) {
			this.score_submit(request, response);
		}
		
	}
	//评分提交
	private void score_submit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Integer cId = getIntParameter(request, "cId");
		String[] stuIdArr = request.getParameterValues("stuId");
		String[] scoreArr = request.getParameterValues("score");
		try {
			DaoFactory.getInstance().getScDao().update(stuIdArr, scoreArr, cId);
			response.sendRedirect(PathUtils.getBasePath(request)+"sc?method=cs&cId="+cId+"&msg=1");
		} catch (SQLException e) {
			response.sendRedirect(PathUtils.getBasePath(request)+"sc?method=cs&cId="+cId+"&msg=0");
			e.printStackTrace();
		}
	}
	//选课的学生查询
	private void course_student(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//1、获取cid的参数
		Integer cId = getIntParameter(request, "cId");
		//2、获取学生列表
			this.select(request, response);
		}else if("submit".equals(method)) {
			this.submit(request, response);
		}else if("tc".equals(method)) {
			this.teacher_course(request, response);
		}else if("cs".equals(method)) {
			this.course_student(request, response);
		}else if("score_submit".equals(method)) {
			this.score_submit(request, response);
		}
		
	}
	//评分提交
	private void score_submit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Integer cId = getIntParameter(request, "cId");
		String[] stuIdArr = request.getParameterValues("stuId");
		String[] scoreArr = request.getParameterValues("score");
		try {
			DaoFactory.getInstance().getScDao().update(stuIdArr, scoreArr, cId);
			response.sendRedirect(PathUtils.getBasePath(request)+"sc?method=cs&cId="+cId+"&msg=1");
		} catch (SQLException e) {
			response.sendRedirect(PathUtils.getBasePath(request)+"sc?method=cs&cId="+cId+"&msg=0");
			e.printStackTrace();
		}
	}
	//选课的学生查询
	private void course_student(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//1、获取cid的参数
		Integer cId = getIntParameter(request, "cId");
		//2、获取学生列表
		try {
			List<Student> list = DaoFactory.getInstance().getScDao().listStudentByCId(cId);
			request.setAttribute("list", list);
			request.setAttribute("cId", cId);
			request.getRequestDispatcher("page/sc/course_student.jsp").forward(request, response);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		//3、return页面
		
	}
	
	private void teacher_course(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		//1、获取老师的session中对象tId
		Teacher teacher =(Teacher)request.getSession().getAttribute("user");
		Integer pageNo = getIntParameter(request, "pageNo");
		Course course = new Course();
		course.setTeacher(teacher);
		PageInfo<Course> pageInfo = new PageInfo<>(pageNo);
		//2、查询所教课程列表
			this.add(request, response);
		}else if("edit".equals(method)) {
			this.findById(request, response);
		}else if("editsubmit".equals(method)) {
			this.editsubmit(request, response);
		}else if("delete".equals(method)) {
			this.delete(request, response);
		}
		
	}
	
	private void delete(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		try {
			DaoFactory.getInstance().getTeacherDao().delete(Integer.parseInt(id));
			//直接重定向到列表页面
			response.sendRedirect(PathUtils.getBasePath(request)+"teacher?method=list");
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
	private void editsubmit(HttpServletRequest request, HttpServletResponse response) {
		Integer tId = Integer.parseInt(request.getParameter("tId"));
		String tName = request.getParameter("tName");
		String userName = request.getParameter("userName");
		Teacher teacher = new Teacher();
		teacher.settId(tId);
		teacher.settName(tName);
		teacher.setUserName(userName);
		try {
			DaoFactory.getInstance().getTeacherDao().update(teacher);
			//直接重定向到列表页面
			response.sendRedirect(PathUtils.getBasePath(request)+"teacher?method=list");
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	private void findById(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		try {
			Teacher teacher = DaoFactory.getInstance().getTeacherDao().findById(Integer.parseInt(id));
			request.setAttribute("teacher", teacher);
			request.getRequestDispatcher("page/teacher/update.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
	
	
	private void add(HttpServletRequest request, HttpServletResponse response) {
		}else if("detail".equals(method)) {
			this.detail(request, response);
		}
		
	}
	
	private void delete(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		try {
			DaoFactory.getInstance().getStudentDao().delete(Integer.parseInt(id));
			//直接重定向到列表页面
			response.sendRedirect(PathUtils.getBasePath(request)+"student?method=list");
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
	private void editsubmit(HttpServletRequest request, HttpServletResponse response) {
		Integer stuId = Integer.parseInt(request.getParameter("stuId"));
		String stuNo = request.getParameter("stuNo");
		String stuName = request.getParameter("stuName");
		Student student = new Student();
		student.setStuName(stuName);
		student.setStuNo(stuNo);
		student.setStuId(stuId);
		try {
			DaoFactory.getInstance().getStudentDao().update(student);
			//直接重定向到列表页面
			response.sendRedirect(PathUtils.getBasePath(request)+"student?method=list");
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	private void findById(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		try {
			Student student = DaoFactory.getInstance().getStudentDao().findById(Integer.parseInt(id));
			request.setAttribute("student", student);
			request.getRequestDispatcher("page/student/update.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String method = request.getParameter("method");
		if("list".equals(method)) {
			this.list(request, response);
		}else if("add".equals(method)) {
			this.add(request, response);
		}else if("edit".equals(method)) {
			this.findById(request, response);
		}else if("editsubmit".equals(method)) {
			this.editsubmit(request, response);
		}else if("delete".equals(method)) {
			this.delete(request, response);
		}
		
	}
	
	private void delete(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		try {
			DaoFactory.getInstance().getTeacherDao().delete(Integer.parseInt(id));
			//直接重定向到列表页面
			response.sendRedirect(PathUtils.getBasePath(request)+"teacher?method=list");
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
	private void editsubmit(HttpServletRequest request, HttpServletResponse response) {
		Integer tId = Integer.parseInt(request.getParameter("tId"));
		String tName = request.getParameter("tName");
		String userName = request.getParameter("userName");
		Teacher teacher = new Teacher();
		teacher.settId(tId);
		teacher.settName(tName);
		teacher.setUserName(userName);
		try {
			DaoFactory.getInstance().getTeacherDao().update(teacher);
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String method = request.getParameter("method");
		if("select".equals(method)) {
			this.select(request, response);
		}else if("submit".equals(method)) {
			this.submit(request, response);
		}else if("tc".equals(method)) {
			this.teacher_course(request, response);
		}else if("cs".equals(method)) {
			this.course_student(request, response);
		}else if("score_submit".equals(method)) {
			this.score_submit(request, response);
		}
		
	}
	//评分提交
	private void score_submit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Integer cId = getIntParameter(request, "cId");
		String[] stuIdArr = request.getParameterValues("stuId");
		String[] scoreArr = request.getParameterValues("score");
		try {
			DaoFactory.getInstance().getScDao().update(stuIdArr, scoreArr, cId);
			response.sendRedirect(PathUtils.getBasePath(request)+"sc?method=cs&cId="+cId+"&msg=1");
		} catch (SQLException e) {
			response.sendRedirect(PathUtils.getBasePath(request)+"sc?method=cs&cId="+cId+"&msg=0");
			e.printStackTrace();
		}
	}
	//选课的学生查询
	private void course_student(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//1、获取cid的参数
		Integer cId = getIntParameter(request, "cId");
		//2、获取学生列表
		try {
			List<Student> list = DaoFactory.getInstance().getScDao().listStudentByCId(cId);
			request.setAttribute("list", list);
			request.setAttribute("cId", cId);
			request.getRequestDispatcher("page/sc/course_student.jsp").forward(request, response);
			request.getRequestDispatcher("page/sc/query_range.jsp").forward(request, response);

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void query_jgl(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			List<Map<String, Object>> list = DaoFactory.getInstance().getScDao().query_jgl();
			request.setAttribute("list", list);
			request.getRequestDispatcher("page/sc/query_jgl.jsp").forward(request, response);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}

@WebFilter(urlPatterns= {"/*"},initParams= {
		@WebInitParam(name="exclude",value="/login.jsp,/login,/noprivilige.jsp,.css,.png,.jpg,.js")
})
public class PermissionFilter implements Filter {

	public static String excludeString ;
	

@WebServlet("/main")
public class MainServlet extends HttpServlet {

	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			List<Map<String, Object>> list = DaoFactory.getInstance().getScDao().query_jgl();
			request.setAttribute("list", list);
			List<Map<String, Object>> top5List = DaoFactory.getInstance().getScDao().top5();
			request.setAttribute("top5List", top5List);
			request.getRequestDispatcher("main.jsp").forward(request, response);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值