Demo servlet rejects "java.lang.IllegalStateException: STREAM" when invoking resp.getWriter()

3,489 views
Skip to first unread message

6real

unread,
Sep 10, 2009, 3:02:38 AM9/10/09
to Google Web Toolkit
Dear all,

I met an issue with my servlets, then I try the demo servlet given by
Google :

-------
import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse
resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, world");
}
}
--------

And I still raise an exception when invoking the method getWriter :

java.lang.IllegalStateException: STREAM
at org.mortbay.jetty.Response.getWriter(Response.java:583)
at .....

Can anyone help me ? Is there a workaround ?

For information my environment is :
- Mac OS X 10.5.6
- I downgraded my default JVM to the JAVA 5 32 bits version (else I
couln't launch GWT app in hosted mode ...).

Thanks for your help.

C.

Sri

unread,
Sep 11, 2009, 1:38:15 AM9/11/09
to Google Web Toolkit
I am guessing its because you have already opened the stream by
calling the resp.setContentType("text/plain"); method, and are then
trying to get a Writer object. You can either use Stream based
classes, or Writer based classes - not both.

Either remove the setContentType(), or send the response using
response.getOutputStream() method. That should solve the problem.

--sri
Reply all
Reply to author
Forward
0 new messages