190 likes | 203 Views
Learn about JSP Standard Tag Library (JSTL) features such as Expression Language, Core Tags, and Format Tags. Understand how JSTL simplifies JSP development through easy access to JavaBeans, properties, and simple operations.
E N D
JSP Standard Tag Library Jay Sissom
Agenda • JSTL Overview • Expression Language • Core tags • Format tags • Struts-EL
JSTL Overview • JSP Standard Tag Library • Will be included in all Servlet containers at some point in the future • Jakarta provides 2 implementations • Version 1.1.1 for Tomcat 5+ (Servlet spec 2.4/JSP 2.0) • Version 1.0.6 for Tomcat 4 (Servlet spec 2.3/JSP 1.2) • Jakarta implementation written by Shawn Bayern who designed and wrote CAS
JSTL Overview (con’t) • Comprised of 4 tag libraries • Core - Iteration, Conditions, etc • Format - Formatting, i18n • XML - XML processing • SQL - Database access • All tags support expression language
Expression Language • Very simple language • Allows easy access to Javabeans, properties and perform simple operations • Expressions must start with ${ and end with } • Example: • <c:out value=“1 + 2 = ${1+2}”/> Prints 1 + 2 = 3 • <c:out value=“${username}”/> Looks for a javabean named username and prints it’s value
Expression Language (con’t) • Access Javabean properties using . • ${user.name} translates to user.getName() • EL searches each scope area if a scope isn’t specified • Specific scope areas can be used: • ${pageScope.username} • ${requestScope.username} • ${sessionScope.username} • ${applicationScope.username}
Expression Language (con’t) • Comparisons • == or eq for Equals • != or ne for Not Equals • < or lt for Less Than • > or gt for Greater Than • <= or le for Less than or Equal • >= or ge for Greater than or Equal • Example • ${campus eq “BL”}
Core tags • Print data to the browser • Conditional output • Iterations
Core tags <c:out> • Prints an expression to browser • Attributes: • value - Expression to print • default - Value to print if expression is null or invalid • escapeXml - Escape tags in expression true/false
Core tags <c:if> • Conditionally include part of page • Specify logical expression • empty keyword tests for null or missing parameters
Core tags <c:choose> • Choose output based on tests
Format tags • Format numbers and dates • Print i18n messages from ApplicationResources
Format tags <fmt:message> • Print a message from ApplicationMessages file
Format tags <fmt:formatNumber> • Format a number for printing • Decimal places, and comma grouping can be specified • Print a percentage • Print currency (watch out)
Format tags <fmt:formatDate> • Format a date • Print time, date or both • Print in just about any style • Handles i18n
Format tags <fmt:message> • Print messages from message bundle • Automatically handle locale based on browser (just like Struts) • <fmt:bundle> can specify the bundle once on the page instead of for each message tag
Resources • Book: JSTL in Action by Shawn Bayern • Safari: Core JSTL: Mastering the JSP Standard Tag Library by David M. Geary • Safari: JSTL: JSP Standard Tag Library Kick Start by Jeff Heaton
Struts-EL • Add-on to Struts 1.1 • Included in Struts 1.1 download • Allows use of Expression Language in Struts tags • http://struts.apache.org/faqs/struts-el.html • Some Struts tags aren’t implemented in Struts-EL