File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Tag variable problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Tag variable problem" Watch "Tag variable problem" New topic

Tag variable problem

Sam Wang
Ranch Hand

Joined: Jul 17, 2001
Posts: 95
I write some custom tags about sql.As follow:
<mytag:connection driver="driver-class" url="db-url" />
<mytag:query >some sql</mytag:query>
The connection tag will set a java.sql.Connection as a attribute of pageContext.It is also defined in connectionExtraInfo and tld.
My problem is i can't get connection after the connection tag end.

ersin eser
Ranch Hand

Joined: Feb 22, 2001
Posts: 1072
Did you code for to open the connection after the end tag ? ( in doEndTag() may be ..)
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63873

You can store the connection as a request or page attribute and retrieve it from the page after the tag is closed. If you also use a TEI class for your tag, you can automatically create a page variable for the object.
I'd caution to be sure you free the connection (or return it to the pool or whatever) on the page when you are done with it. Since lots of things can interrupt page processing, a try/finally block might be good insurance.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Tag variable problem
It's not a secret anymore!