Custom JSP tags. Lets you connect through JDBC to any
database, perform some SQL select operator and present output in XML format.
So the idea is to use XSLT stuff for publishing data from your database (datasource).
For example:
<%@ taglib uri="taglib.tld" prefix="get" %> <get:XSQL driver="your_jdbc_driver" url="your_db_url" user="scott" password="tiger"> <get:setQuery>select A,B from Table</get:setQuery> </get:XSQL> Tag executes the given query and outputs (inserts into page) result in
XML format. And now you may use for example XSL taglib
for an appropriate transformation:
<%@ taglib uri="taglib.tld" prefix="get" %> <%@ taglib uri="taglib1.tld" prefix="xslt" %> <xslt:applyXSL xslData="sheet.xsl"> <xslt:setXML> <get:XSQL jndiname="your_datasource"> <get:setQuery>select C,D from T where C>?</get:setQuery> <get:setParameter position="1" type="int">2</get:setParameter> </get:XSQL> </xslt:setXML> </xslt:applyXSL> XML data will be presented as a collection of rows where the each row is
a set of attributes:
<rows> <row> <attribute_name1>attribute_value1</attribute_name1> <attribute_name2>attribute_value2</attribute_name2> ... </row> ... ... </rows> so for the above mentioned example (select A,B from Table) it will be some like
this:
<rows> <row> <A>1</A> <B>2</B> </row> <row> <A>3</A> <B>4</B> </row> ... </rows> and you may use stylesheet like this for presenting data in HTML table
for example:
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="rows"> <table border="1" width="100%"> <tr> <th>A</th> <th>B</th> </tr> <xsl:for-each select="row"> <tr> <td><xsl:value-of select="A"/></td> <td><xsl:value-of select="B"/></td> </tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet> Any null value will be presented as an empty string. See also XBean taglib for getting XML right from your DAO. Tags are: XSQL Body tag presents data from your SQL datastore in XML format. Parameters are: 1) driver JDBC driver
setQuery Tag's body defines a SQL select operator. As for JDBC you may use ? sign as a mark for parameters. You can set actual values for parameters through setParameter tag. setParameter Tag's body defines one parameter for SQL statement. Parameters are: 1) position Optional parameter. Describes an
index (the first parameter is 1, the second is 2 etc.) Default value is 1.
for downloading: Library: xsqltag.jar Description: taglib.tld See also Coldtags suite - the largest collection of custom JSP tags.
|
Also in Coldtags:
|