菜鸟一只,如有错误请谅解,想可以帮助你
1、首先你要知道子zip的存放位置
2、这个zip文件存放的位置要在你部署服务器的tomcat下,不然你访问不到(还有一种方法可以解决文件不再tomcat下),下面会有说明。
public Object download() {
String urlName="";
// String filePath =
// this.queueService.getCsvFilePathById(id);
//所要下载的文件路径,从数据库中查询得到,当然也可以直接写文件路径,
//如:C:\Users\Administrator\Desktop\csv\号码_utf8_100.csv
String id =getParameter(“id”);
String tableId = getParameter(“tableId”);
//获取表名
String tableName = getService(PackageDownloadService.class)
.selectTableId(tableId);
String name =
getService(PackageDownloadService.class).selectByName(id,tableName);
String path = “upload”;
String pName =path+"/"+name+".zip";
try {
urlName = new String(pName.getBytes(“UTF-8”), “ISO8859-1”);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setReturnData(urlName);
return urlName;
path:是tomcat下面一个文件的名字
<%@page import=“org.apache.commons.fileupload.UploadContext”%>
<%@ page import=“com.ces.config.utils.CommonUtil”%>
<%@ page language=“java” contentType=“text/html; charset=UTF-8”
pageEncoding=“UTF-8”%>
<%@ taglib prefix=“ces” tagdir="/WEB-INF/tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + “?/”
+ request.getServerName() + “:” + request.getServerPort()
+ path + “/”;
String basePath1 = request.getScheme() + “?/”
+ request.getServerName() + “:” + request.getServerPort()
+ “/”;
// 统一使用获取id后缀方法
request.setAttribute(“idSuffix”, CommonUtil.generateUIId(""));
request.setAttribute(“id”,request.getParameter(“id”));
request.setAttribute(“tableId”,request.getParameter(“tableId”));
// 获取参数
//request.setAttribute(“name”, request.getParameter(“P_name”));
%>
/*所有js变量或方法写在这个命名空间里面,防止构件与构件之间变量或方法冲突/
jQuery.extend(jQuery.ns(“namespaceKaTeX parse error: Expected '}', got 'EOF' at end of input: …1%>" var url=.contextPath+”/package-download!download.json?id=KaTeX parse error: Expected 'EOF', got '&' at position 5: {id}&̲tableId={tableId}";
$.ajax({
url:url,
type : ‘post’,
dataType : ‘json’,
data : data,
success:function(data){
var path = data
var ul = basePath1+data
alert(ul);
window.open(ul);
}
});
/if(!data.success) {
$.message({message:“警告!下载未完成!”,cls:“warning”});
return;
}*/
/ var form = KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲form{idSuffix}");
form.attr(‘target’,’’);
form.attr(‘method’,‘post’);
form.attr(‘action’,
.
c
o
n
t
e
x
t
P
a
t
h
+
′
/
p
a
c
k
a
g
e
−
d
o
w
n
l
o
a
d
!
d
o
w
n
l
o
a
d
.
j
s
o
n
?
i
d
=
.contextPath +'/package-download!download.json?id=
.contextPath+′/package−download!download.json?id={id}&tableId=${tableId}’);
KaTeX parse error: Expected 'EOF', got '#' at position 3: ('#̲max{idSuffix}’).append(form);
windowns.open(basePath1+data);
form.submit();
form.remove(); */
//CFG_clickCloseButton(KaTeX parse error: Expected 'EOF', got '#' at position 3: ('#̲max{idSuffix}’).data(‘configInfo’));
}
});
// 构件配置信息,每个构件的主页面必须要加上以下这段来初始构件基础配置信息
KaTeX parse error: Expected '}', got 'EOF' at end of input: …y.ns('namespace{idSuffix}’).packDownload();
},
});
});
通过windown.open(url)的方式进行下载,这是浏览器自带的下载方式,方便使用。本人测试过的 可以使用