using jsp 2.0’s new features shawn bayern research programmer, yale university jstl...

68
Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development with JavaServer Pages

Upload: maude-matthews

Post on 30-Dec-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Using JSP 2.0’sNew Features

Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action

Web Development with JavaServer Pages

Page 2: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSTL in Action

“A nicely written book...beginner-friendly on all levels... It will be a long time before I forget the author's definition of ‘scope’ that compared it to flying rats... The words ‘in action’ in the book’s title aren’t just words, it’s a methodological principle. The discussion concentrates on practice rather than theory and specifications.”—JavaRanch.com

Page 3: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSTL in Action

“The jokes seem inappropriate.” — Internal reviewer

Page 4: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

“Regime Change” for JSP

Four key questions to answer today:

What justifies JSP 2.0?

What are its major new features?

What is JSTL?

What do these new technologies suggest about development patterns and best practices?

Page 5: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Crash course on the J2EE Presentation Tier

Your application

Java language

Java Servlet API

JavaServer Pages (JSP)

JSTL

Yourweb pages

Page 6: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Crash course on the J2EE Presentation Tier

J2EE

JSP

JSTLServlets

Current standards:JSP 1.2Servlet 2.3JSTL 1.0

In a few months:JSP 2.0Servlet 2.4JSTL 1.1

JSTL

Page 7: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

More details about scheduling JSP 2.0 is currently in Proposed Final Draft

(PFD) JSP 2.0 PFD2 (second draft) is planned for

January 2003. JSP 2.0, JSTL 1.1, Servlet 2.4 released with

J2EE 1.4 (probably a few months from now)

JSP 1.2

JSTL 1.0

(JSP 2.0 PFD)

As of today A few weeks

(JSP 2.0 PFD2)

A few months

JSP 2.0

JSTL 1.1

Page 8: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

What kinds of things go in JSP pages?

Scriptlets

<%

getFoo(request);

printFoo(out);

String a = ”username”;

%>

