jsp文件下载相关代码
2011-08-08 00:05
429 查看
function mydownload(filename, downloadlocation){ var downloadform = document.createElement("FORM"); document.body.appendChild(downloadform); downloadform.method = "post"; createNewFormElement(downloadform, "filename", filename); createNewFormElement(downloadform, "downloadlocation", downloadlocation); downloadform.action = "<%=base %>/downloadAction.do"; downloadform.target = "_self"; downloadform.submit(); } function createNewFormElement(inputForm, elementName, elementValue) { var newElement = document.createElement("input"); newElement.setAttribute("name",elementName); newElement.setAttribute("type","hidden"); newElement.setAttribute("value",elementValue); inputForm.appendChild(newElement); return newElement; }
FileInputStream fis = null; OutputStream ops = null; try { fis = new FileInputStream(downloadlocation); reponse.reset(); reponse.setContentType("application/x-download"); reponse.setHeader("Content-Disposition", "attachment;filename=" + filename); ops = reponse.getOutputStream(); byte[] buffer = new byte[1024]; int count = 0; while((count = fis.read(buffer)) > 0){ ops.write(buffer, 0, count); } ops.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally{ if(fis != null){ try { fis.close(); } catch (IOException e) { e.printStackTrace(); } } if(ops != null){ try { ops.close(); } catch (IOException e) { e.printStackTrace(); } } }
界面及后台相关代码--
相关文章推荐
- jsp文件下载功能实现代码
- jsp文件上传与下载实例代码
- Jsp下载文件 一段代码
- JSP 文件 下载 代码 (不使用 jsp smart upload 组件) 解决中文名 问题
- JSP 文件下载的相对完整代码(解决中文问题和Weblogic报错)
- JSP 多个文件打包下载代码
- JSP文件下载代码示例
- jsp实现文件下载的代码(通过文件流方式)
- 自己动手写中文分词解析器完整教程,并对出现的问题进行探讨和解决(附完整c#代码和相关dll文件、txt文件下载)
- JSP 多个文件打包下载代码
- jsp文件上传与下载实例代码
- jsp+servlet用底层代码实现文件上传下载
- jsp文件的上传和下载操作代码
- JSP 文件下载的相对完整代码(解决中文问题和Weblogic报错)
- java+jsp代码实现从FTP服务器上传下载文件
- php 文件下载的相关代码 兼容所有浏览器
- JSP基本功 pageContext对象page,request,session,application四个域对象的使用及区别JSP运行原理和九大隐式对象及下载文件、访问次数的代码总结出el表达式简单
- JSP实现文件下载代码
- jsp 文件下载示例代码