360安全浏览器版体为:3.2正式版
下载代码为:private HttpServletResponse downLoadFun(HttpServletRequest request,
HttpServletResponse response,String filepath){
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
OutputStream fos = null;
InputStream fis = null;
try{
//如果是从服务器上取就用这个获得系统的绝对路径方法。 String filepath = servlet.getServletContext().getRealPath("/" + path);
//String filepath=path;
//System.out.println("文件路径"+filepath);
File uploadFile = new File(filepath);
fis = new FileInputStream(uploadFile);
bis = new BufferedInputStream(fis);
fos = response.getOutputStream();
bos = new BufferedOutputStream(fos);
//这个就就是弹出下载对话框的关键代码
response.setCharacterEncoding("GBK");
response.setContentType( "application/octet-stream ");
response.setHeader("Content-disposition",
"attachment;filename=" +
URLEncoder.encode(filepath, "utf-8"));
int bytesRead = 0;
//这个地方的同上传的一样。我就不多说了,都是用输入流进行先读,然后用输出流去写,唯一不同的是我用的是缓冲输入输出流
byte[] buffer = new byte[8192];
while ((bytesRead = bis.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.flush();
fos.flush();
return response;
}catch(Exception ex){
ex.printStackTrace();
return response;
}finally{
try{
if (fis != null){
fis.close();
}
if (bis != null){
bis.close();
}
if (fos != null){
fos.close();
}
if (bos != null){
bos.close();
}
}catch(Exception exf){
exf.printStackTrace();
}
}
}
下载代码为:private HttpServletResponse downLoadFun(HttpServletRequest request,
HttpServletResponse response,String filepath){
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
OutputStream fos = null;
InputStream fis = null;
try{
//如果是从服务器上取就用这个获得系统的绝对路径方法。 String filepath = servlet.getServletContext().getRealPath("/" + path);
//String filepath=path;
//System.out.println("文件路径"+filepath);
File uploadFile = new File(filepath);
fis = new FileInputStream(uploadFile);
bis = new BufferedInputStream(fis);
fos = response.getOutputStream();
bos = new BufferedOutputStream(fos);
//这个就就是弹出下载对话框的关键代码
response.setCharacterEncoding("GBK");
response.setContentType( "application/octet-stream ");
response.setHeader("Content-disposition",
"attachment;filename=" +
URLEncoder.encode(filepath, "utf-8"));
int bytesRead = 0;
//这个地方的同上传的一样。我就不多说了,都是用输入流进行先读,然后用输出流去写,唯一不同的是我用的是缓冲输入输出流
byte[] buffer = new byte[8192];
while ((bytesRead = bis.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.flush();
fos.flush();
return response;
}catch(Exception ex){
ex.printStackTrace();
return response;
}finally{
try{
if (fis != null){
fis.close();
}
if (bis != null){
bis.close();
}
if (fos != null){
fos.close();
}
if (bos != null){
bos.close();
}
}catch(Exception exf){
exf.printStackTrace();
}
}
}
解决方案 »
- java不能做高端产品吗?请看截图!
- 项目初期设计的问题
- 关于SpringMVC的问题
- 两个类 当个类运行正常 连起来方法调用 就报异常 一个类中 有个sleep(6000) 就是线程方法
- 如何用java开发短信收发的软件了?
- 在网站中怎样用jsp代码写的效果如下:
- ajax 报异常 java.lang.IllegalStateException: getOutputStream() has already been called for this response
- 刚在c#那边转过来,想学java,不知要注意些什么.
- 谁知道这个错误怎么解决 javax.transaction.xa.XAException: 违反协议
- java servlet例子怎么调试啊?
- 关于交互模式
- 请教个问题,hibernate持久化类是否必须要有一个主键? 为什么呢?
第一种:
response.setCharacterEncoding("UTF-8");response.setHeader("Content-Disposition", "attachment; filename="+new String(jkjyfj.getFileName().getBytes("gb2312"),"ISO8859-1"));response.setContentType("application/msexcel");// 定义
第二种:
response.setContentType("application/x-msdownload");
String s = "attachment; filename=" + new String(jkjyfj.getFileName().getBytes("gb2312"),"ISO8859-1"); response.setHeader("Content-Disposition", s); // 以上输出文件元信息
response.setContentLength((int) filesize);
因为浏览器的差别会使我们的代码量加大
第一种在360中可以实现下载但是在最原始的ie中不能实现
第二种在原始额度ie中可是显示,但是在360等浏览器中不能实现