Beruflich Dokumente
Kultur Dokumente
Who I Am
Hans Bergsten
hans@gefionsoftware.com President of Gefion software Member of the JSP working group (JCP) Author of JavaServer Pages (OReilly)
2001-07-25
Overview
JSP Background Processing and Basic JSP 1.1 Elements Extension Framework/Custom Tags Flow Control and Scopes Java 2 Enterprise Edition (J2EE) Future Direction
2001-07-25
Background
Servlets part of JavaWebServer, 1997 Formalized as Servlet 2.1, Nov. 1998
2001-07-25
2001-07-25
Background
Servlets part of JavaWebServer, 1997 Formalized as Servlet 2.1, Nov. 1998 JHTML, HTML with Java code snippets JSP 1.0, June 1999 JSP 1.1, December 1999
2001-07-25
2001-07-25
JSP Elements
Directives: <%@ dirname attr=value %> Actions: <pref:name attr=value /> Scripting:
Scriptlet: <% scripting code %> Expression: <%= expression %> Declaration: <%! declaration %>
2001-07-25
JSP Processing
hello.jsp read request response Web Server/ Web Container generate hello.java compile
execute
hello.class
2001-07-25
10
2001-07-25
11
Directive Elements
page: Page-dependent attributes
contentType, errorPage, buffer
2001-07-25
12
Directives Example
<%@ page contentType=text/html %> <%@ include file=header.jsp %> <h1>Hello World!</h1> <jsp:useBean id=date class=java.util.Date() /> Its <%= date %> <%@ include file=footer.jsp %>
2001-07-25 GWDC: JavaServer Pages (JSP) Introduction 13
Action Elements
useBean: Declare a bean getProperty: Add property value to page setProperty: Set property value include: Include response from page forward: Continue processing at page plugin: Add HTML for Java Plugin
2001-07-25
14
JavaBeans Model
A thing with public properties A JavaBeans component is a regular Java class Naming conventions for property access methods
2001-07-25
15
useBean Example
<jsp:useBean id=user class=com.foo.UserInfoBean />
2001-07-25
17
setProperty Example
<jsp:setProperty name=user property=firstName value=Hans /> <jsp:setProperty name=user property=* /> <jsp:setProperty name=user property=firstName param=fName />
2001-07-25
18
getProperty Example
<jsp:getProperty name=user property=firstName />
2001-07-25
19
include Example
<jsp:include page=foo.jsp flush=true> <jsp:param name=user value=Bob /> </jsp:include>
2001-07-25
21
2001-07-25
22
Action
In the request phase Response added to including pages response
2001-07-25
23
Scripting Elements
Scriptlet: <% scripting code %> Expression: <%= expression %> Declaration: <%! declaration %>
2001-07-25
25
Scriptlet Example
<% if (user.isValid()) { %> Do something <% } else { %> Do something else <% } %>
2001-07-25
26
Expression Example
First Name: <%= user.getFirstName() %> 1 + 1 = <%= 1 + 1 %>
2001-07-25
27
Declaration Example
<%! int pageCounter = 0; %> <% int requestCounter = 0; %> <h1>Counters</h1> Instance variable counter: <%= pageCounter++ %> Local variable counter: <%= requestCounter++ %>
2001-07-25 GWDC: JavaServer Pages (JSP) Introduction 28
2001-07-25
29
2001-07-25
30
2001-07-25
31
2001-07-25
32
Custom Actions
Used the same as standard actions Regular Java classes; JavaBeans with a few extra methods Invoked automatically by the container Access to request and application data Reduces the need for scripting code!
2001-07-25
33
2001-07-25
34
2001-07-25
35
MVC Pattern
Model: business data and logic View: users view of business data Controller: user interaction
2001-07-25
36
2001-07-25
37
input.jsp View
process.jsp Controller
confirm.jsp View
Model
UserInfoBean
2001-07-25
38
UserInfoBean
2001-07-25
39
forward Example
<%@ taglib uri=/foolib prefix=foo %> <foo:ifEq name=user property=valid value=true> <foo:save name=user /> <jsp:forward page=confirm.jsp /> </foo:ifEq>
2001-07-25 GWDC: JavaServer Pages (JSP) Introduction 40
Request Scope
input.jsp
process.jsp
confirm.jsp
Session scope
prodlist.jsp
addtocart.jsp
cartcontents.jsp
Application scope
prodlist.jsp
addtocart.jsp
cartcontents.jsp
Session scope
45
Database
Client Tier
2001-07-25
Middle Tier
EIS Tier
46
EJB
2001-07-25
47
Future Direction
JSP 1.2/Servlet 2.3
include without flush Listeners Filters Custom tag development enhancements
More Info
JSP Specification
http://java.sun.com/products/jsp/
InstantOnline Basic
http://www.gefionsoftware.com/InstantOnline/
2001-07-25 GWDC: JavaServer Pages (JSP) Introduction 49