This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets 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: 60764

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]
I agree. Here's the link:
subject: Exception handling in Servlet
Similar Threads
setting PrintWriter out = response.getWriter(); out.print("My Servlet"); response.setContentType
problem with urldecoder in doGet mehtod
init and destroy method
Sharing method between servlets
Web Service