1. JavaServer Pages™ /Servlets
and Web Application Frameworks
Doris Chen, Ph.D
Staff Engineer This box provides
space for call to
Sun Microsystems, Inc action text, URLs,
or any relevant info
2. Speaker’s Qualifications
● Doris Chen
– Technology Evangelist at Sun Microsystems
– Develops and delivers Code Camps for
J2EE, Java performance tuning, J2ME and web
services technologies for Sun Microsystems
– Speaks around the world concerning
Sun™ technologies
4. How It Fits Together
JSF S1AF
JSTL
Struts
JSP™
java bean, expression
lang.,custom tag lib
Servlet
session tracking, filtering, listener
5. Web Foundation: JSP™/Servlets
● Java Servlet technology since ’96, JSP 1.0
specification in June ’99
● Servlets and JSP technologies:
• JSP 1.2 and Java Servlet 2.3 technologies in the J2EE
1.3 platform (now)
• JSP 2.0 and Java Servlet 2.4 technologies in the J2EE
1.4 platform (proposed final draft)
6. Java Servlet Technology
● Foundation for many technologies
• The JAX-RPC API
• Java portlet technology
• The JAXM API
• Struts, JavaServer Faces™, Sun™ ONE application
framework
● Well understood by industry
7. The JavaServer Pages™
(JSP™) Specification
● JavaServer Pages technology: Building
Block
● Mature spec
● Widely Used
● Many uses of Tag Libraries
● Very good community, look for the
JSP 2.0 release
11. Jakarta Struts
● Struts is an open source framework developed
by the Apache Jakarta project
http://jakarta.apache.org/struts/
– Struts 1.02 is available and Struts 1.1 is in beta
● Struts allows:
– JSP/Servlet developers to fashion their web applications
using the MVC design pattern
– Configure a lot of the default framework objects through
xml configuration files
– Run Servlet2.2/JSP1.1 container and above
12. Model-View-Control (model 2)
MVC Design Pattern
1
Request
(Controller)
Servlet
BROWSER
In
Redirect 3
st
2
an
tia
te
5 (View) (Model)
Java Bean
Response JSP 4
Servlet Container (EIS)
13. Struts: MVC Pattern Implemented
Controller
Model
Action Action
Mapping Action
Servlet
Request (xml)
Client
uses
Response
Action Action
JSP View
Forward Form Model Data
View
14. Struts Components and
Feature
● The View - a JSP or HTML page
● The Model - a Java object ( called a
ActionForm)
● Central controller – ActionServlet
• URI to ActionMapping(Action class) located in struts-
config.xml file
• Action classes
• Adaptors between business layer and web tier
● Validation, Internationalization, Custom
tags for creating HTML, presentation logic,
and templating
15. Model
● Model classes should be coded independent
of the Struts framework
– Maximum code reusability by other applications
● Struts provides default Model components,
most important one ActionForm
• Create model class by extending the Struts
ActionForm class
● Struts provides a org.apache.struts.util.PropertyUtils
has a static method called copyProperties()
– To copy all form properties to your original model
object when your controller receives a form
16. Controller
● The controller is the switch board of MVC
● Directs the user to the appropriate views by
providing the view with the correct model
● The task of directing users to appropriate views
is called “mapping”
● Struts framework provides a base object called
org.apache.struts.action.ActionServlet
17. Controller (Cont.)
Http://myhost/authorize.do
Server configured to pass *.do extensions to
org.apache.struts.action.ActionServlet via a web.xml configuration file
ActionServlet object inspects the URI and tries to match it
against an ActionMapping located in the struts-config.xml file
Instance of appropriate Action class is found and it’s perform() is called
Action object handles the request and returns control to a view
based where the user is within the flow of the application
19. View
● ActionForward object tells JSP page to dispatch
to
● The view in Struts is represented by JSP
● JSP can use ActionForm bean to get output
Model data to display
● Struts contains a series of tag libraries
– Facilitates communication between HTML designers
and developers
– Facilitates dynamic Web content
21. Struts Example
Page 1 Jsp 1 Jsp 2 Jsp 3
Web Browser
Web Server
Form Request/session View
Jsp Engine Bean Form
1 Bean Other
Layer
2 Bean
1
Controller
Struts-
config.
xml
Mappings
• path Action1 Action2 Action3 Action4
• action .java .java .java .java
• [form bean]
• [forwards]
Business
Business Business Business
Bean 1 Bean 2 Bean 3 Logic
Layer
CoreSession CoreSession Socket
Data
MarkVision Server Layer
29. Key JSF Concepts
● UIComponent – JavaBean like classes
─ Render-independent characteristics
─ Base class with standard behaviors
● Standard UIComponent Subclasses:
─ UICommand, UIForm, UIGraphic, UIInput, UIOutput, UIPanel,
UISelectBoolean, UISelectMany, UISelectOne
● FacesEvent – Base class for request and
application events
● Validator – Base class for standard and
application defined validators
30. Key JSF Concepts
● Converter – Plug-in for String-Object
conversion
● FacesContext – Per-Request State:
─ Servlet request, response, session
─ JSF request, response trees
─ Model reference expression evaluators
• Syntax similar to the expression language of the JSP
Standard Tag Library (JSTL) 1.0
• Primary interface between components and the data
provided by (or to) the application
31. Key JSF Concepts
● Renderer – Converts components to and
from a specific markup language
─ Supports render-dependent attributes on
components
─ May support more than one component type
● RenderKit – Library of Renderers
─ Extensible at runtime
─ Basic HTML RenderKit is part of the specification
33. Component Tree
HelloForm
Input Form
text UserName Submit event
Stored Queued
34. Steps in Development Process
● Author the pages using the UI component
tags
• useBean tag
• faces tags:
• faces:form, faces:textentry_input, faces:command_button
● Develop the model objects, which will hold
the data
● Develop navigation handlers
• Define the navigation for the application by
implementing ApplicationHandler class
35. Current Development Status
● Warning – everything above is subject to
change!
● Under development in JSR-127
─ Introduced at JavaOne US 2001
● Large expert group
─ Framework developers, Tools providers, ISVs
● Completed Community Draft status (07/2002)
● Working towards Public Draft release of
specification
36. Current Development Status
● Early Access of Reference Implementation
is also available
● Early Access (pre-Public Draft) Specification
available:
• http://java.sun.com/j2ee/javaserverfaces/
● JSF Public Forum:
• http://forum.java.sun.com/forum.jsp?forum=427
● JSF Comments: jsr-127-
comments@sun.com
● Intranet Site:
http://wspack.sfbay.sun.com/jsf
37. If You Only Remember One
Thing…
● JavaServer Faces is destined to become the
standard mechanism for creating user
interface components for J2EE based web
applications.
39. Sun™ ONE Application
Framework (JATO) Overview
● A J2EE application framework
• Primarily focused on web tier
• Leverage Sun Java Center J2EE Patterns
● Provide a robust, scalable application
foundation
• Application composition via reusable components
• Full-featured event model and high-level tag library
● SOAP & Web Services support / integration
● Leveraged through Sun ONE Studio Wizard-
based visual interfaces
40. Where can the Sun ONE
Application Framework be used?
● Enterprises or ISV's building large
enterprise web applications
● Large development team (10+) focused on
web applications
● Few really know Java APIs at the web tier
or enterprise tier
43. J2EE Design Pattern
● Leverage Sun Java Center J2EE Patterns
• Best practice design patterns for J2EE
development
• Fine grained patterns
• Can be combined into a complete MVC
● Use Model View Controller pattern
(MVC)
44. J2EE patterns used in S1AF
● Business delegate
● View helper
● Composite view
● Service to worker
● Front controller
46. Models
● Implements Business Delegate pattern
– Reduce coupling between presentation tier clients and business
services
– Hides the underlying implementation details of business service
(e.g. JDBC details)
● Provides developers a common interface for using any
Enterprise resource
– Web Service resources
– Database resources
– UIF (Enterprise Connectors) resources
– J2EE Connector Architecture resources
– AND 3rd party created
47. Views
● A union of JSP tags with S1AF view objects
– S1AF JSPs use S1AF tags and othe 3rd party tags
– S1AF views simply refer to model data
● Implements J2EE view helper pattern
– S1AF views allows JSPs to remain Java-free
– Presentation logic is placed in View class
– More than one JSP can use a View Helper
• Allows for variable content rendering
● Implements J2EE Composite View Pattern
– S1AF view may be arbitrarily nested
49. Controller
● Consistes of two patterns
– Front controller
– Service to workers
● Implements front controller pattern
– All requests pass through front controller
– Module servlet serves as front controller
– Single point of entry allows for centralization
of certain types of logic
50. Controller (Cont.)
● Implements ServiceToWorker pattern
– Single service dispatches to request specific
controllers(workers)
• All requests pass through the FrontController
• Controller logic can be partitioned into more fine
grained units for scalability and logical partitioning
– S1AF module servlet dispatches request to
the appropriate worker (controller)
• S1AF controller can be a Command interface
• Developers will implement the command interface
52. View Components
● “ Out of the box” Page components are available such
as Button, Check Box, Combo Box
● 3rd party (SI’s) components can be dynamically added
to the product
59. JSF, Struts and S1AF
● Focus is a bit different
– Struts: encapsulates user-interface more at form or page level
– JSF: UI components, component model for user-interface, Tools
focus
– S1AF: extends MVC and J2EE design pattern and comes with an
extendable but ready-to use base implementation, visual builder
tool
● Some overlap
– Use the parts that are helpful, ignore the parts that are not
– Pick solution best suited to expertise/task
– JSF/Struts integration
http://jakarta.apache.org/builds/jakarta-struts/nightly/struts-
faces/
60. JSF, S1AF, and Struts
● All three communities are represented on
JSR-127 expert group
– The lead developer of Struts, Craig McClanahan, now
works for Sun and is a member of JSF expert group
– S1AF Architect is already participating in expert group
meeting
– Long term strategy:
● S1AF and struts will co-exists/merge with S1af evolving to
use struts controller technology and JSF components
● Goal is to provide a single web-based framework also
monetizes struts technology
61. Where to look further
● JSF
http://java.sun.com/products/j2ee/javaserverfa
● Struts http://jakarta.apache.org/struts
● A good place to start is the S1AF-Tips group:
http://groups.yahoo.com/group/iPlanet-JATO-
Tips/
● FAQ of the larger community forum at:
http://groups.yahoo.com/group/iPlanet -JATO/
● The Whitepaper: http://ias.red.iPlanet.com/jato
● You can get more information at:
http://developer.iPlanet.com/tech/appserver/fr
amework/index.jsp