基于javaweb+mysql的ssh课程资源教学在线考试平台(java+ssh+mysql+jsp+tomcat)

基于javaweb+mysql的ssh课程资源教学在线考试平台(java+ssh+mysql+jsp+tomcat)

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

基于javaweb的SSH课程资源教学在线考试平台(java+ssh+mysql+jsp+tomcat)

一、项目简述

功能包括: 管理员可以增删改查教材、教材商、入库教材、用户(用 户包括学生和教师)可以对教材商、教材进行。xcel的导入 导出操作。教师可以领取入库的教材,可以退还教材。学 生只能在对应的教师那里领取教材,并且可以退还教材、 查询自己已经领取的教材。并且对已领教材付款等等。

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP +Struts+Spring+Hibernate + html+ css + JavaScript + JQuery + Ajax等等。

					alert("选项C不能为空!!");
					f.option3.focus();
					return false;
				}
				if(f.option4.value==""){
					alert("选项D不能为空!!");
					f.option4.focus();
					return false;
				}
			}
			if(f.answer.value==""){
				alert("答案不能为空!!");
				f.answer.focus();
				return false;
			}	
			if(course.value==""){
				alert("请选择所属课程!");
				return false;
			}
			if(f.difficulty.value==""){
				alert("请选择试题难度!");
				return false;
			}
			return true;
		}
		function init(){
			var type = "${requestScope.question.type}";
			var typename = document.getElementById("typename");
			switch(type){
    			case "single":
    				typename.innerHTML="单选题";
    				break;
    			case "multiple":
    				typename.innerHTML="多选题";
    				break;
    			case "judgment":
    				typename.innerHTML="判断题";
    				break;
    			default:
    				typename.innerHTML="解答题";
    				break;
    		}
		}
    </script>

  </head>
  
  <body onload="init();">
    <form action="questionAction_update" method="post" role="form" onSubmit="return checkForm(this)">
    	<div style="width:1000;margin:20">
		chat.setTeacher(teacher);
		chat.setDirection(2);
		chat.setTime(new Date());
		chatService.saveChat(chat);
		
		if(student.getStatus()==1){
			SystemMail.sendMail(student.getEmail(), teacher.getName(), student.getName(), 2);
		}
		
		List<Student> students = studentService.findStudentInChat(teacher.getTid());
		List<Chat> chats = chatService.findChatByTS(teacher.getTid(), student.getSid());
		
		ActionContext.getContext().put("student", student);
		ActionContext.getContext().put("students", students);
		ActionContext.getContext().put("chats", chats);
		
		return "beforChat";
	}
}
/**
 * 使用hibernate.cfg.xml
 */
//public class UserDaoImpl implements UserDao {
//	// 提供hibernate模板
//	private HibernateTemplate hibernateTemplate;
//	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
//		this.hibernateTemplate = hibernateTemplate;
//	}
//	public User findById(Integer id) {
//		return this.hibernateTemplate.get(User.class, id);
//	}
//	public List<User> findAll() {
//		return this.hibernateTemplate.find("from User");
//	}
//	public void save(User user) {
//		this.hibernateTemplate.save(user);
//	}
//	public void update(User user) {
//		this.hibernateTemplate.update(user);
//	}
		ActionContext.getContext().put("themes",themes);
		return "selectAllForA";
	}
	
	public String adminDelete() {
		themeService.deleteTheme(theme);
		return this.selectAllForA();
	}
	
	public String update(){
		this.themeService.updateTheme(theme);
		return "success";
	}
	
	public String delete(){
		themeService.deleteTheme(theme);
		List<Theme> themes = themeService.findAllTheme();
		ActionContext.getContext().put("themes", themes);
		return "selectAll";
	}
	
	public String add(){
		theme.setReplies(0);
		theme.setSendtime(new Date());
		themeService.saveTheme(theme);
		List<Theme> themes = themeService.findAllTheme();
		ActionContext.getContext().put("themes",themes);
		return "selectAll";
	}
	
	public String showTheme(){
		Theme theme = themeService.findThemeById(this.theme.getThid());
		List<Reply> replys = replyService.findReplyByThid(this.theme.getThid());
		ActionContext.getContext().put("theme1", theme);
		ActionContext.getContext().put("replys", replys);
		return "showTheme";
	}
	
	
}

			}	
			if(course.value==""){
				alert("请选择所属课程!");
				return false;
			}
			if(f.difficulty.value==""){
				alert("请选择试题难度!");
				return false;
			}
			return true;
		}
		function init(){
			var type = "${requestScope.type}";
			var typename = document.getElementById("typename");
			switch(type){
    			case "single":
    				typename.innerHTML="单选题";
    				break;
    			case "multiple":
    				typename.innerHTML="多选题";
    				break;
    			case "judgment":
    				typename.innerHTML="判断题";
    				break;
    			default:
    				typename.innerHTML="解答题";
    				break;
    		}
		}
    </script>

  </head>
  
  <body onload="init();">
    <form action="questionAction_add" method="post" role="form" onSubmit="return checkForm(this)">
    	<div style="width:1000;margin:20">
			<table class="table table-bordered table-hover">
			<thead>
    			<tr align="center">
    				<td colspan="6" class="success"><h3>添加试题信息</h3></td>
    			</tr>
    		</thead>
 	 		<tbody>
    			<tr align="center">
      				<td class="active">试题描述</td>
     				<td colspan="5"><input type="text" name="description" class="form-control"></td>
    			</tr>
    			<tr class="active" align="center">
      				<td width=100>题型</td>
      				<td id="typename" align="center" width=100>
      				
      				</td>
      				<td width=100>所属课程</td>

public class ExamAction extends ActionSupport implements ModelDriven<Exam>{
	
	private static final long serialVersionUID=1L;

	private Exam exam = new Exam();
	
	private List<Integer> scores_m = new ArrayList<Integer>();

	public List<Integer> getScores_m() {
		return scores_m;
	}

	public void setScores_m(List<Integer> scores_m) {
		this.scores_m = scores_m;
	}

	Paper paper = new Paper();
	Student student = new Student();
	public Exam getModel() {
		Exam exam = this.exam;
		exam.setPaper(paper);
		exam.setStudent(student);
		return exam;
	}

	// ***********用于导出excel*********
	private String filename;
	private String contentType;

	public String getFilename() throws IOException{
		return encodeDownloadFilename(filename,ServletActionContext.getRequest().getHeader("User-Agent"));
	}
	public void setFilename(String filename) throws UnsupportedEncodingException{
		filename = new String(filename.getBytes("iso-8859-1"),"utf-8");
		this.filename = filename;
	}
    }

    // **********上传文件*******************
    public String upload() throws Exception {

        InputStream is = new FileInputStream(file);
        String uploadPath = ServletActionContext.getServletContext().getRealPath("/homeworks");
        File toFile = new File(uploadPath, this.getFileFileName());
        OutputStream os = new FileOutputStream(toFile);
        byte[] buffer = new byte[1024];
        int length = 0;
        while (-1 != (length = is.read(buffer, 0, buffer.length))) {
            os.write(buffer);
        }
        is.close();
        os.close();

        homework.setName(fileFileName);
        homeworkService.saveHomework(homework);

        return "upload";
    }

    // **********下载文件*******************
    public InputStream getDownloadFile() {
        String filepath = "/homeworks/" + filename;
        return ServletActionContext.getServletContext().getResourceAsStream(filepath);
    }

    public String encodeDownloadFilename(String name, String agent) throws IOException {
        if (agent.contains("Firefox")) {
            name = "=?UTF-8?B?" + new BASE64Encoder().encode(name.getBytes("utf-8")) + "?=";
        } else {
            name = URLEncoder.encode(name, "utf-8");
        }
        return name;

    }

    // *****************************
    public String selectAll() {
        List<Homework> homeworks = homeworkService.findAllHomework();
        ActionContext.getContext().put("homeworks", homeworks);
        return "selectAll";
    }

    public String beforeUpdate() {
        Homework homework = homeworkService.findHomeworkById(this.homework.getHid());
        ActionContext.getContext().put("homework", homework);
		return "logoff";
	}
}

/**
 * 使用hibernate.cfg.xml
 */
