This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Servlets and the fly likes Exception handling in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Exception handling in Servlet" Watch "Exception handling in Servlet" New topic

Exception handling in Servlet

Robertovich Wartins

Joined: Nov 21, 2006
Posts: 16
I have servlet and service method looks like the following:

The problem is in catch block - I'm not able to obtain PrintWriter object -> "OutputStream already obtained"
Any Ideas or suggestions - how to solve this?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 62127

Simple. Don't grab it twice. Refactor your code to obtain the output stream once.

P.S. Do you really want to show the stack trace to your users?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Consider Paul's rocket mass heater.
subject: Exception handling in Servlet