java 文件下载谷歌可以IE不可以,该如何解决
java 文件下载谷歌可以IE不可以
response.setHeader("Content-type", "application-download");
response.setHeader("Content-disposition", "attachment;filename=" + name);
//response.setContentType("text/html;charset=UTF-8"); //yu add 0723
response.setContentType("application/msword;charset=GBK");
response.setContentType("multipart/form-data");
response.getWriter().write(path+fileName);
运行上述代码谷歌可以自动下载,IE无反应
ie捕捉response.resposeText返回的是乱码
求大神。
------解决方案--------------------
降低IE的安全级别
------解决方案--------------------
这个是我以前自己写的,下载没有问题
------解决方案--------------------
你写了这么多代码 真正有用的只有response.setHeader("Content-disposition", "attachment;filename=" + name);
------解决方案--------------------
都告诉你了 写这句和最后一句 别的都不用
------解决方案--------------------
应该是上面这一句的问题,你把filepath打印出来看看嘛,因为你的路劲不一定是c:\\a\b.png这种形式的
response.setHeader("Content-type", "application-download");
response.setHeader("Content-disposition", "attachment;filename=" + name);
//response.setContentType("text/html;charset=UTF-8"); //yu add 0723
response.setContentType("application/msword;charset=GBK");
response.setContentType("multipart/form-data");
response.getWriter().write(path+fileName);
运行上述代码谷歌可以自动下载,IE无反应
ie捕捉response.resposeText返回的是乱码
求大神。
------解决方案--------------------
降低IE的安全级别
------解决方案--------------------
String filepath=this.getServletContext().getRealPath("/download/云.PNG");
String filename=filepath.substring(filepath.lastIndexOf("\\")+1);
//由于文件名带有中文,但是游览器不支持,所以此时需要编码一下,故使用URLEncoder,英文名或者数字不用转码
response.setHeader("Content-Disposition", "attachment;filename="+URLEncoder.encode(filename,"utf-8"));
InputStream input=new FileInputStream(filepath);
OutputStream out=response.getOutputStream();
byte[] buf=new byte[1024];
int len=0;
while((len=input.read(buf))!=0)
{
out.write(buf, 0, len);
}
input.close();
这个是我以前自己写的,下载没有问题
------解决方案--------------------
你写了这么多代码 真正有用的只有response.setHeader("Content-disposition", "attachment;filename=" + name);
------解决方案--------------------
都告诉你了 写这句和最后一句 别的都不用
------解决方案--------------------
String filepath=this.getServletContext().getRealPath("/download/云.PNG");
String filename=filepath.substring(filepath.lastIndexOf("\\")+1);
//由于文件名带有中文,但是游览器不支持,所以此时需要编码一下,故使用URLEncoder,英文名或者数字不用转码
response.setHeader("Content-Disposition", "attachment;filename="+URLEncoder.encode(filename,"utf-8"));
InputStream input=new FileInputStream(filepath);
OutputStream out=response.getOutputStream();
byte[] buf=new byte[1024];
int len=0;
while((len=input.read(buf))!=0)
{
out.write(buf, 0, len);
}
input.close();
这个是我以前自己写的,下载没有问题
报错:java.lang.ArrayIndexOutOfBoundsException
下标越界。
String filename=filepath.substring(filepath.lastIndexOf("\\")+1);
应该是上面这一句的问题,你把filepath打印出来看看嘛,因为你的路劲不一定是c:\\a\b.png这种形式的