Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutputStream(

J

javadev

I have an Apache Tomcat server on which I have deployed 2 web
applications.

When I deploy and run the first application everything works fine. But
on deploying the second application, I get the following error:

Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been
called for this response

I think this might have to do with both applications running of the
same port on the server. How can I fix this?

Thanks
SS
 
M

Manish Pandit

I think this might have to do with both applications running of the
same port on the server. How can I fix this?

As long as they have different contexts, you should be okay. The
mentioned exception occurs when you try to write to the response after
it has been committed. Can you provide more information around the two
applications? This should happen to an application regardless of it's
coexistance with another, as the contexts are totally different.

-cheers,
Manish
 
J

javadev

As long as they have different contexts, you should be okay. The
mentioned exception occurs when you try to write to the response after
it has been committed. Can you provide more information around the two
applications? This should happen to an application regardless of it's
coexistance with another, as the contexts are totally different.

The 2 applications are deployed separately through the Tomcat Manager
which I assume should create separate contexts for them.

I get the same error message on NetBeans (which I use to develop the
applications) but my application runs fine through NetBeans. However
when I deploy the 2nd application and try to run it on the server, then
I can access the index.jsp which contains a login page. On submitting
this page, I get the stack trace of the above error.
 
T

Tor Iver Wilhelmsen

javadev said:
Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been
called for this response

Uusually triggered by calling RequestDispatcher.forward() or some
ServletResponse methods (like setting response headers) that don't
like it if you have tried to get hold of the (body) output stream
(i.e. you have committed the response). Since it cannot know whether
you have written to it it just assumes you have been naughty and done
so.
I think this might have to do with both applications running of the
same port on the server. How can I fix this?

It doesn't have anything to do with the port: You can have as many
distinctly named web applications you like (for practical purposes) on
the same Tomcat.
 
A

adwords

There's a good change you've opened your PrintWriter, and then done a
forward. A forward expects a clean, virginal PrintWriter.

Check that you're not doing a Print before or after forwarding with the
RequestDispatcher.

Cheers!

-Cameron McKenzie
Author of the SCJA Certification Guide and What is WebSphere?


Free WebSphere Tutorials: www.pulpjava.com
Free Mock Java Certification Exams: www.scja.com
Free J2EE and Java Multimedia Tutorials: www.mcnz.com

Certification Resources: www.examscam.com
 
J

javadev

Hi Tor

It turned out that it was being caused by the RequestDispatcher's
forward() call. I've changed those now to jsp:forward and it works fine
now.

Thanks
Swetha
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top