Introduction To Javaserver Pages Technology: Section 1. Tutorial Tips Should I Take This Tutorial?
Introduction To Javaserver Pages Technology: Section 1. Tutorial Tips Should I Take This Tutorial?
technology
Navigation
Navigating through the tutorial is easy:
Getting help
If you have questions as you go through this
tutorial, you can send them directly to the support
team.
Section 2. Overview
Introduction to JavaServer
Pages technology
In today's environment, most Web sites want to
display dynamic content based on the user and the
session. Most content, such as images, text, and
banner ads, is most easily built with HTML editors.
So we need to mix the "static" content of HTML
files with "directives" for accessing or generating
dynamic content.
Introduction to JavaServer
Pages technology(continued)
In this lecture, we'll talk about key aspects of
JavaServer Pages(tm) (JSP) technology. We'll
consider several key concepts as they apply to
JSP technology:
* Servlets
* JavaBeans(tm) components
* Syntax
Conclusion
In this overview, we learned that JavaServer
Pages technology provides server-side scripting
support for generating Web pages with combined
static and dynamic content.
Section 3. Servlets
You recall that JSP pages are text pages that have
all the information needed to generate servlets.
Security
There are a number of advantages for using
servlets rather than such related technologies as
CGI-based applications and proprietary Web
server extensions. Let's go over them, one by one.
Security (continued)
Servlets provide secure connections to the
back-tier with more control than previous
applications and may use native security features.
But the privileges of servlets can be restricted
using Access Control Lists that permit only certain
users or groups of users to have access to them.
Robustness
Rich application programming interfaces (APIs) are
available to Java programs, thus making it easier
to build sophisticated applications in a short length
of time. These APIs include connectivity services
to back-end services, such as:
Performance
Java servlets provide better performance than
CGI-based applications. CGI-based applications
require process creation overhead for each user
request.
Portability
Use of servlets increases portability. Servlet
technology replaces the family of server plugins
such as Netscape API or Gateway API, which are
not standardized like the JavaServer API.
Conclusion
In this section, we discussed what servlets are,
typical uses of servlets, and advantages to using
servlets.
Introduction
One of the most powerful features of JSP
technology is the ability to access reusable
components, such as JavaBeans components,
from within a JSP page.
Introduction (continued)
The reason to use JavaBeans components with
JSP pages is to separate code from layout. We've
discussed that concept already in the Overview.
You minimize the code on the JSP page by using
JavaBeans components.
Characteristics of JavaBeans
components
A JavaBean component is a reusable software
component that uses a standard "method" naming
convention. This gives JavaBean components
predictable behavior and makes tool-based
manipulation easy.
Characteristics of JavaBeans
components (continued)
Properties are the parts of a JavaBean. They might
be other Java objects, primitives. As we will see in
the next panel, properties of JavaBeans
components are defined by pairs of public getter
and setter methods.
Conclusion
In this section, we discussed what JavaBeans
components are, JavaBean properties, and the
advantages of using JavaBeans components with
JSP pages.
Section 5. Syntax
JSP directives
JSP directives set global values such as class
declaration, a method to be implemented, or output
content type. Directive syntax is shown on the left.
JSP declarations
Declarations define class-wide variables and
methods. Syntax for open tags and closing tags is
shown on the left.
JSP scriptlets
JSP pages use scriptlets to mark Java code
destined for the servlet. The syntax is shown on
the left. HTML tags, interleaved with JSP tags, are
copied unchanged to the HTTP response stream.
JSP expressions
An expression is a short-hand notation for a
scriptlet that outputs a value to the response
stream. When the expression is evaluated, the
result is converted to a string and displayed. The
syntax shown on the left means "take this
expression, convert it to a string, and write it out to
the browser."
Bean syntax
Finally, let's look at bean tags. We have a whole
topic on the use of JavaBeans components in JSP
pages. And you know from our Overview that we
want to clearly separate the work areas of page
authors and producers from the Java scripting
language programmers.
name is the value of the key used to look up the bean, for example, key-value for
getValue() or getAttribute().
varname is the name of the local variable that refers to the bean and is available for
use by scriptlets. If the varname attribute isn't specified, the value of the name attribute
will be used.
type is the Java language type of the JavaBean component being accessed. The
default type is java.lang.Object.
When introspect is yes, each property of the bean whose name matches the name of a
request parameter will have its setter method called to set the property value to the
value of the corresponding request parameter. The default value for introspect is yes.
If the scope is request, the bean is to be retrieved from request context using the
getAttribute() method. This is default scope. If the bean is created, it is stored in the
current request context. This is used when the bean only needs to be available for the
current HTTP request.
When session, the bean is retrieved from the current session using the getValue()>
method. If the bean is created, it is stored in the current session. This is used when the
bean may be needed in multiple HTTP requests.
beanName is the filename used to create a JavaBean from a serialized bean file.
Conclusion
In this section, we discussed JSP syntax for
directives, declarations, scriptlets, expressions,
and beans. We also reviewed the HTML template
tag.
Section 6. Lab
Colophon
This tutorial was written entirely in XML, using the developerWorks tutorial tag set. The tutorial is converted into a
number of HTML pages, a zip file, JPEG heading graphics, and a PDF file by a Java program and a set of XSLT
stylesheets.