<% if (a.equals(”pig”) {%>

Oink!

<% } %>

Java (and more?) embedded within template text

Access to implicit objects: request, response, etc.

Conditional blocks, loops—manually constructed

Page 9: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

What kinds of things go in JSP pages?

Tag libraries

<foo:bar/>

<c:if test=”${c}”>

c is true

</c:if>

<c:forEach>

Round and round we go

</c:forEach>

XML tags Invoke Java logic

behind the scenes. May access body, e.g.,

for iteration, conditional inclusion—or just as arbitrary parameter

May access PageContext

Libraries and prefixes

Page 10: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Question 1

Why JSP 2.0?

(Or, what’s wrong with the current version of JSP?)

Page 11: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Why we like JSP in the first place ()

Open standard with support from many vendors

The performance and scalability of servlets (for JSP pages compile into servlets)

Extensibility (custom tags) Easy integration with other J2EE and

Java technologies (Servlets, EJB)

Page 12: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

What’s irritating about JSP?

() The tag-extension protocol is too

complicated

Tag handler

doStartTag() doEndTag()

doCatch() doFinally()

doInitBody() doAfterBody()

release()

Too hard for

Gosling, even?

Page 13: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

What’s irritating about JSP?

() Also, tags don’t support certain kinds

of code reuse.

<font color=”<%=statusColor%>”>

<% for (…) { %>

<%= customer %>: <%= hatSize %>

<% } %>

</font> out.println(…);

for(…) {

out.println(…);

}

Page 14: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

What’s bad about JSP? ()

The general consensus says…

Scriplets

They complicate abstraction and code reuse.

They make it harder for nonprogrammers to maintain pages

Page 15: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Question 2

What new features does JSP 2.0 offer?

(Or, how does it fix the issues we just raised?)

Page 16: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

How does JSP 2.0 address these issues?

Expression language (EL) Tag files Simplified Tag API (SimpleTag versus Tag) Improved XML syntax

Also, though it’s not really part of JSP,JSTL improves things too.

The end result:

JSP pages become easier to write and maintain.

Page 17: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

The JSP Expression Language (EL): Goals and principles

The major goal: simplicity. The language should be usable by

nonprogrammers. Inspirations: JavaScript, XPath

But it’s much simpler than even these basic expression languages.

• Quick: what does //foo = ‘bar’ mean in XPath?• Or what happens with age + 3 in ECMAScript?

Page 18: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

How easy is XPath?

//foo=’bar’ <a> <b> <c> <foo>hmm</foo> </c> <d> <foo>bar</foo> </d></a>

Page 19: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

XPath (//foo = ‘bar’)

“If one object to be compared is a node-set and the other is a string, then the comparison will be true if and only if there is a node in the node-set such that the result of performing the comparison on the string-value of the node and the other string is true.”

Page 20: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

How easy is XPath?

//foo=’bar’ <a> <b> <c> <foo>hmm</foo> </c> <d> <foo>bar</foo> </d></a>

True!

Page 21: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

ECMAScript (age + 3)

Page 62 of 188:

The Addition operator ( + )The addition operator either performs string concatenation or numeric addition.The production AdditiveExpression : AdditiveExpression + MultiplicativeExpression is evaluated asfollows:1. Evaluate AdditiveExpression.2. Call GetValue(Result(1)).3. Evaluate MultiplicativeExpression.4. Call GetValue(Result(3)).5. Call ToPrimitive(Result(2)).6. Call ToPrimitive(Result(4)).7. If Type(Result(5)) is String or Type(Result(6)) is String, go to step 12. (Note that this step differsfrom step 3 in the comparison algorithm for the relational operators, by using or instead of and.)8. Call ToNumber(Result(5)).9. Call ToNumber(Result(6)).10. Apply the addition operation to Result(8) and Result(9). See the note below (11.6.3).11. Return Result(10).12. Call ToString(Result(5)).13. Call ToString(Result(6)).14. Concatenate Result(12) followed by Result(13).15. Return Result(14).

29. One-half of self-employment tax. Attach Schedule SE.30. Self-employed health insurance deduction (see page 33)31. Self-employed SEP, SIMPLE, and qualified plans32. Penalty on early withdrawal of savings33. Alimony paid34. Add lines 23 through 33a35. Subtract line 34 from line 22. This is your adjusted gross income.

Page 22: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

The JSP Expression Language (EL): Key syntax Expressions appear between ${ and }.

Note that ${ and } may contain whole expressions, not just variable names, as in the Bourne shell (and its dozen derivatives.)

E.g., ${myExpression + 2}

Expressions’ default targets are scoped attributes (page, request, session, application) ${user} ≡ pageContext.findAttribute(“user”)

Page 23: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

The JSP Expression Language (EL): Key syntax The . and [] operators refer to

JavaBean-style properties and Map elements:

${user.getAddress} can resolve to ((User)

pageContext.getAttribute(”user”)).getAddress()

Note the automatic type-cast. This is one of the great features of the EL: users do

not need to concern themselves with types in most cases (even though the underlying types of data objects are preserved.)

Page 24: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

The JSP Expression Language (EL): advanced data access

Expressions may also refer to cookies, request parameters, and other data:

${cookie.colorPreference}${param.password}${header[“User-Agent”]}${pageContext.request.remoteUser}${initParam.databasePassword}

Page 25: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

The JSP Expression Language (EL): more syntax The EL supports

Arithmetic ${age + 3}Comparisons ${age > 18}Equality checks ${age = 55}Logical operations ${young or

beautiful}

Grouping ${(a+b) * c}Emptiness detection ${empty a}

• ‘a’ is empty String (“”), empty List, null, etc. Useful for ${empty param.x}

Page 26: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

The JSP Expression Language: Uses JSTL 1.0 introduced the EL, but it

could be used only within tags. In JSP 2.0, it can be used almost

anywhere

<font color=”${color}”> Hi, ${user}. You are <user:age style=”$

{style}”/> years old.</font>

Page 27: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

EL functions: new in JSP 2.0

The expression language does not support methods.Why not?

Instead, it lets you register static functions in a tag-library descriptor (TLD)

Page 28: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Registering an EL function

<taglib> ... <function>

<name>isNejugMember</name><function-class>

org.nejug.Util </function-class>

<function-signature>Boolean isNejugMember(String)

</function-signature> </function></taglib>

public static Boolean isNejugMember(String x);

Page 29: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Using an EL function

${myLib:isNejugMember(user)}

<myLib:printStatus

member=”${isNejugMember(user)}”

/>

Page 30: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

EL API

JSTL 1.0 introduced the EL, but not a standard API to access its interpreter.

JSP 2.0 offers standard API under javax.servlet.jsp.el package.

Uses: JavaServer Faces; open-source projects; your own products.

Page 31: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Tag Files: nature and purpose

Solve difficulty of reusing text/HTML within a tag.And makes it much easier to write

simple tags, since you can do so in JSP instead of Java.

Stand-alone file with <%@ tag %> directive instead of traditional <%@ page %> directive.

Page 32: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

The role of tag files

JSP Page

.jsp

<%@ page %>

Servlet

JSP tag file

.tag

<%@ tag %>

Tag-handler class

Page 33: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSP 2.0 tag files<%@ tag name=”tableTag” %><%@ attribute name=”items” %>

<table width=”…” bgcolor=”…”> <th> <td>Name</td> <td>IQ</td> </th> <c:forEach var=”i” items=”${items}”> <tr> <td>${i.fullName}</td> <td>${i.IQ}</td> </tr> </c:forEach></table>

Page 34: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Using the new tag…

Your shopping cart:

<my:tableTag items=”${cart}” />

Your wish list:

<my:tableTag items=”${wishList}” />

Things we want you to buy:

<my:tableTag items=”${pressuredSales}” />

Page 35: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Tag-file directives

<%@ tag %>Just as boring as <%@ page %>Primarily for bookkeeping, tool supportE.g.,

• description, large-icon, small-icon• isScriptingEnabled• isELEnabled

Page 36: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Tag-file directives

<%@ attribute %>Declares attributes for the tag you’re creating

Provides support for “fragments”• Like Dynamo’s “OPARAMS” (ATG)

<%@ attribute name=“foo” required=“true” rtexprvalue=“false” %>

<%@ attribute name=“foo” fragment=“true” %>

<jsp:invoke fragment=“foo”>

<jsp:param name=“userLevel” value=“expert” >

</jsp:invoke>

Page 37: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Using fragments

<myTag:printTable data=“${myData}”> <jsp:attribute name=“tableSeparator”> <c:if value=“${param.browserType eq ‘textOnly’}”> - - - - - - - </c:if> <c:if value=“${param.browserType eq ‘fullHtml’}> <hr /> </c:if> </jsp:attribute> …</myTag>

Page 38: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Old tag handler

Tag handler

doStartTag() doEndTag()

doCatch() doFinally()

Tagattributes

Tagbody

doInitBody()

doAfterBody()

release()

Page 39: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

SimpleTag handler

Tag handler

Tagattributes

Tagbody

(no scriptlets)

doTag()

Page 40: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Using SimpleTag

Examplepublic class MyTag extends SimpleTagSupport {

public void doTag() {

JspWriter out = getJspContext().getOut();

out.println(”My body is…”);

out.print(getJspBody());

out.println(”attribute=” + attribute);

}

public void setAttribute(String x) { this.attribute = x};

}

Page 41: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Other changes to tag-extension API Dynamic attributes

Ideal for tags that “wrap” other tags, such as HTML tags

How to use• Implement DynamicAttributes interface• Define

public void setDynamicAttribute(String uri, String localName, Object value)

to accept the attributes, and do whatever you want with them.

Page 42: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSP 2.0: Improved XML syntax

Old style: JSP as document

New style: JSP as namespace

<jsp:root>

xmlns:jsp=“http://java.sun.com/JSP/Page”

Page 43: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Question 3

What is JSTL? What features does it offer?

Page 44: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSTL design principles

JSTL 1.0 / 1.1: Keep it simple! Targeted tags

Could have a single <go> tag:• <go action=“forEach” argument1=“$

{myData}”>Instead, single-purpose tags, tightly

focused Design intended for page author

Perhaps something of a fantasy, like the legal “reasonable person.” But a helpful guide nonetheless.

Page 45: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

The parable of Mike and Phillipe

Mike Phillipe

Credit: Pierre Delisle (spec lead)

Page 46: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSTL 1.0 features

Control flow Iteration, conditions

URL management Retrieve data, add session IDs

Text formatting and internationalization Dates and numbers Localized messages

XML manipulation XPath, XSLT

Database access Queries, updates

Page 47: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSTL 1.0 libraries

Library features Recommended prefix

Core (control flow, URLs, variable access)

c

Text formatting fmt

XML manipulation x

Database access sql

Page 48: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSTL features:managing variables Outputting values with EL

<c:out value=”${user.IQ}” />

Storing data<c:set var=”user” scope=”session”> // arbitrary text</c:set>

Note the use of “var” and “scope”: a JSTL convention

Page 49: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSTL features:iteration Iteration

<c:forEach items=”${list}”begin=”5” end=”20”

step=”4”var=”item”>

<c:out value=”${item}”/></c:forEach>

“paging”

Page 50: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSTL features:conditional logic Conditional evaluation

<c:if test=”${a == b}”> a equals b</c:if>

Mutually exclusive conditionals

<c:choose> <c:when test=”${a == b}”> a equals b </c:when> <c:when test=”${a == c}”> a equals c </c:when> <c:otherwise> I don’t know what ’a’

equals. </c:otherwise></c:choose>

Page 51: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSTL features:URL management Retrieving data<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

Printing URLs<c:url value=”/foo.jsp”>

Redirection<c:redirect url=”/foo.jsp”>

Page 52: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSTL features:text formatting Locale-sensitive formatting and parsing

Numbers Dates

Internationalization Message bundles

Message argument substitution “Hi {0}. I would like to {1} your money today.

I will use it to buy myself a big {2}.”

<fmt:formatNumber type=“currency” value=“${salary}” />

<fmt:message key=“welcome” />

Page 53: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSTL features:XML manipulation Use of XPath to access, display

pieces of XML documents

<c:import url=”http://www.cnn.com/cnn.rss” var=”cnn”/><x:parse xml=”${cnn}” var=“dom”><x:out value=”$dom//item[1]/title”/>

Chaining XSLT transformations

<x:transform xslt=”${xsl2}” /> <x:transform xml=”${xml}” xslt=”${xsl}” /></x:transform>

Page 54: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Advantages of JSTL XML/XPath support Why not always use XSLT?

JSTL integrates XPath with 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.

• Functional versus imperative programming

Page 55: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSTL vs. XSLT example

<title><x:out select="."/></title><summary><%-- Retrieve and print the article lead --%><c:set var="articleURL"> <x:out select="./@href"/></c:set><c:import var="articleText" url="$

{articleURL}"/><x:parse … /><x:out … /></summary>

Page 56: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSTL features:database manipulation Queries (and ResultSet caching)

Updates / inserts Transactions (<sql:transaction>) Parametric (PreparedStatement) argument

substitution (<sql:param>) DataSource-based connection management

<sql:query sql=“SELECT * FROM USERS” var=“result” />

<c:forEach items=“${result.rows}”> … </c:forEach>

Page 57: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

SQL tags: the debate

Taglibrary

JSPpage

Back-endJavacode

DatabaseTag

library

Page 58: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

SQL Tags:The expert group’s conclusion SQL tags are needed because…

many nonstandard offerings existit is not JSTL’s role to dictate a choice of

framework• As popular as MVC is, it’s not universal.• Even in an MVC application, not all data is worth

handling carefully.prototyping is importantusers ask for it!

The JSTL specification recommends avoidance of SQL tags in large applications.

Page 59: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

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()

Still, JSP 2.0 is probably easier.• Ugly JSP 1.1 tag protocol Ugly JSP 1.1 tag

protocol with assistance from JSTL 1.0 Nice JSP 2.0 tag protocol.

Page 60: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSTL programmer support

JSTL API allows registrations of defaults…DataSourceLimit on size of resultsLocalization context (Locale, etc.)Time zone

Page 61: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Question 4

How do the technologies work together?

Page 62: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

“Models” of JSP development Origin of the terms “model 1” and “model 2.”

JSP 0.92 spec: “You can apply the JavaServer Pages technology in two ways . . . Model 1: A request sent to a JavaServer Pages file. . . . Model 2: A request sent to a Java Servlet.”

Page 63: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

JSTL works with either model

Core tags, formatting tags are ideal for applications that use either model.

XML-manipulation tags are on the borderline. Ideally, they pull data out of XML files that servlets or other back-end logic sends them.

SQL tags are probably most useful in model-1 applications.

Page 64: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Simple “model 2” example

public void doGet(HttpServletRequest request

HttpServletResponse response) {

// business logic that results in object ’data’

request.setAttribute(”d”, data);

sc.getRequestDispatcher(”/view.jsp”);

}

view.jsp

We have some data to display: <b>${d.property1}</b>

• In this case, the data passed is a simple bean-style object. It could also be an XML document; we’d then use JSTL’s XML-manipulation tags.

Page 65: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Transferring data

Use XML documents (i.e., DOM objects) and the JSTL <x:*> tags

Use JavaBean-style classes

public class MyData {

public String getCustomerName() { return X; }

public Date getCustomerBirthday() { return Y; }

}

${myDataInstance.customerName}

Page 66: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Summary. Or, what’s new?

This was all possible before. What are the benefits of the newer standards and technologies?Easier developmentEasier debuggingEasier maintenanceEasier reuse

Page 67: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

URLs

Official JSTL site (spec, implementations)http://java.sun.com/products/jstl

Quick JSTL referencehttp://www.manning.com/bayern/appendixA.pdf

Official JSP sitehttp://java.sun.com/products/jsp

JSP 2.0 JSR (spec currently in Proposed Final Draft)http://www.jcp.org/jsr/detail/152.jsr

JSTL in Actionhttp://www.jstlbook.com/

My email addressmailto:[email protected]

Page 68: Using JSP 2.0’s New Features Shawn Bayern Research Programmer, Yale University JSTL reference-implementation lead Author, JSTL in Action Web Development

Q&A

Syntax? Semantics? Other features?

Java Community Process procedures, anecdotes?

Future directions?