关于webwork点击按钮后下载一文件如何同时跳转到某一页面

双子悠 2014-05-05 06:05:42
在项目中遇到这样一个问题:用POI生成了一个XLS文件,当点击某一页面上的“下载”按钮时,文件下载,同时页面转到另外一个显示结果页面,可是现在的问题是文件可以下载,但无法跳转页面,始终在当前页面。有没有哪位大虾能告诉我一下我到底哪里弄错了,谢谢了~

在xwork.xml中设置跳转页面
<action name="file" class="fileAction">
<result name="viewPage" type="dispatcher">
<param name="location">/main/View.jsp</param>
</result>
<interceptor-ref name="params" />
</action>

Action类fileAction中execute()方法内容如下:
if("printXls".equals(command)) {
printXLS();
return "viewPage";
}

而printXLS()的内容则是:
String fileName=用POI生成一个XLS文件;
int fileLength = 2097152;
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);

File file = new java.io.File(reportFacade.path + File.separator + fileName);
FileInputStream fileIn = new FileInputStream(file);

byte b[] = new byte[fileLength];
long fileLen = file.length();
int readBytes = 0;
int totalRead = 0;
while ( (long) totalRead < fileLen) {
readBytes = fileIn.read(b, 0, 65000);
totalRead += readBytes;
response.getOutputStream().write(b, 0, readBytes);
}
fileIn.close();
jsp页面上的代码是:
<input type="button" class="button" tabindex="8" name="printButton" value=“download” onMouseDown="printReportXls(document.forms[0])">
javascript:
function printReportXls(form) {
form.action="file.action?command=printXls";
form.submit();
}
...全文
83 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