//public class UserDaoImpl implements UserDao {
//	// 提供hibernate模板
//	private HibernateTemplate hibernateTemplate;
//	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
//		this.hibernateTemplate = hibernateTemplate;
//	}
//	public User findById(Integer id) {
//		return this.hibernateTemplate.get(User.class, id);
//	}
//	public List<User> findAll() {
//		return this.hibernateTemplate.find("from User");
//	}
//	public void save(User user) {
//		this.hibernateTemplate.save(user);
//	}
//	public void update(User user) {
//		this.hibernateTemplate.update(user);
//	}
//	public void delete(User user) {
//		this.hibernateTemplate.delete(user);
//	}
//}
/**
 * 不使用hibernate.cfg.xml
 */
// //继承 HibernateDaoSupport自动生成模板, 必须提供SessionFactory
// public class UserDaoImpl extends HibernateDaoSupport implements UserDao {
// 	public User findById(Integer id) {
// 		return this.getHibernateTemplate().get(User.class, id);
// 		}
public class StudentDaoImpl implements StudentDao {
	// 提供hibernate模板
	private HibernateTemplate hibernateTemplate;
	

	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public Student findById(String sid) {
		return this.hibernateTemplate.get(Student.class, sid);
	}

	public List<Student> findAll() {
		return this.hibernateTemplate.find("from Student");
	}

	public void save(Student student) {
		this.hibernateTemplate.save(student);
	}

	public void update(Student student) {
		this.hibernateTemplate.update(student);
	}

	public void delete(Student student) {
		this.hibernateTemplate.delete(student);
	}
	
	public List<Student> findInChat(String tid){
		Configuration config=new Configuration().configure(); 
		SessionFactory sessionFactory=config.buildSessionFactory();
		Session session = sessionFactory.openSession();
	    Transaction t = session.beginTransaction();
	    Query query=session.createSQLQuery("select * from student s where exists(select * from chat c where s.sid=c.sid and c.tid=?)").addEntity(Student.class);
	    query.setString(0, tid);
	    List<Student> students=query.list();
	    t.commit();
	    session.close();
	    sessionFactory.close();
	    return students;
		
	}
	
	public List<Student> getFromExcel(String file){
		List<Student> students = new ArrayList<Student>();
		
		try{
			Workbook wb = Workbook.getWorkbook(new File(file));
	    t.commit();
	    session.close();
	    sessionFactory.close();
	    return questions;
		
	}
}

public class ResourceAction extends ActionSupport implements ModelDriven<Resource>{
	
	private static final long serialVersionUID=1L;
	
	private Resource resource = new Resource();

	private Teacher teacher = new Teacher();
	public Resource getModel() {
		Resource resource = this.resource;
		resource.setTeacher(teacher);
		return resource;
	}
	
	// **********用于上传文件*******************
	private File file;
	private String fileFileName;
	private String fileContentType;
	
	public File getFile() {
		return file;
	}
			name="=?UTF-8?B?"+new BASE64Encoder().encode(name.getBytes("utf-8"))+"?=";
		}
		else{
			name=URLEncoder.encode(name,"utf-8");
		}
		return name;
		
	}
	
	// *****************************
	public String selectAll() {
		List<Resource> resources = resourceService.findAllResource();
		ActionContext.getContext().put("resources",resources);
		return "selectAll";
	}
	
	public String beforeUpdate(){
		Resource resource = resourceService.findResourceById(this.resource.getRid());
		ActionContext.getContext().put("resource", resource);
		return "beforeUpdate";
	}
	
	public String update(){
		this.resourceService.updateResource(resource);
		return "success";
	}
	
	public String delete(){
		resourceService.deleteResource(resource);
		List<Resource> resources = resourceService.findAllResource();
		ActionContext.getContext().put("resources", resources);
		return "selectAll";
	}
	
	public String add(){
		resourceService.saveResource(resource);
		return "success";
	}
	
	
}

		}
		return students;
	}
	
	public void saveSome(List<Student> students) {
		System.out.println("cols:"+students.size());
		for(int i=0;i<students.size();i++){
			this.hibernateTemplate.save(students.get(i));
		}
	}
}

@Repository
public class QuestionDaoImpl implements QuestionDao {
	
	private HibernateTemplate hibernateTemplate;
	
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public Question findById(Integer qid) {
		return this.hibernateTemplate.get(Question.class, qid);
	}

	public List<Question> findAll() {
		return this.hibernateTemplate.find("from Question");
	}

	public void save(Question question) {
		this.hibernateTemplate.save(question);
	}

