首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

Cannot forward after response has been committed

2014-01-26 
异常信息:Cannot forward after response has been committed原代码: public ActionForward execute(Action

异常信息:Cannot forward after response has been committed

原代码:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
String strFileName = request.getParameter( "fujian ");
System.out.println(strFileName);
String filepath=request.getRealPath( "/ ");
File file = new File(filepath+ "/fujian/ " + strFileName);//
if(file.exists()){
try{
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
byte[] buffer = new byte[1024];
strFileName = java.net.URLEncoder.encode(strFileName, "UTF-8 ");//处理中文文件名的问题
strFileName = new String(strFileName.getBytes( "UTF-8 "), "GBK ");//处理中文文件名的问题
response.reset();
response.setCharacterEncoding( "UTF-8 ");
response.setContentType( "application/x-rar-compressed ");//不同类型的文件对应不同的MIME类型
response.setHeader( "Content-Disposition ", "attachment; filename= "+strFileName);
OutputStream os = response.getOutputStream();
while(bis.read(buffer) > 0){
os.write(buffer);
}
bis.close();
os.close();
return mapping.findForward( "suc ");

}
catch(Exception e){
return mapping.findForward( "fail ");
}
}else{
return mapping.findForward( "fail ");

}
请问Cannot forward after response has been committed是什么原因?

------解决方法--------------------------------------------------------
当文件下载框弹出来之后,应该不能再转向了,你 return null 吧,不知道大家有没好的办法
------解决方法--------------------------------------------------------
在response完成之后,不能forward。你就要检查一下forward之前代码
------解决方法--------------------------------------------------------
Cannot forward after response
看看你的struts_config.xml的配置有没有fail的

        

热点排行