I want to keep a certain resource (a db connection of sorts) open until the last JSP in a request has finished doing its stuff. The reason I want to do this is that I'm putting smart data objects in the request, for consumption by the JSP, and these objects have methods that might trigger a db load. The JSP might inadvertently trigger a lazy load of a dependent object from the db, so I need to keep a db connection open until the JSP is finished. (Actually, it's not exactly a db connection; it's a Hibernate 'session' object that knows how to get db connections. Hibernate is an O/R mapping tool. It is important to close this resource when the request is done.) In other words, the following code might trigger a lazy load:
<%-- might call customer.getDetails, which triggers a db read: --%> <bean:write name="customer.details"/> Details aside, I want to keep a certain resource available for all JSP's, and make sure to close it when the JSP's are done. I'm using tiles, so there's lots of JSP servlets invoked in one request. I tried using a servlet filter that closed the resource after calling chain.doFilter. The problem is that the filter gets called many times per request, for each action and Tile JSP in the request. Can I use response.isCommitted to see if the JSP's are done writing stuff? Something like this: class MyFilter implements ServletFilter { void doFilter(request, response, chain) { if (isResourceOpen() == false) { openResource(); } try { chain.doFilter(...); } catch (Throwable t) { closeResource(); throw t; } if (response.isCommitted()) { closeResource(); } } } If this doesn't work, is there another way to keep a resource available for all the Tiles JSP servlets in a request, and make sure to close the resource when the request is finally complete? I'm new to servlet filters, so there might be something I'm missing. Thanks! Steve -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>