29.01.2013 Views

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 10-17 FeaturedItemXMLServlet.java<br />

Notice that the featureditem package has been added to the JavaSource<br />

folder for the project and that the FeaturedItemXMLServlet has been added to<br />

the package.<br />

We are now ready to add some logic to our servlet to enable it to retrieve the<br />

database connect and SQL query information from the FeaturedItem.xst file, and<br />

also add the logic to dynamically create an XML and XSL string, then transform<br />

the content of these two strings into an HTML string which will eventually be<br />

displayed to the user.<br />

1. With the FeaturedItemXMLServlet.java file still opened in the Java editor,<br />

copy the code from the example below into the servlet. There are comments<br />

throughout the code, so please read through it to get a better understanding<br />

of what is being done. Note that you will need to modify the code that points to<br />

the .xst file to reflect the location of your workspace.<br />

Example 10-4 FeaturedItemXMLServlet.java<br />

package featureditem;<br />

import javax.servlet.http.*;<br />

import java.io.*;<br />

Chapter 10. Working with XML 343

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!