基于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+mysql的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等等。

		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");
	}
	
	public void exportExcel(List<Exam> exams,String filename){
		WritableWorkbook book = null;
        try {
        	String path = ServletActionContext.getServletContext().getRealPath("/temp");

	/**
	 * @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++)
			
			System.out.println(result[i]);
		
		//System.out.println(all.remove(4));
		//System.out.println(all.remove(4));
		System.out.println("********************");
		for(int i=0;i<all.size();i++)
			System.out.println(all.get(i));
			*/
		 WritableWorkbook book = null;
	        try {
	            // 打开文件
	            book = Workbook.createWorkbook(new File("E:/测试.xls"));
	            // 生成名为"学生"的工作表,参数0表示这是第一页
	            WritableSheet sheet = book.createSheet("学生", 0);
	            // 指定单元格位置是第一列第一行(0, 0)以及单元格内容为张三
		this.hibernateTemplate.update(user);
	}

	public void delete(User user) {
		this.hibernateTemplate.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();
		
	
	// **********上传文件*******************
	public String upload() throws Exception{

		InputStream is = new FileInputStream(file);
		String uploadPath = ServletActionContext.getServletContext().getRealPath("/resources");
		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();
		
		System.out.println("tid"+resource.getTeacher().getTid());
		
		resource.setName(fileFileName);
		resourceService.saveResource(resource);
		
		return "upload";
	}
	
	// **********下载文件*******************
	public InputStream getDownloadFile(){
		String filepath="/resources/"+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<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 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);
// 		}
// 	}

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

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

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

	public Admin findById(String aid) {
		return this.hibernateTemplate.get(Admin.class, aid);
	}

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

	public void save(Admin admin) {
		this.hibernateTemplate.save(admin);
	}

		this.fileContentType = fileContentType;
	}
	// **********用于读excel文件*******************
	
	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);
//		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 ThemeAction extends ActionSupport implements ModelDriven<Theme>{
	
	private static final long serialVersionUID=1L;

	private Theme theme = new Theme();

	Student student = new Student();
	public Theme getModel() {
		Theme theme = this.theme;
		theme.setSender(student);
		return this.theme;
	}

	// *****************************
	private ThemeService themeService;
	private ReplyService replyService;
	public void setThemeService(ThemeService themeService) {
		this.themeService = themeService;
	}
	public void setReplyService(ReplyService replyService) {
		this.replyService = replyService;
	}

	public String selectAll() {
		List<Theme> themes = themeService.findAllTheme();
		ActionContext.getContext().put("themes",themes);
		return "selectAll";
	}
	
	public String selectAllForA() {
		List<Theme> themes = themeService.findAllTheme();
		ActionContext.getContext().put("themes",themes);
		return "selectAllForA";
	}
	
	public String adminDelete() {
		themeService.deleteTheme(theme);
		return this.selectAllForA();
	}
	
	public String update(){
		this.themeService.updateTheme(theme);
	public void setQids4(List<Integer> qids4) {
		this.qids4 = qids4;
	}
	public List<String> getAnswers4() {
		return answers4;
	}
	public void setAnswers4(List<String> answers4) {
		this.answers4 = answers4;
	}
	public Integer getCid() {
		return cid;
	}
	public void setCid(Integer cid) {
		this.cid = cid;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}

	private Course course= new Course();

	public Paper getModel() {

		Paper paper = this.paper;
		paper.setCourse(course);
		return paper;
	}
	
	public Integer getQid() {
		return qid;
	}
	public void setQid(Integer qid) {
		this.qid = qid;
	}

	// *****************************
	private PaperService paperService;
	private QuestionService questionService;
	private CourseService courseService;
		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));
			Sheet st = wb.getSheet(0);
			int cols=st.getColumns();
			int rows=st.getRows();
			System.out.println("cols:"+cols+"  rows:"+rows);
			for(int i=1;i<rows;i++){
				String sid=st.getCell(0, i).getContents();
				String password=st.getCell(1, i).getContents();
				String name=st.getCell(2, i).getContents();
				String schoolclass=st.getCell(3, i).getContents();
				String phone=st.getCell(4, i).getContents();
				String email=st.getCell(5, i).getContents();
				students.add(new Student(sid,password,name,schoolclass,phone,email));
			
		List<Teacher> teachers = teacherService.findAllTeacher();
		ActionContext.getContext().put("teachers", teachers);
		return "selectAll";
	}
	
	public String add(){
		teacher.setStatus(1);
		try{
			teacherService.saveTeacher(teacher);
		}catch(Exception e){
			ActionContext.getContext().put("msg","账号已存在,添加失败!");
			return "addError";
		}
		ActionContext.getContext().put("msg","添加成功!");
		return "addSuccess";
	}
	
	public String beforChat() {
		Teacher teacher = teacherService.findTeacherById(this.teacher.getTid());
		
		List<Teacher> teachers = teacherService.findAllTeacher();
		
		Student student = (Student)ActionContext.getContext().getSession().get("student");
		List<Chat> chats = chatService.findChatByTS(teacher.getTid(), student.getSid());
		
		ActionContext.getContext().put("teacher", teacher);
		ActionContext.getContext().put("teachers", teachers);
		ActionContext.getContext().put("chats", chats);
		
		return "beforChat";
	}
	
	public String addChat() {
		Teacher teacher = teacherService.findTeacherById(this.teacher.getTid());
		Student student = (Student)ActionContext.getContext().getSession().get("student");
		
		Chat chat = new Chat();
		chat.setContent(content);
		chat.setStudent(student);
		chat.setTeacher(teacher);
		chat.setDirection(1);
		chat.setTime(new Date());
		chatService.saveChat(chat);
		
		if(teacher.getStatus()==1){
// 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);
// 		}
// 	}

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

@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);
        			</td>
      			</tr>
    			</s:if>
    			
    			<s:elseif test="#request.question.type=='multiple'">
      			<tr>
        			<td align="center">参考答案</td>
        			<td colspan="7">
      	  				<input type="checkbox" name="answer" value="A">&nbsp;A&nbsp;&nbsp;
      	  				<input type="checkbox" name="answer" value="B" >&nbsp;B&nbsp;&nbsp;
      	  				<input type="checkbox" name="answer" value="C" >&nbsp;C&nbsp;&nbsp;
      	  				<input type="checkbox" name="answer" value="D" >&nbsp;D&nbsp;&nbsp;
        			</td>
      			</tr>
    			</s:elseif>
    			
    			<s:elseif test="#request.question.type=='judgment'">
      			<tr>
        			<td align="center">参考答案</td>
        			<td colspan="7">
      	  				<input type="radio" name="answer" value="T" checked>正确
      	  				<input type="radio" name="answer" value="F" >错误
        			</td>
      			</tr>
    			</s:elseif>
    			
    			<s:else>
      			<tr align="center">
        			<td>参考答案</td>
        			<td colspan="7"><textarea name="answer" class="form-control" rows=8>${requestScope.question.answer}</textarea></td>
      			</tr>
    			</s:else>
    			
    			<tr align="center" class="success">
    				<td colspan="8">
      					<input type="hidden" name="qid" value="${requestScope.question.qid}">
      					<input type="hidden" name="type" value="${requestScope.question.type}">
      					<input type="submit" class="btn btn-success" name="update" value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;">
      				</td>
    			</tr>
  			</tbody>
			</table>
		</div>
	</form>
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
	}
	
	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{
		InputStream is = new FileInputStream(file);
		String uploadPath = ServletActionContext.getServletContext().getRealPath("/temp");
		System.out.println(uploadPath);
		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();
		List<Student> students = studentService.getStudentFromExcel(uploadPath+"/"+fileFileName);
		studentService.saveSomeStudent(students);
		File file = new File(uploadPath+"/"+fileFileName);
		//file.delete();

		return "success";
	}
	
	public String beforChat() {
		
		Teacher teacher = (Teacher)ActionContext.getContext().getSession().get("teacher");
		List<Student> students = studentService.findStudentInChat(teacher.getTid());
		if(!students.isEmpty()){
			Student student = students.get(0);
			ActionContext.getContext().put("student", student);
			List<Chat> chats = chatService.findChatByTS(teacher.getTid(), student.getSid());
			ActionContext.getContext().put("chats", chats);
		}
		ActionContext.getContext().put("students", students);
		return "beforChat";
	}
	
 */
// //继承 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);
// 		}
// 	}

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

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

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

	public Teacher findById(String tid) {
		return this.hibernateTemplate.get(Teacher.class, tid);
	}

	public List<Teacher> findAll() {
		return this.hibernateTemplate.find("from Teacher");
	}
	
	public String selectAllForA() {
		List<Theme> themes = themeService.findAllTheme();
		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";
	}
	
	
}


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 getContentType() {
		return ServletActionContext.getServletContext().getMimeType(filename);
	}
	public void setContentType(String contentType) {

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值