ntext.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 upl
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>