I believe that in JSP there's a "log" object or method that will write to the server log. That will work better than attempting to log the stacktrace to the client. Or, if all else fails, write the stacktrace to System.out.
Actually, attempting to acquire a database connection in the way you described has 2 strikes against it.
1. We do not recommend putting logic in JSPs. Use the JSP for display and let a servlet do the dirty work.
2. Instead of the relatively expensive process of creating a Connection that you're using, well-written enterprise webapps use Connection Pools constructed by the webapp server.
Yes, the "brute force" ASP/PHP way is quicker to code, but J2EE is an expensive technology and the extra work up front should pay off in terms of overall maintainability and performance.
Speaking as a rabid Java fan, when I need something quick and dirty, I do use something like PHP, not J2EE.
An IDE is no substitute for an Intelligent Developer.