Marino Vittorio wrote:
>
> Hi gurus, this is the typical layout of my page:
>
> <%@ page ... errorPage="error.jsp" %>
> ...
> <%
>
> SQLManager myMan = SQLManager.getInstance();
> Connection myConn = myMan.requestConnection();
>
> ...
> ...
> ...
>
> myMan.returnConnection(myConn);
> %>
>
> Now, if an exception occurs after requesting a connection to the pool and
> before releasing it, that connection is open and is not gonna be closed till
> PoolMan timeout. In a production environment with an average of 100 active
> sessions this cannot be acceptable. If a page has errors in it after a
> product release, all the connection objects in the pool are gonna be open
> and unusable in seconds.
>
> Now my question: how can I handle this? Do I need to put everything in
> try/catch blocks? Is there any way to pass parameters to the error page?
You *can* wrap your scripting code in try/catch/finally to deal with the
exception cases, but I don't recommend it. Too much code in JSP pages causes
both debugging problems and a maintenance nightmare down the line.
A better approach is to use either a servlet to do all database access
and forward to a JSP page for generating the response, or use JSP custom
actions for the database access in the JSP pages. There are plenty of
custom tag libraries for this available, so you don't have to roll your
own. A couple of examples of implementations you can use for free, with
source code available:
* The example tag library for my JSP book:
<http://TheJSPBook.com>
* The DbTags library from Jakarta:
<http://jakarta.apache.org/taglibs/doc/dbtags-doc/intro.html>
A commercial example is the InstantOnline Basic product my company sells:
* <http://www.gefionsoftware.com/InstantOnline/Basic/>
And if you search the web, I'm sure you can find a lot more.
Hans
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets