Presentation is loading. Please wait.

Presentation is loading. Please wait.

JSTL and Web Development at Universities Shawn Bayern Research programmer, Yale University JSTL reference-implementation lead Author, Web Development with.

Similar presentations


Presentation on theme: "JSTL and Web Development at Universities Shawn Bayern Research programmer, Yale University JSTL reference-implementation lead Author, Web Development with."— Presentation transcript:

1 JSTL and Web Development at Universities Shawn Bayern Research programmer, Yale University JSTL reference-implementation lead Author, Web Development with JavaServer Pages Author, The JSP Standard Tag Library (upcoming)

2 Agenda JSP overview: scripting and tag libraries JSTL basics Origins Design Features Examples of design principles in use Yale’s network-registration application HTML “scraping” for portals Q&A

3 JavaServer Pages Scriptlets <% getFoo(request); printFoo(out); String a = “goat”; %> Oink! Java (and more?) embedded within template text Access to implicit objects: request, response, etc. Conditional blocks, loops—manually constructed

4 JavaServer Pages Tag libraries c is true Round and round we go HTML-like tags (can be well-formed XML) Invoke Java logic behind the scenes. May access body, e.g., for iteration, conditional exclusion—or just as arbitrary parameter May access PageContext Libraries and prefixes

5 Advantages of tag libraries Abstraction, abstraction, abstraction. Abstraction. Separation of logic from presentation and content. Simple, familiar interface for page authors. Implicit (versus explicit) arguments.

6 Tag library Tags: Abstracting logic JSP page Back-end Java code Database Directory Tag library

7 What is a JSP tag? “Standard actions” – e.g., Part of JSP spec Java class implementing Tag interface Accepts attributes as JavaBean properties ( setXXX() ) Answers callbacks associated with Start of tag End of body End of tag … and so on Why so specific? (No closure for body.) Knows about its page (PageContext) Knows about its parent tags findAncestorWithClass() Optionally knows about its body (BodyContent)

8 Tag handler doStartTag()doEndTag() doCatch()doFinally() Tag attributes Tag body

9 Where do tag libraries come from? Java developers like us To support ourselves, our page authors Vendors—e.g., Allaire, BEA, iPlanet Standard tag library Java Community Process (JSR-052) Input from familiar vendors, motivated individuals Under Sun’s leadership Implementation distributed through Apache

10 JSTL design principles JSTL 1.0: Keep it simple! Targeted tags Could have a single tag: Instead, single-purpose tags, tightly focused Design motivated by “page author” Perhaps something of a fantasy, like the legal “reasonable person.” But a helpful guide nonetheless.

11 The parable of Mike and Phillipe Mike Phillipe Credit: Pierre Delisle (spec lead)

12 Potential limitations Tag abstraction may be excessive for tiny applications (but JSP 1.3…) Page authors need technical skills! They must understand: Flow of application Programmatic control flow within page Variable reference (expression language) Domain-specific languages (SQL, XPath) and associated principles

13 JSTL 1.0 features Conditional logic Iteration Text retrieval (URL, RequestDispatcher ) Text formatting and parsing (i18n) XML manipulation (XPath, XSLT) Database access Last but certainly not least: Expression language

14 JSTL 1.0 libraries Library featuresRecommended prefix Core (control flow, URLs, variable access) c Text formattingfmt XML manipulationx Database accesssql

15 JSTL features: expression language JSTL’s major structural innovation Replaces “rtexprvalues” Allows simple retrieval of scoped attributes… $session:duck … and other data $cookie:crumb $param:email

16 JSP history: progress Scriptlets Beans and standard actions Traditional tag libraries ’/> Expression-language capable library rtexprvalu e

17 State of expression language Syntax currently being debated EA2 supports “pluggable” languages for experimentation. Candidates include: SPEL (straw man) ECMAScript JXPath Comments?

18 Advantages of expression language Scripting, not programming. Not even scripting, really.  Having said that, I personally hope that the EL(s) we  standardize on are so simple as to require almost no  education at all. +2 Typeless reference Simplified syntax

19 JSTL features: core tags (1) Iteration <c:forEach items=“$list” begin=“5” end=“20” step=“4” var=“item”> “var” convention and variable access “paging”

20 JSTL features: core tags (2) Conditional evaluation a equals b Mutually exclusive conditionals a equals b a equals c I don’t know what ‘a’equals.

21 JSTL features: core tags (3) URL retrieval <c:import var=“cnn” url=“ http://www.cnn.com/cnn.rss ”/> Data exposed as String or Reader All core URLs supported (HTTP, FTP, HTTPS with JSSE) Local, cross-context imports supported

22 JSTL features: text formatting Formatting and parsing Numbers Dates Internationalization Message bundles Locale support Message argument substitution “Hi {0}. I would like to {1} your money today. I will use it to buy myself a big {2}.”

23 JSTL features: XML manipulation Use of XSLT, XPath to access, display pieces of XML documents http://www.cnn.com/cnn.rss Example later

24 JSTL features: database manipulation Tags for Queries ResultSet caching Updates / inserts Transactions Parametric ( PreparedStatement ) argument substitution DataSource-based connection management

25 SQL tags: the debate Tag library JSP page Back-end Java code Database Tag library

26 JSTL programmer support JSTL also supports Java developers Simplifies tag development IteratorTagSupport, ConditionalTagSupport Instead of writing whole tag handler ( doStartTag(), doEndTag() ), simply override a few methods: protected boolean condition() protected Object next()

27 JSTL schedule Currently in Early Access Release 2 No promises, but many hints. http://jakarta.apache.org/taglibs/ → “Standard” http://jakarta.apache.org/taglibs/ EA3 mid December Release of 1.0 in 2002 JSTL 1.0 to include core features Later versions fill in other convenient but less general functionality. Perhaps more J2EE-specific support. Applies to this presentation too!

28 JSP/JSTL future Finalize JSTL JSP 1.3 Universalize “expression language” Support creation of tags in JSP itself Works nicely with JSTL’s focused tags Books, educational materials on JSTL to assist page authors (and us developers vicariously).

29 Yale example: Netreg Student network registration (Netreg) application Used by 5900 students to register computers for network use Discovers EA via SNMP router query Managed by Student Computing group at Yale; my group provided support Developed in less than a month Student Computing group (nonprogrammers) maintains user interface

30 Yale example: Netreg HTML, JSP code produced and maintained by nonprogrammers Application uses early-access “standard” – plus locally written – tags.

31 Yale example: Netreg Example code Retrieve full name from database <reg:fullName var="name“ netid=“$netid"/> Conduct CAS authentication Discover Ethernet address

32 Yale example: Netreg Custom “registration” tags documented, available to page authors. Via attributes, the data these tags expose is accessible to JSTL tags.

33 Yale example: XML/XPath Portals, other “summary” web sites often need to retrieve content from other pages. JSTL provides a flexible, standard way to handle this task. Example: retrieve headlines from student newspaper, display in custom format.

34 Yale example: XML/XPath <x:expr select="$dom//a[@$class='leadheadline’]”/> Sample XML: … Headline …

35 Advantages of JSTL XML/XPath support Why not always use XSLT? JSTL provides XPath support but doesn’t preclude convenient, standard access to Java/JSP code. E.g., parse an article URL out of a document, then follow the URL and parse its contents. JSP/JSTL may be more familiar and convenient for simple tasks.

36 Summary JSP supports scriptlets (poor abstraction) and tags (useful abstraction) JSTL is the JSP Standard Tag Library. JSTL and JSP tags support separation of content from presentation

37 URLs Jakarta Taglibs http://jakarta.apache.org/taglibs/ JSTL JSR http://www.jcp.org/jsr/detail/052.jsr JSP 1.3 JSR http://www.jcp.org/jsr/detail/152.jsr Official email address for JSTL comments mailto:jsr052-comments@sun.com My upcoming JSTL book’s site http://www.jstlbook.com/ My email address mailto:shawn.bayern@yale.edu


Download ppt "JSTL and Web Development at Universities Shawn Bayern Research programmer, Yale University JSTL reference-implementation lead Author, Web Development with."

Similar presentations


Ads by Google