Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tag variable problem

 
Sam Wang
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Please.
 
ersin eser
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you code for to open the connection after the end tag ? ( in doEndTag() may be ..)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
hth,
bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic