Heim  >  Artikel  >  Web-Frontend  >  showModelDialog弹出文件下载窗口的使用示例_jquery

showModelDialog弹出文件下载窗口的使用示例_jquery

WBOY
WBOYOriginal
2016-05-16 17:14:11955Durchsuche

当点击我要修改时,需要在后台生成excel文件,同时需要提供下载文件功能。
生成excel文件容易、弹出”文件下载”也容易:
点击按钮,跳转到action中,在该action中生成Excel文件,填充数据,保存到临时文件夹中,然后在按钮的Click事件中,根据模板生成Excel报表,填充数据,保存到临时文件夹,然后output.wirte()。一切看起来很顺利。
Action如下(弹出"文件下载"窗口):

复制代码 代码如下:

/**
*@paramresponse
*@paramdownloadFile
*/
privatevoidclientResponse(HttpServletResponseresponse,FiledownloadFile,StringfileName){
try{
response.reset();
response.setContentType("application/octet-stream");

//用来弹出保存窗口,设置为attachment
response.setHeader("Content-Disposition","attachment;filename="+newString(fileName.getBytes(),"ISO-8859-1"));
InputStreaminput=newFileInputStream(downloadFile);
OutputStreamoutput=response.getOutputStream();
intc;
//读取流并写入到文件中
while((c=input.read())!=-1){
output.write(c);
}
output.flush();
output.close();
input.close();
}catch(Exceptione){
}
}

但是当测试的时候,发现我点击”我要修改”按钮,总是会弹出一个新的窗口。百度一下,加了这段:,这个表示在当前页打开页面。
如下:
base:为页面上的所有链接规定默认地址或默认目标
target:跳转到的目标页





这个问题解决了,但是新的问题又来了,就是文件不可以下载。所以我有没有那种方法既可以在本页打开,又可以提供下载呢?想到了iframe框架。我们可以设置一个看不见的iframe框架,然后target=iframName就可以解决了。

复制代码 代码如下:



位于之间
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn