Java Tutorial - Java Script : JSP Standard Tag Library

Java Tutorial - Java Script :

JSP Standard Tag Library

·         paramValues, a collection of all request parameters, each as a string arra
When using one of these collections or other data structures, the c:foreach action makes it easy to loop through each element. The following example displays all of the header variables sent with a JSP page:
<c:forEach items=’${header}’ var=’head’>
<ul>
<li>Name: <c:out value=’${head.key}’/></li>
<li>Value: <c:out value=’${head.value}’/></li>
</ul>
</c:forEach>
Four variables can be used to make explicit references to variable scope:
·         applicationScope, a collection of all application scope objects
·         pageScope, a collection of all page scope objects
·         requestScope, a collection of all request scope objects
·         sessionScope, a collection of all session scope objects
For example, the expression ${sessionScope.price} retrieves an object named price in session scope. If no other scope has an object named price, the expression ${price} also works. Today’s final project shows some of the power and flexibility of JSTL. This page makes use of XML actions to present data from an RSS newsfeed, an XML format for offering web content in machine-readable form. JSTL can import and parse XML, HTML, or any other data available at a URL, even if it isn’t on the same server as the page making use of it. RSS, which stands for Really Simple Syndication, enables websites to share headlines, links, and other content with each other (and with readers using software called an RSS aggregator). Listing 21.13 contains an example: a simplified version of the RSS feed for the SportsFilter website.
SportsFilter, a popular sports community weblog at http://www.sportsfilter.com, shares the latest news in an RSS 2.0 feed. The XML data from the feed can be read into a variable using the c:import action from the core library and parsed with the x:parse action from the XML library. The parsed data can be examined, filtered, transformed, and displayed. Listing 21.14 contains a JSP application that uses simple XPath statements to extract and display parts of the XML data.
Comments on the page describe the JSTL actions that it contains. The most challenging part of JSTL is the Expression Language, which can be avoided by using versions of the tag libraries that use JSP syntax for Java statements and expressions. JSTL’s Expression Language is distinguished from the other JSP syntax by the limits on what it can do. There are no assignment operators or conditional logic, which forces developers to use external Java classes and JSTL actions for these tasks. Though some Java programmers might blanch at the thought of learning another language simply for web applications, the Expression Language is simple enough to be picked up quickly, especially by those who are comfortable with JavaScript. By keeping Java code out of JSP  pages, the Expression Language offers reusability and reliability. In conjunction with JSTL, it brings JSP much closer to the promise of separating the presentation of a web application from the code required to make it happen. JSTL serves as a nice complementary offering to Struts, an open source web application framework that’s also the work of the Apache Jakarta project.