It's not a secret anymore!*
The moose likes Servlets and the fly likes getWriter() has already been called for this response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "getWriter() has already been called for this response" Watch "getWriter() has already been called for this response" New topic

getWriter() has already been called for this response

Markus Schmider
Ranch Hand

Joined: Feb 25, 2007
Posts: 100

I am trying to implement a servlet which returns xml after an example from Eben Hewitt: Java SOA Cookbook.
However I get an exception
WARNUNG: StandardWrapperValve[SimpleRestServlet]: PWC1406: Servlet.service() for servlet SimpleRestServlet threw exception
at de.pox.servlets.SimpleRestServlet.processRequest(
at de.pox.servlets.SimpleRestServlet.doGet(
at javax.servlet.http.HttpServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.StandardWrapper.service(

And I cannot figure out why.
Tested on glassfish 3.1 and JBoss 6.

Any help would be greatly appreciated.

Matthew Brown

Joined: Apr 06, 2010
Posts: 4343

You can't call both getWriter() and getOutputStream() on the same response object, because they use the same underlying stream.

So you'll have to get rid of one of the calls. That doesn't look too hard, as you aren't really using the Writer for anything.
It is sorta covered in the JavaRanch Style Guide.
subject: getWriter() has already been called for this response
Similar Threads
Exception executing servlet with database connectivity
Session tracking with URL rewriting
org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException: 8
not able to insert values in ms access database
Hello world ejb3 problem