1 / 18

JSP Standard Tag Library

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

wturnbull
Download Presentation

JSP Standard Tag Library

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JSP Standard Tag Library Jay Sissom

  2. Agenda • JSTL Overview • Expression Language • Core tags • Format tags • Struts-EL

  3. 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

  4. 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

  5. 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

  6. 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}

  7. 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”}

  8. Core tags • Print data to the browser • Conditional output • Iterations

  9. 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

  10. Core tags <c:if> • Conditionally include part of page • Specify logical expression • empty keyword tests for null or missing parameters

  11. Core tags <c:choose> • Choose output based on tests

  12. Format tags • Format numbers and dates • Print i18n messages from ApplicationResources

  13. Format tags <fmt:message> • Print a message from ApplicationMessages file

  14. Format tags <fmt:formatNumber> • Format a number for printing • Decimal places, and comma grouping can be specified • Print a percentage • Print currency (watch out)

  15. Format tags <fmt:formatDate> • Format a date • Print time, date or both • Print in just about any style • Handles i18n

  16. 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

  17. 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

  18. 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

More Related