You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by red phoenix <ro...@gmail.com> on 2008/12/10 17:26:49 UTC
getOutputStream() has already been called for this response
I use struts2.0.11,I want to show a picture by struts action,like follows:
public String showphoto() throws Exception{
response=ServletActionContext.getResponse();
response.setContentType("image/png");
...
InputStream in = picture.getBinaryStream();
OutputStream out = response.getOutputStream();
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) != -1){
out.write(buf, 0, len);
}
in.close();
out.close();
response.flushBuffer();
return SUCCESS;
}
When I run above code,it can run well,and it can show picture in jsp,but I
find it write error information in tomcat6,like follows:
fatal: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called
for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:610)
at
org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
at
javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
Why raise above error in tomcat6? How to correct my code to correct above
error?
Thanks in advance!
Re: getOutputStream() has already been called for this response
Posted by Dave Newton <ne...@yahoo.com>.
When you return SUCCESS you're asking S2 to process the response normally. I'd assume you'd need to return null to indicate that S2 shouldn't do anything.
I don't actually know if that works, because there's a stream result type designed specifically for this situation.
Dave
--- On Wed, 12/10/08, red phoenix <ro...@gmail.com> wrote:
> From: red phoenix <ro...@gmail.com>
> Subject: getOutputStream() has already been called for this response
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Date: Wednesday, December 10, 2008, 11:26 AM
> I use struts2.0.11,I want to show a picture by struts
> action,like follows:
> public String showphoto() throws Exception{
> response=ServletActionContext.getResponse();
> response.setContentType("image/png");
> ...
> InputStream in = picture.getBinaryStream();
> OutputStream out = response.getOutputStream();
> byte[] buf = new byte[1024];
> int len;
> while ((len = in.read(buf)) != -1){
> out.write(buf, 0, len);
> }
> in.close();
> out.close();
> response.flushBuffer();
> return SUCCESS;
> }
>
> When I run above code,it can run well,and it can show
> picture in jsp,but I
> find it write error information in tomcat6,like follows:
> fatal: Servlet.service() for servlet jsp threw exception
> java.lang.IllegalStateException: getOutputStream() has
> already been called
> for this response
> at
> org.apache.catalina.connector.Response.getWriter(Response.java:610)
> at
> org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
> at
> javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
> at
> org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
>
> Why raise above error in tomcat6? How to correct my code to
> correct above
> error?
> Thanks in advance!
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org