	public void update(Question question) {
	

	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public Exam findById(Integer cid) {
		return this.hibernateTemplate.get(Exam.class, cid);
	}

	public List<Exam> findAll() {
		return this.hibernateTemplate.find("from Exam where status=3");
	}

	public void save(Exam exam) {
		this.hibernateTemplate.save(exam);
	}

	public void update(Exam exam) {
		this.hibernateTemplate.update(exam);
	}

	public void delete(Exam exam) {
		this.hibernateTemplate.delete(exam);
	}
	
	public List<Exam> findBySid(String sid) {
		return this.hibernateTemplate.find("from Exam where student.sid=? and status=3",sid);
	}
	
	public List<Exam> findByPid(Integer pid) {
		return this.hibernateTemplate.find("from Exam where paper.pid=? and status=3",pid);
	}
	
	public Exam findBySP(String sid,Integer pid) {
		Configuration config=new Configuration().configure(); 
		SessionFactory sessionFactory=config.buildSessionFactory();
		Session session = sessionFactory.openSession();
	    Transaction t = session.beginTransaction();
	    Query query=session.createQuery("from Exam where student.sid=? and paper.pid=?");
	    query.setString(0, sid);
	    query.setInteger(1, pid);
	    List<Exam> exams=query.list();
	    t.commit();
	    session.close();
	    sessionFactory.close();
	    return exams.get(0);
	}
	
	public List<Exam> findUntreated() {
		return this.hibernateTemplate.find("from Exam where status=2");
			<table class="table table-bordered table-hover">
			<thead>
    			<tr align="center">
    				<td colspan="6" class="success"><h3>添加试题信息</h3></td>
    			</tr>
    		</thead>
 	 		<tbody>
    			<tr align="center">
      				<td class="active">试题描述</td>
     				<td colspan="5"><input type="text" name="description" class="form-control"></td>
    			</tr>
    			<tr class="active" align="center">
      				<td width=100>题型</td>
      				<td id="typename" align="center" width=100>
      				
      				</td>
      				<td width=100>所属课程</td>
     				<td width=200>
      					<select name="course.cid" id="course" class="form-control">
  		  					<s:iterator value="#request.courses" var="course">
            					<option value="${course.cid}">${course.name}
          					</s:iterator>
  	    				</select>
     				</td>
     				<td width=100>难度等级</td>
      				<td width=200>    	
  						<select name="difficulty" class="form-control">
            				<option value="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            				<option value="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            				<option value="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  	    				</select>
      				</td>
    			</tr>
    			
    			<s:if test="#type=='single'||#type=='multiple'">
   				<tr align="center">
        			<td class="active">选项A</td>
        			<td colspan="5"><input type="text" name="option1" class="form-control"></td>
      			</tr>
      			<tr align="center">
        			<td class="active">选项B</td>
        			<td colspan="5"><input type="text" name="option2" class="form-control"></td>
// 			return this.getHibernateTemplate().find("from User");
// 		}
// 		public void save(User user) {
// 			this.getHibernateTemplate().save(user);
// 		}
// 		public void update(User user) {
// 			this.getHibernateTemplate().update(user);
// 		}
// 		public void delete(User user) {
// 			this.getHibernateTemplate().delete(user);
// 		}
// 	}

/**
 * 使用注解方式
 */

@Repository
public class StudentDaoImpl implements StudentDao {
	// 提供hibernate模板
	private HibernateTemplate hibernateTemplate;
	

	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public Student findById(String sid) {
		return this.hibernateTemplate.get(Student.class, sid);
	}

	public List<Student> findAll() {
		return this.hibernateTemplate.find("from Student");
	}

	public void save(Student student) {
//		this.hibernateTemplate = hibernateTemplate;
//	}
//	public User findById(Integer id) {
//		return this.hibernateTemplate.get(User.class, id);
//	}
//	public List<User> findAll() {
//		return this.hibernateTemplate.find("from User");
//	}
//	public void save(User user) {
//		this.hibernateTemplate.save(user);
//	}
//	public void update(User user) {
//		this.hibernateTemplate.update(user);
//	}
//	public void delete(User user) {
//		this.hibernateTemplate.delete(user);
//	}
//}
/**
 * 不使用hibernate.cfg.xml
 */
// //继承 HibernateDaoSupport自动生成模板, 必须提供SessionFactory
// public class UserDaoImpl extends HibernateDaoSupport implements UserDao {
// 	public User findById(Integer id) {
// 		return this.getHibernateTemplate().get(User.class, id);
// 		}
// 		public List<User> findAll() {
// 			return this.getHibernateTemplate().find("from User");
// 		}
// 		public void save(User user) {
// 			this.getHibernateTemplate().save(user);
// 		}
// 		public void update(User user) {
// 			this.getHibernateTemplate().update(user);
// 		}
// 		public void delete(User user) {
// 			this.getHibernateTemplate().delete(user);
// 		}
// 	}

/**
 * 使用注解方式
 */

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//User user = new User();
		//user.setUsername("fuck");
		//user.setPassword("1234");
		//String xmlPath = "applicationContext.xml";
		//ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
		//		xmlPath);
		//UserService userService = applicationContext.getBean("userService",
		//		UserService.class);
		//userService.saveUser(user);
		/*
		List<Integer> all = new ArrayList<Integer>();//m取10,n取5;
		for(int i=0;i<5;i++)
			all.add(i);
		
		Integer j = 5;
		Integer[] result = new Integer[5];
		Random random = new Random();
		
		for(int i=0;i<5;i++)
			result[i] =all.remove(random.nextInt(j--));
			
		
		for(int i=0;i<5;i++)
	
	private Student student = new Student();

	public Student getModel() {
		return this.student;
	}

	// *****************************
	private StudentService studentService;
	private ChatService chatService;
	public void setStudentService(StudentService studentService) {
		this.studentService = studentService;
	}
	public void setChatService(ChatService chatService) {
		this.chatService = chatService;
	}
	
	public String selectAll() {
		List<Student> students = studentService.findAllStudent();
		ActionContext.getContext().put("students",students);
		return "selectAll";
	}
	
	public String beforeUpdate(){
		Student student = studentService.findStudentById(this.student.getSid());
		ActionContext.getContext().put("student", student);
		return "beforeUpdate";
	}
	
	public String update(){
		this.studentService.updateStudent(student);
		return "success";
	}
	
	public String delete(){
		studentService.deleteStudent(student);
		List<Student> students = studentService.findAllStudent();
		ActionContext.getContext().put("students", students);
		return "selectAll";
	}
	
	public String add(){
		student.setStatus(1);
		try{
			this.studentService.saveStudent(student);
		}catch(Exception e){
			ActionContext.getContext().put("msg","账号已存在,添加失败!");
			return "addError";
		}
		ActionContext.getContext().put("msg","添加成功!");
		return "addSuccess";
	}
	
	public String read() throws Exception{

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

  • 16
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
javaweb是一种以Java为基础的web开发技术,它包括了servlet、jsp等相关技术。servlet是JavaEE规范中的一种组件,它主要用于处理用户发送的HTTP请求和返回HTTP响应。servlet可以接收前端页面传来的数据,然后对数据进行处理并返回给前端页面。mysql是一种关系型数据库管理系统,它能够存储大量的数据并提供有效的数据管理和查询功能。在javaweb开发中,我们可以通过servlet来连接mysql数据库,从而实现数据的持久化存储和操作。 jsp是一种基于Java的动态网页开发技术,它可以将Java代码嵌入到HTML页面中,从而实现动态页面的生成和展示。jsp可以使用Java代码来获取数据库中的数据并将其显示在前端页面上,实现了前后端的数据交互。 service是一种用于实现业务逻辑的组件或类,它负责处理具体的业务功能。在javaweb开发中,我们可以将业务逻辑封装在service中,然后在servlet中调用相应的service方法,实现对数据的处理和操作。 考试中无框架要求表示不可以使用现成的框架或库来完成开发任务,需要手动编写相关代码。在考试中,可以考察学生对javaweb技术的理解和应用能力,要求学生能够熟练地使用servlet、jsp等相关技术,并能够编写出符合需求的代码。此外,对于数据库操作,学生还需要了解mysql的基本操作和相关的jdbc编程技巧。 总而言之,javaweb servlet mysql jsp service的考试是考察学生对javaweb开发技术的掌握程度和应用能力的一种考试形式,学生需要熟练地使用这些技术,并能够灵活运用到实际的开发场景中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值