You don't. You can't return two responses to a single request.
You're going to need to back up and explain what it is that you are really trying to accomplish.
Joined: Nov 16, 2004
On my JSP I have a function that uses a jQuery.getJSON call to the servlet sending a url address as a parameter. It is supposed to display a drawing cooesponding to the url. If the url does not exist I want to return a flag to the calling JSP and display a message to that effect. If the url does exist I want to display the drawing. Right now the servlet code rus but no drawing is displayed.
Your code is not complete, but I suspect you're doing exactly what your exception message says. Trying to write multiple responses to one request. Are you using a RequestDispatcher to talk to a JSP after writing to the OutputStream?
What a JSP does is basically make an HTML page and write it to the response object. If you've already written to the response object and then you write a whole jsp page... then of course you get that exception. You can't write the response, and then dispatch to a JSP, because you've already written your response!