ImageVerifierCode 换一换
格式:DOCX , 页数:16 ,大小:20.80KB ,
资源ID:21586288      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/21586288.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(多照片上传插件代码Word格式.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

多照片上传插件代码Word格式.docx

1、 public void init() throws ServletException / 获取本项目所在真实硬盘目录 String path = getClass().getProtectionDomain().getCodeSource() .getLocation().getPath(); path = path.substring(0, path.indexOf(WEB-INF); / 判断目标是否存在,不存在就建立 String uploadDir = path.concat(this.getInitParameter(uploadDir System.out.println(upl

2、oadDir:=+uploadDir); String tempUploadDir = path.concat(this.getInitParameter(tempUploadDirtempUploadDir:+tempUploadDir); File f_uploadDir = new File(uploadDir); File f_tempUploadDir = new File(tempUploadDir); if (!f_uploadDir.exists() f_uploadDir.mkdirs(); f_tempUploadDir.exists() f_tempUploadDir.m

3、kdirs(); / 给变量赋值 this.uploadDir = uploadDir; this.tempUploadDir = tempUploadDir; * see * javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest * , javax.servlet.http.HttpServletResponse) 不接收get方式提交的数据,返回上传失败状态码。 protected void doGet(HttpServletRequest request, HttpServletRespons

4、e response) throws ServletException, IOException this.setResponse(response); PrintWriter out = response.getWriter(); out.print(error:-1); / 非法提交方式 * javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest * , javax.servlet.http.HttpServletResponse) 上传文件请求都是通常POST提交 protected void

5、 doPost(HttpServletRequest request, / 设置响应类型,以便前端解析 String result = try / 检查本次是否一个文件上传请求 boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) DiskFileItemFactory factory = new DiskFileItemFactory(); / 创建一个工厂基于磁盘的文件项 factory.setRepository(new File(tempUploadDir); / 配置

6、储存库(确保安全的临时位置时) ServletFileUpload upload = new ServletFileUpload(factory); / 创建一个新的文件上传处理程序 upload.setSizeMax(1024 * 1024 * 100); / 设置总体要求尺寸限制(建议前后台分别设置,因为前后台用到了不同的插件) List items = upload.parseRequest(request); / 解析请求 Iterator iter = items.iterator(); / 处理上传的项目 while (iter.hasNext() / 如果是一次性上传多个文件,那

7、这里会分别去保存 FileItem item = iter.next(); if (!item.isFormField() / 过滤表单里的非文件类型字段 if (!.equals(item.getName() / 过滤非文件类型的input String s_name = item.getName(); / 获得原始文件名 int position = s_name.lastIndexOf(. String s_fileType = s_name.substring(position, s_name.length(); / 获得文件后缀 String date = new SimpleDat

8、eFormat(yyyyMMdd) .format(new Date(); String s = uploadDir.concat().concat(date) .concat( / 这里按日期分目录保存文件 File sf = new File(s); if (!sf.exists() sf.mkdirs(); String s_filePath = s.concat( UUID.randomUUID().toString().concat( s_fileType); File path = new File(s_filePath); item.write(path); result +=

9、s_filePath.concat(, else result = break; else result = String s_resultJSON = this.jointJSON(result); / 拼接返回前端JSON out.print(s_resultJSON); catch (Exception e) e.printStackTrace(); finally out.flush(); out.close(); /* * 拼接JSON,将保存文件的文件名和日期目录返回给前端(前端可能需要这个路径完成其他表单操作,比如将文件路径存放到数据库) * param result * JSO

10、N格式的字符串 * return * throws UnsupportedEncodingException private String jointJSON(String result) throws UnsupportedEncodingException String str = .equals(result) String rs = result.split( StringBuffer buffer = new StringBuffer(rows for (int i = 0; i rs.length; i+) String s_tmpName = rsi; s_tmpName = s

11、_tmpName.substring(uploadDir.length(), s_tmpName .length(); buffer.append(name).append(s_tmpName).append(, str = buffer.toString(); str = str.substring(0, str.length() - 1).concat( else str = -2 / 上传失败 return str; * 设置响应类型ContentType为application/x-json * param response private void setResponse(HttpS

12、ervletResponse response) response.setCharacterEncoding(UTF-8 response.setContentType(application/json;charset=UTF-8 response.setHeader(cache-control, no-cacheWeb.xml-配置web-app xmlns:xsi=http:/www.w3.org/2001/XMLSchema-instance xmlns= xsi:schemaLocation= id=WebApp_ID version=2.5 sdwelcome-file-listwe

13、lcome-filetest_upload.html/welcome-file-listservletdescription专门用来处理上传操作的servletservlet-nameFileUploadServletservlet-classcom.xiaoxing.upload.FileUploadServletinit-param文件存放的正式目录,可以自己配置uploadDirparam-value/upload/images/init-param文件存放的临时目录,可以自己配置,里的文件由下面配置的监听器自动删除。tempUploadDir/upload/temp DeleteSer

14、vletcom.xiaoxing.upload.DeleteServleturl-pattern/delImg/servlet-mapping/upload临时文件资源清理,工具包自带,不用我们来写mons.fileupload.servlet.FileCleanerCleanup/listener/web-app test_upload.html-前台页面!DOCTYPE htmlhtmlheadmeta charset=GBKtitlejQuery Uploadify + Apache Fileupload异步上传文件示例(2014-5-3)link rel=stylesheet type

15、=text/css href=uploadify.cssscript src=jquery-1.9.0.min.js/scriptjquery.uploadify.min.jsscript type=text/javascript$(function() $(#fileupload).uploadify( method : post,buttonTextflash上传文件fileSizeLimit2048KBfileTypeExts*.gif; *.jpg; *.pngswfuploadify.swfuploaderupload, /这是上传图片的路径,也就是我在web.xml里配置的serv

16、letonUploadSuccess function(file, data, response) /图片上传成功后返回数据在这里处理 var ary = eval( + data + ).rows; var data = $(#data).val()+1; $().val(data); for ( var i = 0; ary.length; $(#J_div).append( div style=position:relative; width:160px; height:200px; float:left; margin-right:10px;div class=close style=

17、absolute; top:8px; right: cursor: pointer;img src=window-close.png/divimg id=acc+data.length+ alt=图片 src=upload/images + aryi.name + width=160px height=200pxdivinput type=hidden name=imges value=.close).click(function() var img = $(this).parent().next().children().val(); $.post(delImg method: img:im

18、g, xml $(this).parent().next().remove(); $(this).parent().remove(); ); ););style type=.img_boxx position:135px; display:inline; padding:0 5px; margin-bottom: .img_boxx span background:#fff; position:0px;5px;15px;block; .img_remove cursor:pointer;/style/headbodyform action=sss.jsp div id=J_div- /form/body/htmlUploadify.css - 样式/*UploadifyCopyright (c) 2012 Reactive Apps, Ronnie GarciaReleased under the MIT License */.uploadify relative; 1em;.uploadify-button background-color: #50

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1