作者主页:源码空间站2022

 简介:Java领域优质创作者、Java项目、学习资料、技术互助

项目介绍

管理员对全局的管理,比如用户,老师,题目,留言板,发布资料等。老师可以实现在线发布题目,下载学生作业等。学生可以浏览资料,公告,发表留言等。总之完整的实现了一个网络教学平台的功能。

由于本程序规模不大,可供课程设计,毕业设计学习演示之用

环境需要

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版本;

技术栈

HTML+CSS+JavaScript+jsp+mysql

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;

4. 运行项目,输入localhost:8080/login.jsp 登录

运行截图

前台页面

Java在线教育项目名称 java教育平台项目_json

Java在线教育项目名称 java教育平台项目_开发语言_02

Java在线教育项目名称 java教育平台项目_Java在线教育项目名称_03

Java在线教育项目名称 java教育平台项目_Java在线教育项目名称_04

管理端页面

Java在线教育项目名称 java教育平台项目_开发语言_05

Java在线教育项目名称 java教育平台项目_开发语言_06

Java在线教育项目名称 java教育平台项目_java_07

Java在线教育项目名称 java教育平台项目_java_08

相关代码 

用户管理控制器

public class UsersAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private Integer id;
	private String username; 	// 用户名
	private String password; 	// 密码
	private String realname; 	// 姓名
	private int age; 			// 年龄
	private String sex;			// 性别
	private String phone; 		// 联系方式
	private String role; 		// 角色
	private String remark; 		// 备注

	
	private IUsersService usersService;
	private Users user = new Users();
	
	public String login() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		user.setUsername(request.getParameter("username"));
		user.setPassword(request.getParameter("password"));
		System.out.println(user.getUsername() + " " + user.getPassword());
		
		String role = "error";
		try {
			Users loginUser = usersService.login(user.getUsername(),user.getPassword());
			if (null != loginUser) {	// 登录成功
				ActionContext context = ActionContext.getContext();
				context.getSession().put("LOGINUSER", loginUser);
				role = loginUser.getRole();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("登录用户类型: " + role);
		return role;
	}

	public void findAllUsers() throws UnsupportedEncodingException {

		HttpServletRequest request = ServletActionContext.getRequest();
		// 获取请求次数
		String draw = "0";
		draw = request.getParameter("draw");
		// 数据起始位置
		String start = request.getParameter("start");
		int startId = Integer.parseInt(start);
		// 数据长度
		String length = request.getParameter("length");
		int endId = startId + Integer.parseInt(length);
		// 获取排序方式 默认为asc
		String orderDir = "asc"; 
		// 定义列名
		String[] cols = { "username", "password", "realname", "age", "sex", "phone", "role", "remark" };
		// 获取客户端需要那一列排序
		String orderColumn = "0"; 
		// 排序列
		orderColumn = request.getParameter("order[0][column]");
		orderColumn = cols[Integer.parseInt(orderColumn)];
		orderDir = request.getParameter("order[0][dir]");
		// 搜索过滤
		String searchValue = new String(request.getParameter("search[value]")
				.getBytes("ISO8859-1"), "UTF-8");
		System.out.println("draw: " + draw + " start: " + start + " length: "
				+ length + " orderColumn: " + orderColumn + " orderDir: " + orderDir + " searchValue: " + searchValue);


		List<Users> list1 = usersService.findAllUsers();
//		String total = String.valueOf(list1.size());
		String total;
		if(list1 == null || list1.size() == 0){
			total = String.valueOf(0);
		}else{
			total = String.valueOf(list1.size());
		}
		List<Users> list = usersService.findUsersByKeyword(searchValue, startId, endId, orderColumn, orderDir);
		
		Map<Object, Object> info = new HashMap<Object, Object>();
		info.put("data", list);
		info.put("recordsTotal", total);
		info.put("recordsFiltered", String.valueOf(usersService.getUsersFiltered(searchValue)));
		info.put("draw", draw);
		String json = new Gson().toJson(info);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/json");
		response.setCharacterEncoding("UTF-8");
		try {
			PrintWriter out = response.getWriter();
			out.println(json);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void addUser() throws IOException {
		
		HttpServletRequest request = ServletActionContext.getRequest();

		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String realname = request.getParameter("realname");
		int age = Integer.parseInt(request.getParameter("age"));
		String sex = request.getParameter("sex");
		String phone = request.getParameter("phone");
		String role = request.getParameter("role");
		String remark = request.getParameter("remark");

		Users user = new Users();
		user.setUsername(username);
		user.setPassword(password);
		user.setRealname(realname);
		user.setAge(age);
		user.setSex(sex);
		user.setPhone(phone);
		user.setRole(role);
		user.setRemark(remark);

		usersService.addUser(user);
		
		JSONObject json = new JSONObject();
		json.put("status", "success");

		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/json");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.println(json.toString());
		out.flush();
		out.close();
	}
	
	public void updateUser() throws IOException {
		
		HttpServletRequest request = ServletActionContext.getRequest();

		int id = Integer.parseInt(request.getParameter("id"));
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String realname = request.getParameter("realname");
		int age = Integer.parseInt(request.getParameter("age"));
		String sex = request.getParameter("sex");
		String phone = request.getParameter("phone");
		String role = request.getParameter("role");
		String remark = request.getParameter("remark");

		Users user = new Users();
		user.setId(id);
		user.setUsername(username);
		user.setPassword(password);
		user.setRealname(realname);
		user.setAge(age);
		user.setSex(sex);
		user.setPhone(phone);
		user.setRole(role);
		user.setRemark(remark);

		usersService.updateUser(user);
		
		JSONObject json = new JSONObject();
		json.put("status", "success");

		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/json");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.println(json.toString());
		out.flush();
		out.close();
	}
	
	public void deleteUser() throws IOException {
		
		HttpServletRequest request = ServletActionContext.getRequest();

		String username = request.getParameter("username");
		
		usersService.deleteUserByUsername(username);
		
		JSONObject json = new JSONObject();
		json.put("status", "success");

		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/json");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.println(json.toString());
		out.flush();
		out.close();
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getRealname() {
		return realname;
	}

	public void setRealname(String realname) {
		this.realname = realname;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public IUsersService getUsersService() {
		return usersService;
	}

	public void setUsersService(IUsersService usersService) {
		this.usersService = usersService;
	}

	public Users getUser() {
		return user;
	}

	public void setUser(Users user) {
		this.user = user;
	}

}

问题管理控制器

public class OptionAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private Integer optionId; // 选项id
	private Integer subjectId; // 所属投票id
	private String optionContent; // 选项内容
	private String remark; // 备注

	private IOptionService optionService;
	
	private Option Option = new Option();

	public void findAllOption() throws UnsupportedEncodingException {

		HttpServletRequest request = ServletActionContext.getRequest();
		// 获取请求次数
		String draw = "0";
		draw = request.getParameter("draw");
		// 数据起始位置
		String start = request.getParameter("start");
		int startId = Integer.parseInt(start);
		// 数据长度
		String length = request.getParameter("length");
		int endId = startId + Integer.parseInt(length);
		// 获取排序方式 默认为desc
		String orderDir = "desc"; 
		// 定义列名
		String[] cols = { "subjectId", "optionContent"};
		// 获取客户端需要那一列排序
		String orderColumn = "0"; 
		// 排序列
		orderColumn = request.getParameter("order[0][column]");
		orderColumn = cols[Integer.parseInt(orderColumn)];
		orderDir = request.getParameter("order[0][dir]");
		// 搜索过滤
		String searchValue = new String(request.getParameter("search[value]")
				.getBytes("ISO8859-1"), "UTF-8");
		System.out.println("draw: " + draw + " start: " + start + " length: "
				+ length + " orderColumn: " + orderColumn + " orderDir: " + orderDir + " searchValue: " + searchValue);

		List<Option> list1 = optionService.findAllOption();
		String total = String.valueOf(list1.size());
		List<Option> list = optionService.findOptionByKeyword(searchValue, startId, endId, orderColumn, orderDir);

		Map<Object, Object> info = new HashMap<Object, Object>();
		info.put("data", list);
		info.put("recordsTotal", total);
		info.put("recordsFiltered", String.valueOf(optionService
				.getOptionFiltered(searchValue)));
		info.put("draw", draw);
		String json = new Gson().toJson(info);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/json");
		response.setCharacterEncoding("UTF-8");
		try {
			PrintWriter out = response.getWriter();
			out.println(json);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void addOption() throws IOException {

		HttpServletRequest request = ServletActionContext.getRequest();

		try {
			int subjectId = Integer.parseInt(request.getParameter("subjectId"));
			String optionContent = request.getParameter("optionContent");
			
			Option option = new Option();
			option.setSubjectId(subjectId);
			option.setOptionContent(optionContent);
			option.setVotes(0);
			
			optionService.addOption(option);

			JSONObject json = new JSONObject();
			json.put("status", "success");
			
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("text/json");
			response.setCharacterEncoding("UTF-8");
			PrintWriter out = response.getWriter();
			out.println(json.toString());
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void updateOption() throws IOException {

		HttpServletRequest request = ServletActionContext.getRequest();
		try {
			int optionId = Integer.parseInt(request.getParameter("optionId"));
			int subjectId = Integer.parseInt(request.getParameter("subjectId"));
			String optionContent = request.getParameter("optionContent");
			int votes = Integer.parseInt(request.getParameter("votes"));
			
			Option option = new Option();
			option.setOptionId(optionId);
			option.setSubjectId(subjectId);
			option.setOptionContent(optionContent);
			option.setVotes(votes);
			
			optionService.updateOption(option);
			
			JSONObject json = new JSONObject();
			json.put("status", "success");

			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("text/json");
			response.setCharacterEncoding("UTF-8");
			PrintWriter out = response.getWriter();
			out.println(json.toString());
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void deleteOption() throws IOException {

		HttpServletRequest request = ServletActionContext.getRequest();

		try {
			int optionId = Integer.parseInt(request.getParameter("optionId"));

			optionService.deleteOptionById(optionId);

			JSONObject json = new JSONObject();
			json.put("status", "success");

			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("text/json");
			response.setCharacterEncoding("UTF-8");
			PrintWriter out = response.getWriter();
			out.println(json.toString());
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void findOptionsBySubjectId() throws IOException {

		HttpServletRequest request = ServletActionContext.getRequest();

		try {
			int subjectId = Integer.parseInt(request.getParameter("subjectId"));

			List<Option> list = optionService.findOptionsBySubjectId(subjectId);

			JSONObject json = new JSONObject();
			json.put("result", list);
			json.put("status", "success");

			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("text/json");
			response.setCharacterEncoding("UTF-8");
			PrintWriter out = response.getWriter();
			out.println(json.toString());
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public Integer getOptionId() {
		return optionId;
	}

	public void setOptionId(Integer optionId) {
		this.optionId = optionId;
	}

	public Integer getSubjectId() {
		return subjectId;
	}

	public void setSubjectId(Integer subjectId) {
		this.subjectId = subjectId;
	}

	public String getOptionContent() {
		return optionContent;
	}

	public void setOptionContent(String optionContent) {
		this.optionContent = optionContent;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public IOptionService getOptionService() {
		return optionService;
	}

	public void setOptionService(IOptionService optionService) {
		this.optionService = optionService;
	}

	public Option getOption() {
		return Option;
	}

	public void setOption(Option option) {
		Option = option;
	}

}

投票管理控制器

public class SubjectAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private Integer id; // 投票id
	private String subjectName; // 投票名
	private String optionType; // 选项类型(单选、多选)
	private int optionNum; // 选项数目
	private Date createTime; // 创建时间
	private String remark; // 备注

	private ISubjectService subjectService;
	private IOptionService optionService;
	private Subject subject = new Subject();

	public void findAllSubject() throws UnsupportedEncodingException {

		HttpServletRequest request = ServletActionContext.getRequest();
		// 获取请求次数
		String draw = "0";
		draw = request.getParameter("draw");
		// 数据起始位置
		String start = request.getParameter("start");
		int startId = Integer.parseInt(start);
		// 数据长度
		String length = request.getParameter("length");
		int endId = startId + Integer.parseInt(length);
		// 获取排序方式 默认为desc
		String orderDir = "desc"; 
		// 定义列名
		String[] cols = { "subjectName", "optionType", "optionNum", "createTime" };
		// 获取客户端需要那一列排序
		String orderColumn = "0"; 
		// 排序列
		orderColumn = request.getParameter("order[0][column]");
		orderColumn = cols[Integer.parseInt(orderColumn)];
		orderDir = request.getParameter("order[0][dir]");
		// 搜索过滤
		String searchValue = new String(request.getParameter("search[value]")
				.getBytes("ISO8859-1"), "UTF-8");
		System.out.println("draw: " + draw + " start: " + start + " length: "
				+ length + " orderColumn: " + orderColumn + " orderDir: " + orderDir + " searchValue: " + searchValue);

		List<Subject> list1 = subjectService.findAllSubject();
//		String total = String.valueOf(list1.size());
		String total;
		if(list1 == null || list1.size() == 0){
			total = String.valueOf(0);
		}else{
			total = String.valueOf(list1.size());
		}
		List<Subject> list = subjectService.findSubjectByKeyword(searchValue, startId, endId, orderColumn, orderDir);

		Map<Object, Object> info = new HashMap<Object, Object>();
		info.put("data", list);
		info.put("recordsTotal", total);
		info.put("recordsFiltered", String.valueOf(subjectService
				.getSubjectFiltered(searchValue)));
		info.put("draw", draw);
		String json = new Gson().toJson(info);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/json");
		response.setCharacterEncoding("UTF-8");
		try {
			PrintWriter out = response.getWriter();
			out.println(json);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void addSubject() throws IOException {

		HttpServletRequest request = ServletActionContext.getRequest();

		try {
			subjectName = request.getParameter("subjectName");
			String optionType = request.getParameter("optionType");
			int optionNum = Integer.parseInt(request.getParameter("optionNum"));
			Date nowDate = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date createTime = sdf.parse(sdf.format(nowDate));
			
			Subject subject = new Subject();
			subject.setSubjectName(subjectName);
			subject.setOptionType(optionType);
			subject.setOptionNum(optionNum);
			subject.setCreateTime(createTime);
			
			subjectService.addSubject(subject);
			
			Subject addedSubject = subjectService.findSubjectBySubjectName(subjectName);

			JSONObject json = new JSONObject();
			json.put("result", addedSubject);
			json.put("status", "success");
			
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("text/json");
			response.setCharacterEncoding("UTF-8");
			PrintWriter out = response.getWriter();
			out.println(json.toString());
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void updateSubject() throws IOException {

		HttpServletRequest request = ServletActionContext.getRequest();
		try {
			int id = Integer.parseInt(request.getParameter("id"));
			subjectName = request.getParameter("subjectName");
			String optionType = request.getParameter("optionType");
			int optionNum = Integer.parseInt(request.getParameter("optionNum"));
			
			Subject subject = new Subject();
			subject.setId(id);
			subject.setSubjectName(subjectName);
			subject.setOptionType(optionType);
			subject.setOptionNum(optionNum);
			
			subjectService.updateSubject(subject);
			
			JSONObject json = new JSONObject();
			json.put("status", "success");

			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("text/json");
			response.setCharacterEncoding("UTF-8");
			PrintWriter out = response.getWriter();
			out.println(json.toString());
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void deleteSubject() throws IOException {

		HttpServletRequest request = ServletActionContext.getRequest();

		try {
			int id = Integer.parseInt(request.getParameter("id"));

			subjectService.deleteSubjectById(id);

			JSONObject json = new JSONObject();
			json.put("status", "success");

			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("text/json");
			response.setCharacterEncoding("UTF-8");
			PrintWriter out = response.getWriter();
			out.println(json.toString());
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @Func 根据投票id查找对应的投票信息
	 * @author Justerdu 2020-03-13
	 */
	public void findSubjectInfoById() throws IOException {

		HttpServletRequest request = ServletActionContext.getRequest();

		try {
			int id = Integer.parseInt(request.getParameter("id"));

			Subject subject = subjectService.findSubjectById(id);

			JSONObject json = new JSONObject();
			json.put("result", subject);
			json.put("status", "success");

			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("text/json");
			response.setCharacterEncoding("UTF-8");
			PrintWriter out = response.getWriter();
			out.println(json.toString());
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * @Func 删除投票(同时需删除其子选项)
	 * @author Justerdu 2020-03-13
	 */
	public void deleteSubjectInfoAndOptionsInfoById() throws IOException {

		HttpServletRequest request = ServletActionContext.getRequest();

		try {
			int id = Integer.parseInt(request.getParameter("id"));

			// 根据subjectId删除对应的投票选项
			optionService.deleteOptionsBySubjectId(id);
			subjectService.deleteSubjectById(id);

			JSONObject json = new JSONObject();
			json.put("status", "success");

			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("text/json");
			response.setCharacterEncoding("UTF-8");
			PrintWriter out = response.getWriter();
			out.println(json.toString());
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getSubjectName() {
		return subjectName;
	}

	public void setSubjectName(String subjectName) {
		this.subjectName = subjectName;
	}

	public String getOptionType() {
		return optionType;
	}

	public void setOptionType(String optionType) {
		this.optionType = optionType;
	}

	public int getOptionNum() {
		return optionNum;
	}

	public void setOptionNum(int optionNum) {
		this.optionNum = optionNum;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public ISubjectService getSubjectService() {
		return subjectService;
	}

	public void setSubjectService(ISubjectService subjectService) {
		this.subjectService = subjectService;
	}

	public Subject getSubject() {
		return subject;
	}

	public void setSubject(Subject subject) {
		this.subject = subject;
	}

	public IOptionService getOptionService() {
		return optionService;
	}

	public void setOptionService(IOptionService optionService) {
		this.optionService = optionService;
	}
	
}