下载文件的时候报错!!!
response这个对象是Servlet自己管理的,之所以出现上面的错误:
1.网上都说跟Output之类其他的输出流相互排斥了。
2.也可能是多次调用那个Struts里面定义的方法。
3.最后查出原因:Struts方法之间调用引起的。
因为:每个方法都返回的是一个ActionForward对象,而response是ActionForward对象参数,所以就会使response冲突!
例如:
public AcitionForward AAA(HttpServletResponse response){
BBB();
return mapping.findForward(".....");
}
//下载操作
public ActionForward BBB(HttpServletResponse response){
.....
return mapping.findward("....");//返回一个ActionForward对象
}
上面写会报错,这么写就不会了!
public AcitionForward AAA(HttpServletResponse response){
if(null == BBB()){//加一个判断
return null;
}
}
//下载操作(凡是用到response的操作)
public ActionForward BBB(HttpServletResponse response){
.....
return null;//必须返回一个NULL
}
突破点:response这个封装的对象里面有个useingOutputStream标志,boolean型 所以就是根据这个来查getOutputStream()是否重复调用的
分享到:
相关推荐
在Java Web开发中,"getOutputStream() has already been called for this response" 是一个常见的错误,通常出现在使用Servlet或JSP时。这个错误意味着在HTTP响应中,`getOutputStream()`已经被调用,然后尝试再次...
1.在tomcat6.0下jsp出现getOutputStream() has already been called for this response异常的原因和解决方法 在tomcat6.0下jsp中出现此错误一般都是在jsp中使用了输出流(如输出图片验证码,文件下载等),没有...
验证码出现getOutputStream() has already been called for this response错误解决
纠结了半天的 java.lang.IllegalStateException: getOutputStream() has already。这个问题困扰了半天,在网上查阅了大量资料 出这个错误一般就是下面2个.....
解决了getOutputStream() has already been called for this response. 并将产生验证码的逻辑从JSP页面中分离出来,单独写了一个类 便于重用。
Returns a boolean indicating whether the named response header has already been set. contextDestroyed(ServletContextEvent) - Method in interface javax.servlet.ServletContextListener Notification ...