Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
javadev - 14 Nov 2006 08:45 GMT
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
Manish Pandit - 14 Nov 2006 09:55 GMT
> 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
javadev - 14 Nov 2006 10:02 GMT
> 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.
Tor Iver Wilhelmsen - 15 Nov 2006 17:51 GMT
> 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.
adwords@pulpjava.com - 15 Nov 2006 22:44 GMT
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

> > Servlet.service() for servlet jsp threw exception
> > java.lang.IllegalStateException: getOutputStream() has already been
[quoted text clipped - 13 lines]
> distinctly named web applications you like (for practical purposes) on
> the same Tomcat.
javadev - 16 Nov 2006 11:22 GMT
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

> There's a good change you've opened your PrintWriter, and then done a
> forward. A forward expects a clean, virginal PrintWriter.
[quoted text clipped - 30 lines]
> > distinctly named web applications you like (for practical purposes) on
> > the same Tomcat.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.