12.07.2015 Views

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

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.

CHAPTER 11 ■ PAGES AND COMPONENTSTo commence, this JSP needs to import the XML taglib (<strong>with</strong> the directive ) and thenaccess the books.xml file, which is loaded into the variable bookUrl using the tag. bookUrlcontains the raw text that needs to be parsed using the tag, and the resulting DOM is stored inthe variable doc. Now that the document is parsed, you iterate through it and display the values by usingXPath expressions <strong>with</strong> (/@isbn represents an XML attribute and /title an XML element). Theresult is the same as that in Figure 11-5.FunctionsFunctions are not tags but are defined in the JSTL specification. They can be used <strong>with</strong> EL and are mostlyemployed to deal <strong>with</strong> string manipulation. For example:${fn:contains("H2G2", "H2")}This code checks whether a string contains a substring. In this example, it will return true becauseH2G2 contains H2. The following function returns the length of a string or a collection. The result will be 4.${fn:length("H2G2")}These functions can display their result in a JSP (<strong>with</strong>in a tag) and can be used in a test or ina loop.H2G2 is four characters longTable 11-7 shows all the functions contained in the library.321

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

Saved successfully!

Ooh no, something went wrong!