This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Well, first of all you'll want to get that code out of a JSP and into a servlet where it belongs. By putting it in a JSP you are mixing the output of your Java code with the output of the JSP -- all that HTML code. That's guaranteed to produce garbage instead of an image.