Docsity

JSP Standard Tag Library Part 2-Java Programming-Lecture Slides, Slides of Java Programming

Partial preview of the text

Download JSP Standard Tag Library Part 2-Java Programming-Lecture Slides and more Slides Java Programming in PDF only on Docsity!

Iterator Tag: <c:forEach>

 Allows you to iterate over a collection of objects

 items: represent the collection of objects

 var: current item

 varStatus: iteration status

 begin, end, step: range and interval

 Collection types

 java.util.Collection

 java.util.Map

 value of var attribute should be of type java.util.Map.Entry

Example: <c:forEach>

quoted from ./iterators/Simple.jsp

<c:forEach var="customer" items="${customers}"> ${customer}
</c:forEach>

Example: <c:forEach>, Data types

quoted from ./iterators/DataTypes.jsp

<c:forEach var="i" items="${intArray}"> <c:out value="${i}"/> • </c:forEach> <c:forEach var="string" items="${stringArray}"> <c:out value="${string}"/>
</c:forEach> <c:forEach var="item" items="${enumeration}" begin=" 2 " end=" 10 " step=" 2 "> <c:out value="${item}"/>
</c:forEach> <c:forEach var="prop" items="${numberMap}" begin=" 1 " end=" 5 "> <c:out value="${prop.key}"/> = <c:out value="${prop.value}"/>
</c:forEach> <c:forEach var="token" items="bleu,blanc,rouge"> <c:out value="${token}"/>
</c:forEach>

Example: <c:forEach>, Data types

quoted from ./iterators/DataTypes.jsp

Example: <c:forEach>, Iteration status

quoted from ./iterators/Status.jsp

Example: <c:forToken>

<c:forTokens var="token" items="one,two,three" delims=","> <c:out value="${token}"/> </c:forTokens>

Example: <c:out>

quoted from /elsupport/Out.jsp

URL Import: <c:import>

 More generic way to access URL-based resources

(than <jsp:include>)

 Absolute URL: for accessing resources outside of Web

application

 Relative URL: for accessing resources inside of the same

Web application

 More efficient (than <jsp:include>)

 No buffering

 <c:param> tag can be used to specify parameters (like

<jsp:param>)

Example: <c:import> with <c:param>

<c:import url="header.jsp"> <c:param name="pageTitle" value="newInstance.com"/> <c:param name="pageSlogan" value=" " /> </c:import>

URL Rewriting: <c:url>

 Used for URL rewriting

 All the URL's that are returned from a JSP page (to a

browser) have session ID if Cookie is disabled on the

browser

 Can take param subtags for including parameters in

the returned URL

Example: <c:url> - Cookie enabled

quoted from /import/Encode.jsp

Example: <c:url> - Cookie disabled