为了账号安全,请及时绑定邮箱和手机立即绑定

代码没有报错,但是点击下载后,页面上没有弹出保存文件的对话框,使用火狐firebug调试,在返回的数据页面右键“在新的标签页中打开”,才会出来

55c706420001ede305000220.jpg

55c70643000119f705000254.jpg

//批量下载高铁作业室的图片,AJAX方式

@RequestMapping(params="method=downloadBoxImages")

public void downloadBoxImages(int id, HttpServletRequest req,HttpServletResponse resp) throws IOException{

List<BoxImages> bi = this.boxInfoService.getBoxImages(id);

resp.setContentType("application/x-msdownload");

resp.setHeader("Content-Disposition", "attachment;filename=pictures.zip");

String path = getServletcontext().getRealPath("/");

String rootpath = path.substring(0, (path.length()-4)) + "gjx_uploadfile\\";

int len = bi.size();

String[] filenames = new String[len];

for (int i = 0; i < len; i ++)

{

filenames[i] = bi.get(i).getImage_path();

}

String str = "";

String rt = "\r\n";

ZipOutputStream zos = new ZipOutputStream(resp.getOutputStream());

for(String filename : filenames){

str += filename + rt;

File file = new File(rootpath + filename);

zos.putNextEntry(new ZipEntry(filename));

FileInputStream fis = new FileInputStream(file);

byte b[] = new byte[1024];

int n = 0;

while((n = fis.read(b)) != -1){

zos.write(b, 0, n);

}

zos.flush();

fis.close();

}

zos.setComment("download success:" + rt + str);

zos.flush();

zos.close();

}


正在回答

4 回答

同学您好,请问您链接jquery库了吗?

ucloeydhhcdrwktinysqjyiplar

0 回复 有任何疑惑可以回复我~

哈哈,代码中关闭默认打开方式就可以了

0 回复 有任何疑惑可以回复我~

前台jsp页面配action了吗?

0 回复 有任何疑惑可以回复我~

放了半天没人解决,自己解决了,给自己个好评吧

1 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

代码没有报错,但是点击下载后,页面上没有弹出保存文件的对话框,使用火狐firebug调试,在返回的数据页面右键“在新的标签页中打开”,才会出来

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信