FormFile file = uploadFile.getFile();
String uuidName = UUID.randomUUID().toString();
String video_Name = uuidName+file.getFileName();
String video_Time = uploadFile.getVideo_Time();
System.out.println("时间="+video_Time);
ServletContext servletContext = this.getServlet().getServletContext();
String path = servletContext.getRealPath("");
FileOutputStream out = new FileOutputStream(path+"/uploadV/"+video_Name);
out.write(file.getFileData());
out.flush();
out.close();
UpLoadManager ulm = new UpLoadManager();
boolean flag = ulm.videoAdd(video_Name, video_Time);
if(flag){
request.setAttribute("currentTime", new Date());
request.setAttribute("upload", "success");
return mapping.findForward("upload");
}
request.setAttribute("upload", "fail");
return mapping.findForward("AuploadV");
path表示得到当前项目下webRoot 的路径,为了保存视频,在webRoot下建立了一个名为uploadV的文件夹,把视频保存在tomcat服务器下。同时为避免出现相同文件名的视频名字,每个视频上传之前在视频名前加了一段唯一的UUID字符编码,对应数据可存入tb_video表中的video_Name字段,将来在显示视频的详细信息时同样根据video_Name来寻找视频。
学生下载视频,用video_Name查找下载视频。下载视频的代码如下:
UpLoadForm ulf = (UpLoadForm)form;
String video_Name = ulf.getVideo_Name();
video_Name = new String(video_Name.getBytes("ISO-8859-1"),"GB18030");
ServletContext servletContext = this.getServlet().getServletContext();
String path = servletContext.getRealPath("");
FileInputStream inPut = new FileInputStream(path+"/uploadV/"+video_Name);
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=" + new String(video_Name.getBytes("GB18030"),"ISO-8859-1"));
OutputStream out = response.getOutputStream();
byte[] b = new byte[1024*1024];
while(inPut.read(b)>0){
out.write(b);
out.flush();
}
inPut.close();
out.close();
教师可以根据video_Name删除某些视频,调用delVideo()方法将相关信息删除。关键代码如下:
UpLoadForm ulf = (UpLoadForm)form;
String video_Name = ulf.getVideo_Name();
ServletContext servletContext = this.getServlet().getServletContext();
String path = servletContext.getRealPath("");
File filename = new File(path+"/uploadV/"+video_Name);
filename.delete();
UpLoadManager um = new UpLoadManager();
boolean flag = um.delVideo(video_Name);
6.2.7 作业管理模块本模块在学生用户的主页是学生将自己的作业上传到服务器下的uploadT文件夹中,还可以下载老师批改后上传的作业。在教师用户的主页中老师将学生上传的作业下载下来,之后再将批改好的作业上传到服务器中,供学生下载。上传作业与上传视频类似,只不过多了个String user_name = uploadFile.getUser_name();用来收集上传试卷的用户名。关键代码如下:
UpLoadForm uploadFile = (UpLoadForm)form;
FormFile file = uploadFile.getFile();
String test_Name = file.getFileName();
String test_Time = uploadFile.getTest_Time();
String user_name = uploadFile.getUser_name();
System.out.println("时间="+test_Time);
ServletContext servletContext = this.getServlet().getServletContext();
String path = servletContext.getRealPath("");
FileOutputStream outPut = new FileOutputStream(path+"/uploadT/"+file.getFileName());
outPut.write(file.getFileData());
outPut.flush();
outPut.close();
UpLoadManager ulm = new UpLoadManager();
boolean flag = ulm.testAdd(test_Name, test_Time,user_name);
学生上传作业页面如图6-8所示:
图6-8学生上传作业页面
6.2.8 在线答疑模块在这个模块中学生和教师可以在线交流,学生可以向老师在线提出问题,老师将在线回答。
学生或者教师将说的话发送,将先存到数据中,随之再将数据库中的后20条记录取出,在message.jsp中显示。在线答疑页面的主要代码如下:
<frameset rows="*" cols="*,250" framespacing="1" frameborder="yes" bordercolor="#99ffff" >
<frameset rows="*,117" cols="*" framespacing="0" frameborder="yes">
<frame src="message.jsp" frameborder="1">
<frame src="control.jsp" frameb