下载EXCEL文件没反应,请大家帮忙看一下

问题描述

StringfilePath=request.getSession().getServletContext().getRealPath("/upload/loanExcel/维保订单.xls");StringfileName=filePath.substring(filePath.lastIndexOf("\")+1);//得到文件名Filefile=newFile(filePath);if(file.exists()){ServletOutputStreamout=response.getOutputStream();response.reset();response.setContentType("application/x-download");//设置为下载application/x-download//response.addHeader("Content-Disposition","attachment;filename="+URLEncoder.encode(fileName,"UTF-8"));response.setHeader("Content-Disposition","attachment;filename="+URLEncoder.encode(fileName,"UTF-8"));BufferedInputStreambis=null;BufferedOutputStreambos=null;try{bis=newBufferedInputStream(newFileInputStream(filePath));bos=newBufferedOutputStream(out);byte[]buff=newbyte[8192];intbytesRead;while(-1!=(bytesRead=bis.read(buff,0,buff.length))){bos.write(buff,0,bytesRead);}bos.flush();}catch(IOExceptione){throwe;}finally{if(bis!=null)bis.close();if(bos!=null)bos.close();}}

解决方案

解决方案二:
需要用"window.location.href"这种get请求方式请求下载方法
解决方案三:
打断点跟踪一下代码,看代码走到哪一步了走完bos.flush();这一步,客户端应该出现弹出框代码走完,服务器断开与客户端的tcp连接时,客户端开始解析下载文件如果断点没走到后台,那就检查下请求下载的方式,看是否请求方式有问题
解决方案四:
你确认进到后台了?换个浏览器试试?
解决方案五:
一楼说的对,不能用ajax等方式去请求,这样是不会弹出框的~~~
解决方案六:
其实你都设置下载流了,直接用response.getOutputStream得到outputStream然后在这里面写入就可以了1.你到tomcat下面看看文件生成没有2.如果没有生成文件就是你的写入有问题3.如果你生成了下载的文件那就是你没有弹出框建议使用OutputStreamout=response.getOutputStream();response.reset();response.setHeader("content-disposition","attachment;filename=demo.xls");response.setContentType("application/msexcel");WritableWorkbookwwb=WritableWorkSheet.createWorkBook(out);WritableSheetsheet=wwb.createSheet("123",0);//写入数据out.flush();out.close();

我以前也遇到过,我是用的是window.location.hrefajax的方法结果不可以ajax没试过不知道可以不
解决方案七:
//将文件存到指定位置(服务器)Stringpath=ConstanData.LOAD_EXCEL;try{Filefile=newFile(path);if(!file.getParentFile().exists()){file.mkdirs();}path=path+"维保订单.xls";Filefile2=newFile(path);FileOutputStreamfout=newFileOutputStream(file2);wb.write(fout);fout.close();DownloadTooldownloadtool=newDownloadTool();response=ServletActionContext.getResponse();request=ServletActionContext.getRequest();//downloadtool.resetResponse(request,response,path);downloadtool.download(request,response,path);//downloadtool.download2(file2,response);}catch(Exceptione){e.printStackTrace();}//从服务器下载文件到本地机器publicvoiddownload(HttpServletRequestrequest,HttpServletResponseresponse,Stringlocation){try{StringfileName=location.substring(location.lastIndexOf("\")+1);//得到文件名Filefile=newFile(location);if(file.exists()){ServletOutputStreamout=response.getOutputStream();response.reset();response.setContentType("application/x-download");//设置为下载application/x-downloadfileName=newString(fileName.getBytes("GBK"),"ISO-8859-1");//response.addHeader("Content-Disposition","attachment;filename="+URLEncoder.encode(fileName,"UTF-8"));response.setHeader("Content-Disposition","attachment;filename="+fileName.substring(fileName.lastIndexOf("/")+1,fileName.length()));BufferedInputStreambis=null;BufferedOutputStreambos=null;try{bis=newBufferedInputStream(newFileInputStream(location));bos=newBufferedOutputStream(out);byte[]buff=newbyte[10240];intbytesRead;while(-1!=(bytesRead=bis.read(buff))){bos.write(buff);}bos.flush();}catch(IOExceptione){throwe;}finally{if(bis!=null)bis.close();if(bos!=null)bos.close();}}}catch(FileNotFoundExceptione){e.printStackTrace();}catch(IOExceptione){e.printStackTrace();}}
解决方案八:
http://download.csdn.net/detail/u013112641/7375585看这个吧

时间: 2024-07-30 10:07:13

下载EXCEL文件没反应,请大家帮忙看一下的相关文章

我调用excel 打开jsp页面,jsp代码打开会出现下载excel文件 ,怎么控制excel 打印时为默认为横向

问题描述 我调用excel打开jsp页面,jsp代码打开会出现下载excel文件,怎么控制excel打印时为默认为横向

xml-XML文件问题,请大神看下并帮忙解释下,感激不尽

问题描述 XML文件问题,请大神看下并帮忙解释下,感激不尽 XML文件问题,下边两段bean代码,我新手不理解,请大神看下并帮忙解释下,感激不尽 <bean id="dingDanDengJiDao" class="com.sysgrrj.module.DingDanDengJi.dao.DingDanDengJiDao"> <property name="sessionFactory"> <ref bean=&qu

struts2-struts.xml文件报错了,求帮忙看一下!!!

问题描述 struts.xml文件报错了,求帮忙看一下!!! <?xml version=""1.0"" encoding=""UTF-8""?><!DOCTYPE struts PUBLIC ""-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"" http://struts.apache.

new-新手求教 请大家帮忙看下源码

问题描述 新手求教 请大家帮忙看下源码 ------------------------DAL------------------------------------------------------------public List select(int UserID) { //初始化数据库连接对象 DateAccessLaye dbmyfile = new DateAccessLaye(); //初始化myfilemodel对象的集合实例 DataTable dsmf = dbmyfile

数据-SQLSERVER存储过程,请各位帮忙看一下

问题描述 SQLSERVER存储过程,请各位帮忙看一下 第一条SQL语句执行没有数据则执行第二条SQL语句,第二条SQL语句没有数据则执行第三条语句 下面是SQL语句 第一句 select * into #TemPoraryBgoods from ( select distinct a.company,a.code,a.name,b.hyprice,a.comeFrom,finish=ISNULL(a.finish,''),c.smallfanwei, dbo.GetDistancefromLn

java-这两种写法有什么差别???请大家帮忙看一看

问题描述 这两种写法有什么差别???请大家帮忙看一看 public void getBenjin() { if (null != benjin.getText()) { benjinD = Double.parseDouble(benjin.getText().toString()); } } public void getLilv() { if (null != lilv.getText()) { lilvD = Double.parseDouble(lilv.getText().toStri

c++/cli-C++ 加载 CTP DLL 报 LNK2001 错误,请大家帮忙看下,这个问题已经困扰几天了

问题描述 C++ 加载 CTP DLL 报 LNK2001 错误,请大家帮忙看下,这个问题已经困扰几天了 有个问题困扰我几天了,群里的大牛帮忙看下. 我加载ctp的dll时,会报下面这个错误. 谁知道原因,或者之前遇到过吗? 解决方案 删除所有的obj,重新编译下,检查下你的lib目录,对应的lib是否齐全.如果程序是自己写的,那么检查下函数的定义和调用是否一致. 解决方案二: 你需要工程中添加ctp的lib库文件.这样link才找得到.

c++新手,请大家帮忙看一看代码哪错了

问题描述 c++新手,请大家帮忙看一看代码哪错了 要求:用户输入一段话,输出每个单词出现的次数如输入:hello my friend . I miss you my friend输出:单词 次数 hello 1 my 2 friend 2 I 1 miss 1 you 1 #include #include #include using namespace std; int main(){ string sen;//用来记录用户输入的句子string word[100];int ab;int t

jvm-tomcat自动挂掉,在tomcat/bin/hs_err_pid4884.log如下,请高手帮忙看下。

问题描述 tomcat自动挂掉,在tomcat/bin/hs_err_pid4884.log如下,请高手帮忙看下. # A fatal error has been detected by the Java Runtime Environment: # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c95a1db, pid=5424, tid=2752 # JRE version: 6.0_45-b06 Java VM: Java HotSpo