当前位置: 技术问答>java相关
如何解决文件下载和页面迁移之间的矛盾
来源: 互联网 发布时间:2017-04-23
本文导语: 我有一个Servlet,希望它在实现文件下载后,迁移到一指定画面,代码如下 /////////////// download /////////////// response.setHeader("Content-Disposition", "attachment;filename=" + "PrjSlip.xls"); response.setHeader("Connection", "close"); response.setHeader("...
我有一个Servlet,希望它在实现文件下载后,迁移到一指定画面,代码如下
/////////////// download ///////////////
response.setHeader("Content-Disposition", "attachment;filename=" + "PrjSlip.xls");
response.setHeader("Connection", "close");
response.setHeader("Content-Type", "application/octet-stream");
// open file input stream
File f = new File(CmResource.PRJ_SLIP);
java.io.FileInputStream fileIn = new java.io.FileInputStream(f);
// write output stream
int i;
ServletOutputStream sos = response.getOutputStream();
int i_length = fileIn.available();
byte buf_l[] = new byte[i_length];
while( i_length > 0) {
fileIn.read(buf_l);
sos.write(buf_l);
i_length = fileIn.available();
}
sos.close();
/////////////// move page ///////////////
RequestDispatcher d = request.getRequestDispatcher(CmResource.GL001GM001);
d.forward(request,response);
实际的运行效果是,最后两行的页面迁移无效,
如何解决这个问题,请高手帮帮忙,谢谢了!
/////////////// download ///////////////
response.setHeader("Content-Disposition", "attachment;filename=" + "PrjSlip.xls");
response.setHeader("Connection", "close");
response.setHeader("Content-Type", "application/octet-stream");
// open file input stream
File f = new File(CmResource.PRJ_SLIP);
java.io.FileInputStream fileIn = new java.io.FileInputStream(f);
// write output stream
int i;
ServletOutputStream sos = response.getOutputStream();
int i_length = fileIn.available();
byte buf_l[] = new byte[i_length];
while( i_length > 0) {
fileIn.read(buf_l);
sos.write(buf_l);
i_length = fileIn.available();
}
sos.close();
/////////////// move page ///////////////
RequestDispatcher d = request.getRequestDispatcher(CmResource.GL001GM001);
d.forward(request,response);
实际的运行效果是,最后两行的页面迁移无效,
如何解决这个问题,请高手帮帮忙,谢谢了!
|
request.sendRedirect("*.jsp");