The time to be putting Java code into a JSP is long, long passed. 10 years in fact. 10 years! It's high time to come up to speed with the JSTL and EL and to stop writing JSP pages like it is still 2001.
Move all the Java code to a servlet and other Java classes where it belongs. Capture the DB data in Java constructs that you place into request scope, and use the JSTL and EL on the JSP page to display the data.
Your post demonstrates one of the problems inherent in scriptlets: you have some Java code and you have some HTML code, and it's mashed together in one place. The Java code should be indented one way, and the HTML should be indented another way. However not only have you not attempted to do that, you haven't got any meaningful indentation at all, so it's very hard to see if your Java braces match or your HTML tags match. (Hint: they don't.)
And your code at lines 36 to 38:
indicate that you haven't quite understood how JSPs work. They can be replaced by this simpler code:
because all of your JSP code except the scriptlets is automatically written to the response.
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads