Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ERROR: Cannot set header. Response already committed

843841Oct 31 2003 — edited Oct 31 2003
Hello world
in a servlet I'm processing a forward :
getServletConfig().getServletContext().getRequestDispatcher("page.jsp").forward(request, response);
and then in the same servlet i'm wrinting in the output stream:
strResult="hello";
ServletOutputStream servOutputStream;			
byte[] bytRetorno=strResult.getBytes();
response.setContentType("text/plain");
servOutputStream =response.getOutputStream();	
servOutputStream.write(bytRetorno);
servOutputStream.close();
when I execute that servlet I've got the following error message:

Error Message: ERROR: Cannot set header. Response already committed.
Error Code: 500
Target Servlet: null
Error Stack:
java.lang.IllegalStateException: ERROR: Cannot set header. Response already committed.
at com.ibm.servlet.engine.srt.SRTServletResponse.setHeader(SRTServletResponse.java:476)
at com.ibm.servlet.engine.srt.SRTServletResponse.setContentType(SRTServletResponse.java:438)
at com.ibm.servlet.engine.webapp.HttpServletResponseProxy.setContentType


Can somebody help me with that please, I want to keep the two actions (forward and writing in the servlet outputstream).

Thanks.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 28 2003
Added on Oct 31 2003
1 comment
617 views