Java/JSP/Custom Tag
Версия от 18:01, 31 мая 2010; (обсуждение)
Содержание
Basic Example of a Custom Tag
Custom Tag: Converter
Custom Tag:Currency
Various JSTL tags
// The following demo is from
// The latest offering from Apress is Pro JSP, 3rd Edition
// Author: Brown et al.
// ISBN : 1-59059-225-5
// URL :Pro JSP, 3rd Edition
// download the jstltest.war for testing the following code.
// set
<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %>
<c:set var="browser" value="${header["User-Agent"]}" scope="session"/>
Your browser is : <B><c:out value="${browser}"/></B>
// tokens
<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %>
<c:set var="queryResult" value="Dan,Jepp,Male,26,Java Developer,London"
scope="request" />
<html>
<body>
<table border="1">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Sex</th>
<th>Age</th>
<th>Occupation</th>
<th>Location</th>
</tr>
<tr>
<c:forTokens items="${queryResult}" delims="," var="token">
<td><c:out value="${token}"/></td>
</c:forTokens>
</tr>
</table>
</body>
</html>
// remove
<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %>
<c:set var="browser" value="${header["User-Agent"]}" scope="session"/>
<c:remove var="browser" scope="session"/>
Your browser is : <B><c:out value="${browser}"/></B>
// output
<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %>
<%@ page import="com.apress.projsp20.ch04.Book"%>
<jsp:useBean id="book" class="com.apress.projsp20.ch04.Book">
<jsp:setProperty name="book" property="title" value="Pro JSP, 3rd Edition"/>
<jsp:setProperty name="book" property="author" value="Brown et al."/>
<jsp:setProperty name="book" property="isbn" value="1-59059-225-5"/>
<jsp:setProperty name="book" property="url" value="http://www.apress.ru/book/bookDisplay.html?bID=256"/>
</jsp:useBean>
The latest offering from Apress is <i><c:out value="${book.title}"/></i><BR>
Author: <c:out value="${book.author}"/><BR>
ISBN : <c:out value="${book.isbn}"/><BR>
URL :</TD>
</TR>
</TABLE>
<HR>
</x:forEach>
// XML if
<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.ru/jstl/xml" prefix="x" %>
<c:import url="book.xml" var="url" />
<x:parse xml="${url}" var="book" scope="session" />
<x:if select="$book/book/publisher="Apress"">
Another great title from Apress! :
<P>
<B><x:out select="$book/book/title"/></B><BR>
<x:out select="$book/book/author"/><BR>
<x:out select="$book/book/url"/><BR>
</x:if>