SCWCD - JSP Presentation
SCWCD - JSP Presentation
1
10/12/2003
Sang Shin
[email protected]
www.javapassion.com/j2eeadvanced/
2
10/12/2003
3
10/12/2003
Revision History
? 10/13/2003: version 1: created by Sang Shin
4
10/12/2003
Agenda
? Focus of JSP 2.0 technology
? Examples of syntax
? Exploration of new features (with
examples)
– Integrated expression language
– Simple tag extensions
– Tag files
– Improved XML syntax
– Other features
5
10/12/2003
M
I
D
D = Basic Knowledge = Expert
L
E
6
6
10/12/2003
<html>
<body>
<util:getShoppingCart var="cart" />
<table>
<% for( int i = 0; i < cart.size(); i++ ) {
CartItem item=(CartItem)cart.get(i);
%>
<tr>
<td><%= item.getName() %></td>
<td><%= item.getPrice() %></td>
</tr>
M
I
<% } %>
D
D
</table>
L
E
</body>
7
</html>
7
10/12/2003
8
10/12/2003
9
10/12/2003
Integrated
Expression Language
10
10
10/12/2003
Integrated Expression
Language
? Based on “SPEL” from JSTL 1.0
? Example: ${item.price}
? Recognized by JSP container in:
– Template text
– Attributes of any standard or custom action
? Programmatic access via javax.servlet.jsp.el
? Support for custom EL functions:
– Extensible via tag libraries
– Example: ${fn:allCaps(lastName)}
M
I
D
– JSTL 1.1 provides 16 standard EL functions
D
L
E
11
11
10/12/2003
Integrated Expression
Language Example
? Using scriptlets:
<center>
<jsp:useBean id="foo" class="FooBean" />
<%= foo.getBar() %>
</center>
M
<center>
I
D
${foo.bar}
D
L
</center>
E
12
12
10/12/2003
Integrated Expression
Language Example
? Using scriptlets:
13
10/12/2003
14
14
10/12/2003
15
10/12/2003
tag body
</my:repeat> BodyTag IterationTag
TagSupport
int doStartTag() {
b BodyTagSupport
this.count = this.num;
Implementation
return Tag.EVAL_BODY_INCLUDE;
} RepeatHandler a
setNum()
int doAfterBody() { c doStartTag()
this.count--; doInitBody()
M
I
return (this.count > 0) ? doAfterBody()
D Tag.EVAL_BODY_AGAIN : d
D doEndTag()
L
E
Tag.SKIP_BODY;
16
}
16
10/12/2003
uri="/mytags" %>
<my:repeat num ="3"> SimpleTagSupport
tag body
</my:repeat>
RepeatHandler
setNum()
doTag()
void doTag() {
Implementation
17
10/12/2003
Tag Files
18
18
10/12/2003
Tag Files
? Quickly write tag extensions using JSP
syntax!
? JSP : Servlet :: Tag File : Tag Handler
? Empowers page authors
? Faster round-trip development
? Simple yet flexible packaging
– Just drop a .tag file in /WEB-INF/tags/
– Implicit tag library automatically generated
M
– Or, write a .tld for added flexibility
I
D
D
– Or, package in a JAR with a .tld
L
E
19
19
10/12/2003
tagdir="/WEB-INF/tags/" %>
<my:repeat num ="3">
tag body
</my:repeat>
20
10/12/2003
21
Tag file concept is introduced in JSP 2.0. Tag file is tag handler
implementation in JSP syntax as opposed to using Java programming
language.
21
10/12/2003
Improved
XML Syntax
22
22
10/12/2003
23
10/12/2003
Other Features
24
24
10/12/2003
Other Features...
? Central configuration via url-patterns
– Map extensions other than .jsp
– Enable / disable scriptlets or EL globally
– Control page encoding globally
– Preludes / codas
? Portable debugging support through JSR-45
? Dynamic attributes
? Enhanced I18N support
M
I
? Fragment attributes
D
D
L
E
25
25
10/12/2003
Resources
26
26
10/12/2003
Resources
? [1] Java Web Services Developer Pack Tutorial
– java.sun.com/webservices/downloads/webservicespack.html
– java.sun.com/webservices/downloads/webservicestutorial.html
? [2] More Servlets and JavaServer Pages (written
by Marty Hall)
27
27
10/12/2003
28
28