50 likes | 195 Views
JSP Tag Library. CSCI 4300 Notes from Steve Small, http://www.javaworld.com/javaworld/jw-02-2003/jw-0228-jstl.html. What is the Tag library?. Creates additional XML-style tags Provide programming functionality with (somewhat) less mess Standard tag library:
E N D
JSP Tag Library CSCI 4300 Notes from Steve Small, http://www.javaworld.com/javaworld/jw-02-2003/jw-0228-jstl.html
What is the Tag library? • Creates additional XML-style tags • Provide programming functionality with (somewhat) less mess • Standard tag library: • Core functions (output, control statements) • Formatting • Internationalization • SQL
Installing the standard library • Download and install JSTL support in Tomcat • Declare in web.xml: • <taglib> <taglib-uri>http://java.sun.com/jstl/core</taglib-uri> <taglib-location>/WEB-INF/c.tld</taglib-location> </taglib> • Include taglib descriptor file c.tld in WEB-INF • <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
Core STL Example • <b>Parameter values passed to this page for each parameter: </b> • <table border="2"><c:forEach var="current" items="${param}"> <tr> <td> <b><c:out value="${current.key}" /></b> </td> <c:forEach var="aVal" items="${paramValues[current.key]}"> <td> <c:out value="${aVal}" /> </td> </c:forEach> </tr></c:forEach></table> • Param and paramValues are global Map vars from Web container
JSP Expression Language • Similar to PHP or Perl string interpolation • ${variable-name} = value of that variable • <c:out value="${anExpression}"/><c:out value="literalText${anExpression}${anotherExpression}"/><c:out value="literalText"/> • ${anObject.aProperty}${anObject["aPropertyName"]}${anObject[aVariableContainingPropertyName]}