关于 浏览器有关问题【页面导出】 功能的实现
关于 浏览器问题【页面导出】 功能的实现 ?
代码
链接该导出页面。
问题:
ie8以上的不能导出。360浏览器能提示导出。
------解决方案--------------------
采用ie9跟Google都木有问题!
主要是你的newname要确定路径上没有问题!!!
你可以调试或者直接输出看看newname的值!
------解决方案--------------------
楼主把文件路径打印下,
之前我也试过,不同浏览器的路径不一样。。。。
------解决方案--------------------
这个测试下载的是同级目录下的index.jsp页面!
代码
<%@page pageEncoding="UTF-8"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.io.OutputStream"%>
<%@page import="java.io.FileInputStream"%>
<%
String path=null;
try{
String name = request.getParameter("name");
String newname = request.getParameter("fileName");
response.setHeader("Content-disposition", "attachment;filename="
+ new String(name.getBytes("GBK"), "ISO-8859-1"));
response.setContentType("application/x-msdownload");
path = newname;
out.clear(); //添加
out = pageContext.pushBody();//添加
InputStream is = new FileInputStream(path);
OutputStream os = response.getOutputStream();
byte[] bs = new byte[1024];
int len = 0;
while ((len = is.read(bs)) != -1) {
os.write(bs, 0, len);
os.flush();
}
os.close();
is.close();
}catch(Exception e){
e.printStackTrace();
}
%>
链接该导出页面。
问题:
ie8以上的不能导出。360浏览器能提示导出。
------解决方案--------------------
request.setCharacterEncoding("UTF-8"); //防止获取中文乱码
String path=null;
try{
String name = request.getParameter("name");
String newname = request.getParameter("fileName");
response.setHeader("Content-disposition", "attachment;filename="
+ new String(name.getBytes("GBK"), "ISO-8859-1"));
response.setContentType("application/x-msdownload");
path = application.getRealPath("/")+newname;
out.clear(); //添加
out = pageContext.pushBody();//添加
InputStream is = new FileInputStream(path);
OutputStream os = response.getOutputStream();
byte[] bs = new byte[1024];
int len = 0;
while ((len = is.read(bs)) != -1) {
os.write(bs, 0, len);
os.flush();
}
os.close();
is.close();
}catch(Exception e){
e.printStackTrace();
}
采用ie9跟Google都木有问题!
主要是你的newname要确定路径上没有问题!!!
你可以调试或者直接输出看看newname的值!
------解决方案--------------------
楼主把文件路径打印下,
之前我也试过,不同浏览器的路径不一样。。。。
------解决方案--------------------
这个测试下载的是同级目录下的index.jsp页面!