response.setContentType("application/x-msdownload");
response.setHeader("Content-disposition","attachment; filename="+new String(zipFileName.getBytes("gbk"),"iso8859-1"));在写完以上代码后,我想用跳转到另一个界面上输出错误信息
request.setAttribute("showmessage",ErrorMessage);
RequestDispatcher requestDisPatcher = request.getRequestDispatcher("dwsdcbqk.jsp");
requestDisPatcher.forward(request,response);ECLIPS提示Cannot forward after response has been committed。
如何破?
{
String zipFileName="";
//生成压缩包
if (dcfs.equals("1"))
{
zipFileName="(" + gdsh + ")"+new String(gdsmc.getBytes("iso-8859-1"), "GBK")+"("+cbyf+")抄表数据(已抄).zip";
FileZip.getInstance().zip(dbfPath, zipdownPath+"\\"+zipFileName);
}
else
{
zipFileName="(" + cbqbh + ")"+new String(cbqmc.getBytes("iso-8859-1"), "GBK")+"抄表器("+cbyf+")抄表数据(已抄).zip";
FileZip.getInstance().zip(dbfPath, zipdownPath+"\\"+zipFileName);
} //////////////////////以文件流形式返回压缩文件供下载////////////////////////
response.setContentType("application/x-msdownload");
response.setHeader("Content-disposition","attachment; filename="+new String(zipFileName.getBytes("gbk"),"iso8859-1"));
//
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream(zipdownPath+"\\"+zipFileName));
// 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);
} } catch(final IOException e) {
ErrorMessage=e.getMessage().replace("\n","\\n").replace("\r","\\r").replace("\"", "");
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
} /////////////////////////////////////////////////////////////
} request.setAttribute("showmessage",ErrorMessage);
RequestDispatcher requestDisPatcher = request.getRequestDispatcher("dwsdcbqk.jsp");
requestDisPatcher.forward(request,response);
我把代码贴出来吧,可以肯定的是,问题就出在此代码块中