




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
搭建课件上传下载及播放文件上传模块前台页面提交文件前台页面验证脚本$(document).ready(function() $(document.form).submit(function() var file = (document.getElementById(file).value; var name = .ppt; if(file.indexOf(name,file.length-4) 0) alert(文件格式不对!请重新选择);return false;return true;););请选择需上传的教学课件(课件格式为PPT):后台上传模块public class AddVideoAction extends ActionSupportprivate static final long serialVersionUID = 1L;private static final int BUFFER_SIZE = 8 *1024;private File uploadFile;private VideoService vs;private String uploadFileFileName;private String uploadFileContentType;public VideoService getVs() return vs;public void setVs(VideoService vs) this.vs = vs;/上传到服务器private static void copy(File src,File dst)tryInputStream in = null;OutputStream os = null;tryin = new BufferedInputStream(new FileInputStream(src);os = new BufferedOutputStream(new FileOutputStream(dst),BUFFER_SIZE);byte buffer = new byteBUFFER_SIZE;while( in.read(buffer) 0)os.write(buffer);finallyif(null != in)in.close();if(null != os)os.close();catch (Exception e)e.printStackTrace();public String execute()throws ExceptionSimpleDateFormat sdf = new SimpleDateFormat(yyyyMMddHHmmss);if(null=ActionContext.getContext().getSession().get(currentAdmin)return login;String fileName = uploadFileFileName;fileName = fileName.replace( ,);String playFileName = sdf.format(new Date()+.flv;File playFile = new File(ServletActionContext.getServletContext().getRealPath(/upload/video/play) + + playFileName);File downloadFile = new File(ServletActionContext.getServletContext().getRealPath(/upload/video/download) + + fileName);copy(uploadFile,downloadFile);copy(uploadFile,playFile);if( 1 = vs.addVideo(downloadFile,playFileName)return SUCCESS;return ERROR;/文件的扩展名public static String getExtention(String fileName)int pos = fileName.lastIndexOf(.);return fileName.substring(pos);public File getUploadFile() return uploadFile;public void setUploadFile(File uploadFile) this.uploadFile = uploadFile;public String getUploadFileFileName() return uploadFileFileName;public void setUploadFileFileName(String uploadFileFileName) this.uploadFileFileName = uploadFileFileName;public String getUploadFileContentType() return uploadFileContentType;public void setUploadFileContentType(String uploadFileContentType) this.uploadFileContentType = uploadFileContentType;文件下载模块文件下载模块public class DownLoadFileAction extends ActionSupportprivate static final long serialVersionUID = 1L;private String fileName;private String type;public String contentType; private VideoService vs ; private PPtService ps; private int id;public int getId() return id;public void setId(int id) this.id = id;public VideoService getVs() return vs;public void setVs(VideoService vs) this.vs = vs;public PPtService getPs() return ps;public void setPs(PPtService ps) this.ps = ps;public InputStream getDownloadFile() if(type.equals(ppt)contentType = application/vnd.ms-powerpoint;return ServletActionContext.getServletContext().getResourceAsStream( /upload/ppt/+getDownLoadChineseFileName();elsecontentType =application/x-shockwave-flash;return ServletActionContext.getServletContext().getResourceAsStream( /upload/video/download/+getDownLoadChineseFileName();public String getDownLoadChineseFileName()String downloadChineseFileName = fileName;trydownloadChineseFileName = new String (downloadChineseFileName.getBytes(ISO8859-1),gbk);System.out.println(downloadChineseFileName);catch(UnsupportedEncodingException e)e.printStackTrace();return downloadChineseFileName;public String execute() throws Exception if(type.equals( ppt)ps.updateDtime(id);elsevs.updateDtime(id);/ServletActionContext.getResponse().setHeader(Content-Disposition,attachment;filename= + getDownLoadChineseFileName();return SUCCESS;public String getFileName() return getDownLoadChineseFileName();public void setFileName(String fileName) this.fileName = fileName;public String getType() return type;public void setType(String type) this.type = type;public void setContentType(String contentType) this.contentType = contentType; public String getContentType() return contentType; 下载的配置文件 $contentTypeattachment;filename=$fileName downloadFile 4096 contentType 指定下载文件的文件类型 application/octet-stream 表示无限制inputName 流对象名 比如这里写inputStream,它就会自动去找Action中的getInputStream方法。contentDisposition 使用经过转码的文件名作为下载文件名 默认格式是attachment;filename=$fileName,将调用该Action中的getFileName方法。bufferSize 下载文件的缓冲大小文件在线播放模块Get the Flash Player to see this rotator.var s1 = new SWFObject(imagerotator.swf,rotator,600,480,8);s1.addParam(allowfullscreen,true);s1.addVariable(file,);s1.addVariable(width,600);s1.addVariable(height,480);s1.addVariable(shuffle,false);s1.addVariable(rotatetime,5);s1.addVariable(icons,true);s1.addVariable(autostart,false);s1.write(container);后台处理PPT模块package com.hbv.service;import java.io.File;import java.text.SimpleDateFormat;import java.util.Date;import java.util.List;import com.hbv.dao.PPtDAO;import com.hbv.model.Focus;import com.hbv.model.PPt;import com.hbv.model.User;import com.opensymphony.xwork2.ActionContext;import java.awt.Dimension;import java.io.BufferedWriter;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.FileReader;import java.io.FileWriter;import java.io.LineNumberReader;import java.awt.Color;import java.awt.Graphics2D;import java.awt.geom.Rectangle2D;import java.awt.image.BufferedImage;import org.apache.poi.hslf.model.TextRun;import org.apache.poi.hslf.usermodel.RichTextRun;import org.apache.poi.hslf.usermodel.SlideShow;import org.apache.struts2.ServletActionContext;public class PPtService private PPtDAO pd;SimpleDateFormat sdf = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);SimpleDateFormat sdff = new SimpleDateFormat(yyyyMMddHHmmss);public PPtDAO getPd() return pd;public void setPd(PPtDAO pd) this.pd = pd;public int addPPt(File file) String pptFile = file.getName().replace(.ppt, );PPt pt = new PPt();pt.setP_title(file.getName();Date date = new Date();pt.setAdd_date(sdf.format(date);pt.setP_url(/upload/ppt/);pt.setClick_time(0);pt.setAdd_author(User) ActionContext.getContext().getSession().get(currentAdmin).getUser_name();try BufferedWriter bw = new BufferedWriter(new FileWriter(ServletActionContext.getServletContext().getRealPath(/upload/ppt_picture)+ + sdff.format(date) + .xml);bw.write();bw.newLine();bw.write();bw.newLine();bw.write(t);bw.newLine();FileInputStream is = new FileInputStream(file);SlideShow ppt = new SlideShow(is);is.close();Dimension pgsize = ppt.getPageSize();org.apache.poi.hslf.model.Slide slide = ppt.getSlides();pt.setP_num(slide.length);for (int i = 0; i slide.length; i+) TextRun truns = slidei.getTextRuns();for (int k = 0; k truns.length; k+) RichTextRun rtruns = trunsk.getRichTextRuns();for (int l = 0; l rtruns.length; l+) rtrunsl.setFontSize(25);rtrunsl.setFontIndex(1);rtrunsl.setFontName(黑体);BufferedImage img = new BufferedImage(pgsize.width,pgsize.height, BufferedImage.TYPE_INT_RGB);Graphics2D graphics = img.createGraphics();int backgroundColor = slidei.getColorScheme().getBackgroundColourRGB();graphics.setPaint(new Color(backgroundColor);graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width + 100,pgsize.height + 200);slidei.getBackground().draw(graphics);slidei.draw(graphics);/生成图片FileOutputStream out = new FileOutputStream(ServletActionContext.getServletContext().getRealPath(/upload/ppt_picture)+ / + sdff.format(date) + (i + 1) + .jpg);javax.imageio.ImageIO.write(img, jpg, out);out.close();bw.write(tt);bw.newLine();bw.write(ttt + sdff.format(date) + (i + 1)+ );bw.newLine();bw.write((liuxiaochun);bw.newLine();bw.write(tttupload/ppt_picture/+ sdff.format(date) + (i + 1) + .jpg);bw.newLine();bw.write(ttt);bw.newLine();bw.write(tt);bw.newLine();bw.write(t);bw.newLine();bw.write();bw.close();if (1 = pd.addPPt(pt);return 1; catch (Exception e) e.printStackTrace();return 0;public List quertPPt() return pd.queryPPt();public List queryPPtByPageNum(long page_num) return pd.queryPPtByPageNum(page_num);public int deletePPt(int id, String title, int num, String name) String jpgPath = ServletActionContext.getServletContext().getRealPath(/upload/ppt_picture/);String pptPath = ServletActionContext.getServletContext().getRealPath(/upload/ppt/);File fil
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 ISO 30414:2025 EN Human resource management - Requirements and recommendations for human capital reporting and disclosure
- 去年初二数学试卷
- 围网灯光施工方案(3篇)
- 亲子小程序活动策划方案(3篇)
- 防冻水管施工方案(3篇)
- 沃尔沃卡车施工方案(3篇)
- 卫浴知识考试题库及答案
- 山东应急考试题库及答案
- 农村现代农业技术服务外包合同
- 企业员工薪酬福利外包服务合同书
- 《慢阻肺健康大课堂》课件
- 三年级 人教版 数学 第六单元《两位数乘一位数(不进位)口算》课件
- 民爆信息系统网络服务平台
- 2024人教版英语七年级下册《Unit 3 Keep Fit How do we keep fit》大单元整体教学设计2022课标
- 2025年度智慧企业ERP系统集成与运维服务合同模板2篇
- 中国高血压防治指南(2024年修订版)
- 2024年优居房产全国加盟手册3篇
- 中广核人才测评题库
- 污水处理工程施工工程组织设计
- 氨基酸作为药物靶点
- 护理深静脉血栓科普
评论
0/150
提交评论