grails文件下载
来源:互联网 发布:矩阵求导链式法则 编辑:程序博客网 时间:2024/05/20 23:55
1.后台controller代码
- /**
- * 文件下载
- */
- def fileDownload = {
- def filePath = params.filePath //文件路径
- def fileName = encode(params.fileName) //文件名
- response.setHeader("Content-disposition", "attachment; filename=" + fileName)
- response.contentType = "application/x-rarx-rar-compressed"
- def out = response.outputStream
- def inputStream = new FileInputStream(filePath)
- byte[] buffer = new byte[1024]
- int i = -1
- while ((i = inputStream.read(buffer)) != -1) {
- out.write(buffer, 0, i)
- }
- out.flush()
- out.close()
- inputStream.close()
- }
- /**
- * 字符编码
- */
- final def encode(String value,String charSet='UTF-8'){
- java.net.URLEncoder.encode(value, charSet)
- }
2.前端gsp
- /**
- *下载
- */
- function download(m,f){
- //检查文件是否存在
- var checkurl ="${contextPath}/fileUpload/checkFileExists?filePath="+encodeURIComponent(f);
- j.ajax({
- url:checkurl,
- async:false,
- success:function (dt) {
- json = eval('('+dt+')');
- if(json.success){
- var url= "${contextPath}/fileUpload/fileDownload?filePath="+encodeURIComponent(f)+"&fileName="+encodeURIComponent(m);
- window.open(url);
- return false;
- }else{
- alert(json.msg);
- }
- }
- });
- }
阅读全文
0 0
- grails文件下载
- grails文件下载
- grails 文件的上传和下载
- IntelliJ IDEA 工具grails实现多个文件压缩下载
- Grails附件下载
- Grails 下载与安装
- grails上传文件
- grails文件上传
- Grails 文件上传
- grails文件上传
- grails学习笔记-文件上传
- grails项目中导出文件
- The.Definitive.Guide.to.Grails下载
- Grails中文件的上传和下载
- grails lib下载任意版本的地址
- Grails的下载、安装以及配置
- grails
- grails
- HDU_P1176免费馅饼
- C++实验6-项目2
- 离散题目16
- 第三本书 apache
- TensorFlow MNIST TensorBoard版本
- grails文件下载
- 随机发牌
- 套接字与文件描述符
- HTTP请求格式和HTTP响应理解
- jQuery选择器之元素选择器
- 126自动化发邮件
- grails文件上传
- awesome-visual-slam
- 求字符串中重复字符的最大间隔