Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Using XTags to Add XSLT Transformations to Your JSP Web Applications : Page 2

You don't have to write repetitive manual code to display database tables or apply transformations to display XML documents in your JSP Web applications; the Jakarta XTags tag library provides an easy way to apply an XSLT stylesheet to XML data.


advertisement
Configuring a DataSource in WebLogic
The Web application retrieves data from the Oracle database using a JDBC connection. You'll need to configure a JNDI datasource in WebLogic to get the database connection to work. I've used the examplesServer included in the WebLogic server examples to deploy the web application. First, open the WebLogic server administration console by browsing to the URL http://localhost:7001/console. In the console, find the "Services > JDBC > Connection Pools" node, right-click on it, and then select "Configure a New JDBCConnectionPool" from the popup menu. In the "Choose database" frame select Oracle as the database type, and "BEA's Oracle Driver (Type 4 XA)" as the database driver. Click on the Continue button.

To define connection properties for the database, specify the database instance you created earlier in this article as the Database Name, for example, "OracleDB." Enter "localhost" as the Host Name, and "1521" as the Port. Specify "OE" as both the Database User Name and as the password. Click the Continue button.

In the "Test database connection" section, click on "Test Driver Configuration" to test the JDBC connection with the database. Click on the "Create and Deploy" button to create and deploy the connection pool. You use the connection pool to configure a datasource in JNDI by right-clicking on the Data Sources node and selecting "Configure a New JDBCTxDataSource."

Specify a JNDI name for the datasource and click on the Continue button. WebLogic uses the datasource JNDI to obtain a JDBC connection for the JSP application. In the "Connect to Connection Pool" field, select the connection pool you configured earlier. Click on the Continue button. Select the examplesServer to deploy the datasource, and then click on the Create button to create and configure the datasource.

Integrating the Apache Jakarta XTags Tag Library
The application retrieves data from the datasource you configured in the previous section, converts the retrieved data to XML with the XML SQL Utility (XSU), then converts the XML to HTML using the Apache XTags tag library. To enable that to work, you need to add the jar files required for XSU and XTags to the WebLogic server's classpath. Add the following jar files to the CLASSPATH variable that you'll find in the C:\BEA\weblogic81\samples\domains\examples\startExamplesServer script file.

Table 1. Required JAR Files: The table shows a list of the jar files required to use XSU and XTags.
JAR File Description
<dom4j>\dom4j-1.6.1.jar DOM4J
<dom4j>\lib\jaxen-1.1-beta-6.jar JAXEN
<xalan-j_2_7_0>\xalan.jar Xalan
<xalan-j_2_7_0>\xercesImpl.jar Xerces
<Oracle10g>\LIB\xsu12.jar XML SQL Utility
<Oracle10g>\LIB\xmlparserv2.jar XML Parser
<XDK10g>\lib\xdb.jar Oracle XDB
<Oracle10g>\jdbc\lib\classes12dms.jar Oracle JDBC
<Oracle10g>\LIB\servlet.jar Servlet API

The XTags tag library provides several XSLT and XPath tags to transform an XML document in a JSP. Table 2 lists some of the common tags.

Table 2. Common XSLT and XPath XTags: The table shows some of the commonly used XTags.
XTags Tag Description
style Transforms an XML document with an XSLT stylesheet.
param Specifies a parameter for XSLT transformation.
parse Parses an XML document.
variable Defines a XSLT variable.
stylesheet The xsl:stylesheet tag in a JSP.
template The xsl:template tag in a JSP.
applyTemplates The xsl:applyTemplates tag in a JSP.
element The xsl:element tag in a JSP.
attribute The xsl:attribute tag in a JSP.
output The xsl:output tag in a JSP..

Next, configure the XTags tag library with the WebLogic server web application. In the C:\BEA\weblogic81\samples\server\examples\build\mainWebApp\WEB-INF directory, you'll find a web.xml file. Add a tag for the XTags tag library as follows:

<taglib> <taglib-uri> http://jakarta.apache.org/taglibs/xtags-1.0 </taglib-uri> <taglib-location> /WEB-INF/xtags.tld </taglib-location> </taglib>

Copy the C:\XTags\jakarta-taglibs\xtags\taglibs-xtags.tld file to the C:\BEA\weblogic81\samples\server\examples\build\mainWebApp\WEB-INF directory.

Create a lib directory in the WEB-INF directory. Copy the C:\XTags\jakarta-taglibs\xtags\taglibs-xtags.jar file to the WEB-INF/lib directory.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap