Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL: How to avoid scriptlet for JDBC connection close?

Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to convert a JSP to use JSTL and the Expression Language without scriptlets.
The JSP instantiates a bean and then uses the EL to invoke several getter routines.
The bean opens a JDBC connection when the first getter is called, and stores the connection in an instance variable since it will be needed by subsequent getters.
My problem: How can I close the JDBC connection at the end of my page without using a scriptlet? Right now I have this at the bottom of all my pages:
<% bean.close(); %>
where the bean's close() method closes the JDBC connection.
Is there a better way to do this?
I suppose I could change the name of close() to look like a getter routine, and invoke that from the Expression Language, but that seems incredibly kludgy.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic