Title: JSTL and Web Development at Universities
1JSTL 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)
2Agenda
- JSP overview scripting and tag libraries
- JSTL basics
- Origins
- Design
- Features
- Examples of design principles in use
- Yales network-registration application
- HTML scraping for portals
- QA
3JavaServer 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, loopsmanually constructed
4JavaServer 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
exclusionor just as arbitrary parameter - May access PageContext
- Libraries and prefixes
5Advantages of tag libraries
- Abstraction, abstraction, abstraction.
- Abstraction.
- Separation of logic from presentation and
content. - Simple, familiar interface for page authors.
- Implicit (versus explicit) arguments.
6Tags Abstracting logic
JSP page
Back-end Java code
Tag library
Database
Tag library
Directory
7What 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)
8Tag handler
Tag handler
doStartTag()
doEndTag()
Tag body
Tag attributes
?
doCatch()
doFinally()
9Where do tag libraries come from?
- Java developers like us
- To support ourselves, our page authors
- Vendorse.g., Allaire, BEA, iPlanet
- Standard tag library
- Java Community Process (JSR-052)
- Input from familiar vendors, motivated
individuals - Under Suns leadership
- Implementation distributed through Apache
10JSTL 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.
11The parable of Mike and Phillipe
Mike
Phillipe
Credit Pierre Delisle (spec lead)
12Potential 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
13JSTL 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
14JSTL 1.0 libraries
15JSTL featuresexpression language
- JSTLs major structural innovation
- Replaces rtexprvalues
-
- Allows simple retrieval of scoped attributes
- sessionduck
- and other data
- cookiecrumb
- paramemail
16JSP history progress
- Scriptlets
-
- Beans and standard actions
- /
-
-
- Traditional tag libraries
- etid)) /
- Expression-language capable library
-
rtexprvalue
17State of expression language
- Syntax currently being debated
- EA2 supports pluggable languages for
experimentation. Candidates include - SPEL (straw man)
- ECMAScript
- JXPath
- Comments?
18Advantages 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
19JSTL featurescore tags (1)
- Iteration
- begin5 end20 step4
- varitem
-
-
- var convention and variable access
- paging
20JSTL featurescore tags (2)
- Conditional evaluation
-
- a equals b
- Mutually exclusive conditionals
-
-
- a equals b
-
-
- a equals c
-
-
- I dont know what aequals.
-
-
21JSTL featurescore tags (3)
- URL retrieval
-
- urlhttp//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
22JSTL featurestext 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.
23JSTL featuresXML manipulation
- Use of XSLT, XPath to access, display pieces of
XML documents - varcnn/
-
-
- Example later
24JSTL featuresdatabase manipulation
- Tags for
- Queries
- ResultSet caching
- Updates / inserts
- Transactions
- Parametric (PreparedStatement) argument
substitution - DataSource-based connection management
25SQL tags the debate
JSP page
Back-end Java code
Tag library
Database
Tag library
JSTL SQL tags
26JSTL 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()
27JSTL schedule
- Currently in Early Access Release 2
- No promises, but many hints.
- http//jakarta.apache.org/taglibs/ ? Standard
- 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!
28JSP/JSTL future
- Finalize JSTL
- JSP 1.3
- Universalize expression language
- Support creation of tags in JSP itself
- Works nicely with JSTLs focused tags
- Books, educational materials on JSTL to assist
page authors (and us developers vicariously).
29Yale 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
30Yale example Netreg
- HTML, JSP code produced and maintained by
nonprogrammers - Application uses early-access standard plus
locally written tags.
31Yale example Netreg
- Example code
- Retrieve full name from database
-
- var"name netidnetid"/
- Conduct CAS authentication
-
- Discover Ethernet address
- onError"discoveryFailed.jsp"/
32Yale example Netreg
- Custom registration tags documented, available
to page authors. - Via attributes, the data these tags expose is
accessible to JSTL tags.
33Yale 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.
34Yale example XML/XPath
- com/"/
-
-
-
- select"dom//a_at_class'leadheadline/
- Sample XML
-
-
- Headl
ine -
35Advantages of JSTL XML/XPath support
- Why not always use XSLT?
- JSTL provides XPath support but doesnt 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.
36Summary
- 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
37URLs
- 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
- mailtojsr052-comments_at_sun.com
- My upcoming JSTL books site
- http//www.jstlbook.com/
- My email address
- mailtoshawn.bayern_at_yale.edu