【原创随笔】jqUploader jsp开发事例
2012-01-18 14:56
323 查看
1,访问http://www.pixeline.be/experiments/jqUploader/下载jquery.jqUploader.1.0.2.3.zip,解压文件夹至项目中
其中的php文件及demo.html、style.css可删除,不会影响功能
2,将
<script src="js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.jqUploader.1.0.2.3/jquery.flash.js"></script>
<script type="text/javascript" src="js/jquery.jqUploader.1.0.2.3/jquery.jqUploader.js"></script>
导入到jsp文件中,配置jqUploader
配置结果:
3,服务端如果没用struts2可自行获取,如果用struts2的朋友,因为struts2对文件表单会进行再次封装,所以用阿帕奇的文件获取方式是不行的,只能用struts2自己的文件获取方式来获取,即声明File对象及setter和getter,效果如下
4,
其中的php文件及demo.html、style.css可删除,不会影响功能
2,将
<script src="js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.jqUploader.1.0.2.3/jquery.flash.js"></script>
<script type="text/javascript" src="js/jquery.jqUploader.1.0.2.3/jquery.jqUploader.js"></script>
导入到jsp文件中,配置jqUploader
$(document).ready(function() { $('#example1').jqUploader({ debug:0 //debug模式,1为开启 ,background:'' //背景色 ,barColor:'FFDD00'//进度条颜色 ,maxFileSize: '1048576' //允许文件大小 ,src:'js/jquery.jqUploader.1.0.2.3/jqUploader.swf' //swf位置 ,allowedExt:'*.avi; *.jpg; *.jpeg; *.png' //允许格式 ,allowedExtDescr: '*.avi; *.jpg; *.jpeg; *.png' //选择窗格式描述 ,validFileMessage: '' //验证文件的描述 ,endMessage: 'and don\'t you come back ;)' ,hideSubmit: false ,endMessage:'上传成功' //成功后的描述 ,uploadScript:'upload!upload' //提交的服务端action }); });
<span id="example1"> <label for="example1_field" > Choose a file to upload: </label> <input name="file" id="example1_field" type="file" /> </span>
配置结果:
3,服务端如果没用struts2可自行获取,如果用struts2的朋友,因为struts2对文件表单会进行再次封装,所以用阿帕奇的文件获取方式是不行的,只能用struts2自己的文件获取方式来获取,即声明File对象及setter和getter,效果如下
private File filedata; private String filename; public void setFiledata(File filedata) { this.filedata = filedata; } public File getFiledata() { return filedata; } public void setFilename(String filename) { this.filename = filename; } public String getFilename() { return filename; }
4,
public String upload() { try { String fileBasePath = ServletActionContext.getServletContext().getRealPath("/upload") + "\\complaint\\"; String newName = ""; if (filedata != null && filedata.length() > 0) { String type = filename.substring(filename.lastIndexOf("."), filename.length()); newName = UUID.randomUUID().toString() + type; File path = new File(fileBasePath); if (!path.exists()) { path.mkdirs(); } path = null; File outFile = new File(fileBasePath, newName); if (!outFile.exists()) { outFile.createNewFile(); } FileInputStream in = new FileInputStream(filedata); FileOutputStream out = new FileOutputStream(outFile); byte[] bts = new byte[1024]; while ((in.read(bts)) != -1) { out.write(bts); } in.close(); out.flush(); out.close(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
相关文章推荐
- Flex组件开发总结(aierong原创技术随笔)
- jsp结合ajax开发grid,免费原创控件
- Flex组件开发总结(aierong原创技术随笔)
- 开发:随笔记录之 HTML 弹出透明层事例
- [原创]Eclipse3.0.1+Lomboz3.0.1+EMF2.0.1+Tomcat 5.0.30 JSP开发环境搭建实战记录
- 开发:随笔记录之 HTML 弹出透明层事例
- S2jsp 动态网页开发基础 web服务器
- JSP第二章知识点总结——开发模式
- 使用JSP开发WebMail系统
- jsp(java)开发微信公众平台入门
- Windows下JSP开发环境的配置
- jsp开发环境配置整理
- 利用Dreamweaver开发JSP的方法
- eclipse开发jsp环境的插件
- JSP页面如何调用到.class文件【原创】
- javaWeb 使用jsp开发 foreach 标签
- 原创:struts2+json+android整合开发解析前奏
- myeclipse 8.5 +tomcat 6.x+jdk 搭建 jsp 开发环境简记
- Android软件开发随笔笔记第一讲
- unity3D游戏开发实战原创视频讲座系列6之生死逃亡游戏开发