我在servlet中用如下设置输出word文档后,我发现response.sendRedirect("http://www.126.com");无效了。有什么解决办法么?我希望在导出Word文档后跳转到一个新页面中File file = new File(expfilepath);
FileInputStream is = new FileInputStream(file);
BufferedInputStream bis = null;BufferedOutputStream bos = null;// 保存本地文件名
int fileSize = (int) file.length();
String filename = URLEncoder.encode(expfilename, "UTF-8"); //中文文件名(乱码)转换
// 设置下载文件使用的报头域
response.reset();
response.setContentType("application/msword");
response.setHeader("Content-Disposition", "attachment; filename="+ filename);
response.setContentLength(fileSize);
// 得到响应对象的输出流,用于向客户端输出二进制数据
ServletOutputStream sos = response.getOutputStream();
bis = new BufferedInputStream(is);bos = new BufferedOutputStream(response.getOutputStream());byte[] buff = new byte[2048];int bytesRead;while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) { bos.write(buff, 0, bytesRead);
}bos.flush();
bos.close();
bis.close();//这里执行了但是没有效果
response.sendRedirect("http://www.126.com");
FileInputStream is = new FileInputStream(file);
BufferedInputStream bis = null;BufferedOutputStream bos = null;// 保存本地文件名
int fileSize = (int) file.length();
String filename = URLEncoder.encode(expfilename, "UTF-8"); //中文文件名(乱码)转换
// 设置下载文件使用的报头域
response.reset();
response.setContentType("application/msword");
response.setHeader("Content-Disposition", "attachment; filename="+ filename);
response.setContentLength(fileSize);
// 得到响应对象的输出流,用于向客户端输出二进制数据
ServletOutputStream sos = response.getOutputStream();
bis = new BufferedInputStream(is);bos = new BufferedOutputStream(response.getOutputStream());byte[] buff = new byte[2048];int bytesRead;while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) { bos.write(buff, 0, bytesRead);
}bos.flush();
bos.close();
bis.close();//这里执行了但是没有效果
response.sendRedirect("http://www.126.com");
解决方案 »
- 用myeclipse导入别人的工程不能运行(菜鸟问题)
- httpclient能指定访问网站的IP么
- struts2+jquery ajax做分页
- 关于Quartz的版权问题
- 有没有比较热情的JAVA WEB 初学者的群?
- 如何跨窗体操作??
- 如何保证将WORD文档从数据库中提取出来,修改后,仍能够保存到原数据库中
- 高分请教邮件系统(javamail)问题
- 用JSP页面发邮件的一个菜问题
- ★高分请教一个简单问题,关于JSP连接SQLServer2000★
- spring-modules-validation验证框架多个form使用同一个类的问题
- 不用struts标签如何取得struts国际化资源文件中的值
可是response.getOutputStream()是向客户端输出word文档的必须语句,这样该如何进行页面跳转?(跳转页面的目的是刷新调用servlet的页面,以上代码是在一个servlet中执行的)
或者能给我一个向客户端输出word文档后刷新调用页面的方式。谢谢