JavaServer[tm] Pages Technology FAQs
- What is the latest version of the JavaServer[tm] Pages (JSP[tm]) Specification and where can
I find it?
- What is meant by the JSP and Java[tm] Servlet Reference Implementation?
- What tools are available for testing my JSP technology based applications?
- What tools are available for developing JSP technology based web applications?
- What commercially available tools are there for deploying
JSP
technology based web applications?
- Are there any JSP
tutorials available?
- Are there any training classes available?
- Is there a certification for developers using JSP technology?
- What other technical resources are available?
- How can I get technical support?
- What are the general design rules for creating a page
using JavaServer
pages technology (JSP
page)?
- What are the implicit objects provided by a JSP page?
- What is meant by Page beans, Session beans and Application
beans in JSP framework?
- What is the XML syntax of a JSP technology page element?
- What is a custom tag?
- What are Tag libraries and Tag Handlers?
- How can you set a cookie in a JSP page?
- How can we delete a cookie with JSP page?
- How can I avoid caching of JSP page by the browser?
- Can I include static files within a JSP page?
- Can I create dynamic GIFs using JSP technology?
- How to get a client address in a JSP page
- Are there any sample applications available that demonstrate
the correct use of JSP pages as web components?
We want to hear from you! Please send us your
FEEDBACK.
1. What is the latest version of the JavaServer[tm] Pages (JSP[tm]) Specification and where can I
find it?
The latest finalized release of the JSP specification is v1.2 which superceded
v1.1 of the JSP specification in the fall of 2001.
You can download v1.1 and v1.2 of the JSP specification
here.
Version 1.0 of the specification has been archived but is still available
for download here.
Back to Top
2. What is meant by the JSP and Java Servlet Reference Implementation?
A Reference Implementation is a fully implemented version of a given
specification. This applies not only to the JSP specifications but to many of
the other specifications published by Sun. It's both a proof-of-concept and
an operational definition of the Java servlet and JSP specifications. It can be used by developers of JSP
and Java Servlet applications for developing and testing their web applications.
For each version of the JSP specification there is also a Reference Implementation
that implements that specification.
The official Reference Implementation for versions 1.1 and 1.2 of the JSP
Specification is Tomcat which is produced and controlled by the
Apache Software Foundation
as part of the Jakarta Project.
The mission of the Jakarta Project is to "Provide commercial-quality
server solutions based on the Java Platform that are developed in an open
and cooperative fashion."
The 3.x versions of Tomcat implement the 1.1 version of the JSP (and Java
Servlet 2.2) specification while the 4.x releases support the JSP
1.2 specification (and Java Servlet 2.3).
To find out which are the latest versions of Tomcat, check
here.
The Reference Implementation for version 1.0 of the JSP specification is
the JavaServer Web Development Kit v1.0.1 which is available for download
from here.
the JavaServer Web Development Kit 1.0.1 is also the Reference Implementation for version 2.1 of the
Java Servlet Specification.
As the 1.0 specification has been superseded by the 1.1 Specification,
the JavaServer Web Development Kit has not been updated since October, 1999, so it's important to
read the release
notes
before using it.
Note: There is also a
Java Servlet Development Kit
which is the original Reference Implementation for version 2.1 of the
Java Servlet specification, but this does not include support for JSP technology.
Back to Top
3. What tools are available for testing my JSP technology based applications?
First, you'll need to decide on which version of the specification you
want to base your code as not all features are supported by all specifications.
Once you have done this you can decide on which Product or Development Kit
you will use to run and to test your JSP applications. There are several
options here including the JSP and Java Servlet Reference Implementations,
freely available products and commercially available products. For the
Reference Implementations see the "What is meant by the JSP and Java Servlet Reference Implementation?"
question in this set of FAQs.
The Orion Application Server
is free for development and for non-commercial deployment but isn't
OpenSource.
Orion Application Server
For commercially available products see the "What commercially
available tools are there for deploying JSP technology based web applications?"
question in this set of FAQs.
Back to Top
4. What tools are available for developing JSP technology based web applications?
There are several Integrated Development Environments (IDE) that
support the development of JSP
and Java Servlet technology based web applications. Listed below are some of the
most popular IDEs. Few, if any, support the JSP 1.2 specification at this
time.
Forte[tm]
for Java[tm]
Enterprise Edition v3.0
(Solaris[tm]
Operating Environment, Java platform, Linux and Win32)
Forte for Java Community Edition
v3.0
(Solaris[tm]
Operating Environment, Java platform, Linux and Win32)
JBuilder5 Professional
(Solaris Operating Environment, Linux and Win32)
WebGain VisualCafé Enterprise Edition
(Win32)
IBM VisualAge for
Java v4.0 Professional/Enterprise
(Win32)
Back to Top
5. What commercially available tools are there for deploying JSP technology based
web applications?
There are so many Application Servers on the market that it is impossible
to list them all but we'll do our best to keep this list growing by adding
new App servers as we learn about them. The following list is in alphabetical
order and the URLs they link to are the main sites for the vendor of the
product.
Allaire JRun
BEA Systems Web Logic Application Server
Borland Application Server
GemStone/J
HP Bluestone Total-e-Server
IBM WebSphere Application Server
iPlanet[tm] Application Server
Iona IPortal Application Server
Lutris EAS
(based on Enhydra)
SilverStream Application Server
Sybase EA Server
Orion Application Server
Persistence Powertier for EJB
Pramati Server
Secant ModelMethods Enterprise Server
Unify eWave Engine and eWave Studio
Versata Logic Server
Back to Top
6. Are there any JSP tutorials available?
Strangely, JSP technology tutorials are few in number although there are many books that
have been specifically written for developers JSP applications. The
Java Developer Connection[SM]
web site has a tutorial called
JavaServer[tm]
Pages fundamentals,
which covers the basics of JSP application development but doesn't
include anything on Tag Libraries. A Tag Libraries tutorial is available
from the JSP technology
Tag Libraries
page on the Java Developer Connection[SM] web-site although it's under the heading of "Java Software Tutorial". You
can download the PDF version of the tutorial from
here
(doesn't include the examples). This page also includes a link
to the Tag Libraries chapter of the book "Core Servlets and JavaServer Pages".
The J2EE[tm] Tutorial
also includes a section on JSP technology development and the deployment of web
components.
IBM also has a an
"Introduction to JavaServer Pages technology"
tutorial on their
DeveloperWorks
site.
Back to Top
7. Are there any training classes available?
Sun Educational Services (SunEd) offers several Instructor led and web-based
courses that either directly relate to JavaServer Pages technology or cover them within the
scope of the J2EE platform
or web technologies. Visit the SunEd web site at
http://suned.sun.com
and navigate to the country where you are located. There you can find
details of all of the Java technology courses available in your region.
Back to Top
8. Is there a Certification for developers using JSP technology?
Sun Microsystems has recently introduced the
Sun Certified Web Component Developer Certification for the J2EE platform.
The Sun Certified Web Component Developer Certification is aimed at developers who are developing web
components and applications using JSP, Java Servlet and Custom Tag Library
technologies. It covers the JSP 1.2 and Servlet 2.3 specifications. The certification
is open to people who already hold the Sun Certified Programmer for the
Java platform certification and consists of a single exam.
IBM has several IBM certifications that require knowledge of JSP technology
but are generally more focused on support for their VisualAge and WebSphere
products. You can find out more about the IBM certifications by visiting
their Application
Development Certification
web site.
Details of the Sun Certifications can be found
here
. In order to find out about Sun Certifications in your country got to
the Sun Educational Services web site at
http://suned.sun.com
and use the map to navigate to your local country site.
Also, there is the jCert[tm]
initiative which was founded in 1999 by many of the big names in Enterprise
Java application development. The aim of the jCert initiative is to promote common standards
for validating the skills of developers working with the Java platform.
Back to Top
9. What other technical resources are available?
Sun Microsystems are constantly producing new JSP technology related technical content.
Sun's web site has an entire section devoted to JavaServer pages technology.
Throughout the Internet, resources for JSP application development abound.
Each of the application server vendors have really good technical resources
for not only their products but for JSP technology in general. If you have
an application server specific problem it is always a good idea to visit
the vendors web site before posting to the
JavaServer pages forum.
TheServerSide.com
is an excellent J2EE[tm]
technology community that also has a forum on which you can discuss JSP technology
related issues.
The JavaWorld[tm]
publication consistently produces great JSP technology related technical articles
as well as covering all other aspects of Java technology. Visit their
"Enterprise JavaBeans[tm] "
section
here
.
Quasy H. Mahmoud has also produced an excellent series of articles on web
application development with JSP and XML technologies and these have been
published on Sun's Java Developer Connection[SM] web site. They are as follows:
Part 1: Fast Track JSP
Part II: JSP technology with XML in Mind
Part III: Developing JSP technology-based Custom Tags
Back to Top
10. How can I get Technical Support?
The Java technology-based Forums
are a great place to start for technical help. The forums form a large
community with a vast level of expertise on all areas of Java technology. If you have an issue
with a specific J2EE
application of supporting product and you are unable to get help
from the forums, then the best recourse is to visit the web site of the vendor
from whom you obtained your product. Sun Microsystems itself offers excellent
in-depth developer support programs at many different levels. For
more information about these offerings or to purchase support, please visit
the Sun Developer Connection program
web site.
Back to Top
11. What are the general design rules for creating a page using JavaServer pages technology
(JSP page)?
- JSP technology tags are case sensitive.
- Attribute values in tags always appear quoted ; either single
or double quotes can be used.
- Any white-space within the documentation is not significant.
- Spaces are NOT allowed between the equals sign& an attribute
value.
- The character "\" can be used as an escape character in a tag.
- URLs used in JSP technology pages follow Java Servlet conventions, and a URL
starting with a "/", called a context relative path, is interpreted with
reference to the web application to which the JSP technology page belongs.
- If the URL does not start with a "/" it is interpreted relative
to the current JSP technology page.
Back to Top
12. What are the implicit objects provided by a JSP page?
JSP technology
pages provide certain implicit objects, based on the Java Servlet API. These objects are
accessed using standard variables, and are automatically available for use
in your JSP technology page without writing extra code.
The implicit objects available in a JSP technology page are:
- The request object. This represents
an HTTP request and is an instance of javax.servlet.http.HttpServletRequest
. The request object represents the request
that triggered the sevice() invocation. It has
request scope.
- The response object. This represents
an HTTP response and is an instance of javax.servlet.http.HttpServletResponse
. It is legal to set HTTP status codes and headers in the JSP page once
output has been sent to the client. It has page scope.
- The pageContext object. This
represents the JSP technolgy page and is an instance of the page implementation class
that was generated by the JSP technology translator. It is of type
javax.Servlet.jsp.PageContext, and has page scope.
- The session object.
This represents an HTTP session and is an instance of
javax.servlet.http.HttpSession . It has session scope.
- The application object.
This represents the servlet context for the web application and is an
instance of javax.servlet.ServletContext.
It has application scope.
- The out object. This is an
object that is used to write output to the browser from the JSP technology page
and is an instance of javax.servlet.jsp.JspWriter
. The buffer size can be adjusted via the buffer attribute of the page directive.
- The config object. This
config object is the ServletConfig
for the JSP technology page. It is of type javax.Servlet.ServletConfig
and has page scope.
- The page object. This is an
object that is used for the instance of the pages's implementation servlet
class. It is of type java.lang.Object, and
has page scope.
- The exception object. This is
an object that is available to the programmer inside a JSP technology error page.
Back to Top
13. What is meant by Page beans, Session beans and Application beans in
JSP technology?
Page Beans:
A page bean is a model, with the JSP technology page being the view. Page
beans are closely integrated with the JSP technology pages that use them.They will
only be used on mulitiple pages if the same content must be presented in
different formats. Typically, page beans will define 'getter' methods for
each piece of dynamic content displayed by the corresponding JSP technology page.
These getters may return primitive types, or more complex object types
which the JSP technology page will be responsible for displaying.
Session Beans:
Session beans belong to a user's session within an application,
not a page. They are not tied to presentation, but help hold references
to enterprise resources and other data allowing a user session to maintain
and cache state. JSP technology session beans are not directely concerned with
page production, they should be views of or proxies for enterprise middleware,
not enterprise middleware themselves.
Application Beans:
Application beans are still wider in scope than session beans.
They maintain state for all users of a web application. They are used less
often than session beans, but can be useful to minimize memory usage and
enhance performance, especially when many users require access to some data
that is expensive to retrive. Application beans are best used for read-only
data. Using them to hold read-write data is a recipe for concurrency problems
or synchronization bottlenecks.
Back to Top
14. What is the XML syntax of a JSP technology page element?
The JSP 1.1 specification provides an equivalent XML-based syntax for
JSP technology pages, replacing directives and scripting elements with XML-compliant
alternatives. An XML-based syntax is more convenient in some contexts where
it is useful to manipulate a JSP technology page as an XML document.
| Directives |
|
| JSP Syntax: |
<%@ directiveName ATTRIBUTES %> |
| XML-based syntax: |
<jsp:directive:directiveName ATTRIBUTES /> |
|
|
| Scripting Elements: Declarations |
|
| JSP Syntax: |
<%! declaration code %> |
| XML-based syntax: |
<jsp:declaration> declaration code</jsp:declaration> |
|
|
| Scripting Elements: Scriplets |
|
| JSP Syntax: |
<% scriptlet code %> |
| XML-based syntax: |
<jsp:scriptlet> scriptlet code</jsp:scriptlet> |
|
|
| Scripting Elements: Expressions |
|
| JSP Syntax: |
<% expression code %> |
| XML-based syntax: |
<jsp:expression> expression code</jsp:expression> |
|
|
Back to Top
15. What is a custom tag?
A custom tag is a user-defined JSP technology page element. When a JSP technology
page containing
a custom tag is translated into a Java Servlet, the tag is converted
to operations (method calls) on an object called a tag handler. The servlet
engine then invokes those operations when the JSP technology page's servlet is executed.
Custom tags can:
- Be customized via attributes passed from the calling page
- Access all the objects available to JSP technology pages
- Modify the response generated by the calling page
- Communicate with each other. You can create and initialize a JavaBeans[tm] component, create a variable
that refers to that bean in one tag, and then use the bean in another tag.
- Be nested within one another, allowing for complex interactions
within a JSP technology page
- Encapsulate both simple and complex behaviors in an easy to use
syntax and greatly simplify the readability of JSP technology page
Back to Top
16. What are Tag Libraries and Tag Handlers?
In JavaServer Pages technology, actions are elements that can create and access programming
language objects and affect the output stream. In addition to the standard
actions, JSP v1.1 specification supports the development of reusable modules
called custom actions. A custom action is invoked by using a custom tag
in a JSP technology page. A tag library is a collection of custom tags. Some examples
of tasks that can be performed by custom actions include form processing,
accessing databases and other enterprise services such as email and directories,
and flow control. Before the availability of custom actions, JavaBeans components in conjunction with
scriplets were the main mechanism for performing such processing.
There are two types of components for a tag library:
- Tag library descriptor file
- Tag handlers
Tag Library Descriptor File:
A tag library descriptor (TLD) is an XML document that
describes a tag library. A TLD contains information about a library as
a whole and about each tag contained in the library. TLDs are used by a
JSP technology container to validate the tags and by JSP technology page
development tools.
Tag Handler:
A tag handler is an object invoked by a JSP technology container
to evaluate a custom tag during the execution of the JSP technology page that references
the tag. Tag handler methods are called by the JSP technology page implementation
class at various points during the evaluation of the tag.
When the start tag of a custom tag is encountered, the JSP page implementation
class calls methods to initialize the appropriate handler and then invokes
the handler's doStartTag method. When the custom
end tag is encountered, the handler's doEndTag
method is invoked. Additional methods are invoked in between when a tag
handler needs to interact with the body of the tag. In order to provide
a tag handler implementation, you must implement the methods that are invoked
at various stages of processing the tag.
A tag handler has access to an API that allows it to communicate
with the JSP technology page. The entry point to the API is the page context object
through which a tag handler can access to all the other implicit objects
(request, session, and application) accessible from a JSP technology page. Implicit
objects can have attributes associated with them. Such attributes are accessed
using the appropriate set/get]Attribute method.
If the tag is nested, a tag handler also has access to the handler (called
the parent) associated with the enclosing tag. Tag handlers must implement
either the Tag or BodyTag interfaces. Interfaces can be used to take an existing
Java technology object and make it a tag handler. For newly created handlers, you can
use the TagSupport and
BodyTagSupport classes as base classes.
Back to Top
17. How can you set a cookie in a JSP technology page?
Setting cookies from within a JSP technology page is similar to the way they
are done within servlets. For example, the following scriptlet sets a cookie
"Hicookie" at the client:
<%
Cookie Hicookie = new Cookie("aName","aValue");
response.addCookie(Hicookie);
%>
Typically, cookies are set at the beginning of a JSP technology page, as they are
sent out as part of the HTTP headers.
Back to Top
18. How can we delete a cookie with JSP technology page?
A cookie, Hicookie, can be deleted using the following scriptlet:
<%
Cookie killHiCookie = new Cookie("Hicookie", null);
killHiCookie.setMaxAge(0);
killHiCookie.setPath("/");
response.addCookie(killHiCookie);
%>
Back to Top
19. How can I avoid the caching of a JSP technology page by the browser?
You will need to set the appropriate HTTP header attributes in order
to prevent the dynamic content output by the JSP
TM page from being cached by
the browser. Before sending the data to the browser, write the following
statements:
<%
response.setHeader("Cache-Control","no-cache");
response.setHeader("pragma","no-cache");
response.setDateHeader ("Expires", "Sun,26 Apl 2001 09:00:00 GMT"); //Date
in the past
%>
There are some problems with disabling page caching under
IE 5.0, due to the unique buffering. It's a good idea to check the history
settings for both Netscape and Internet Explorer browsers.
Back to Top
20. How can I include other files or resources within a JSP technology page?
There are two ways in which you can include other files or resources
in a JSP technology
page. The include directive and the include action (<jsp:include>
)
The include directive:
JSP technology syntax
<%@ include file=<filename> %>
Examples
<%@ include file="header.html" %>
<%@ include file="banner.html" %>
<%@ include file="tableData.jsp" %>
This directive tells the JSP technology engine to in-line the code of the file specified
by the include directive into the JSP technology page as the page is being parsed
at translation time. This effectively includes the source of that file
into the source of the JSP technology page at the point at which the include directive
was used. Translation time is the point at which the JSP technology page is translated
into a Java[tm]
servlet. This happens when a JSP technology page is first requested after it has
been either created or modified. If a resource included using the include
directive is modified, the JSP technology page will not be translated again. Therefore
changes to the included resource will not be seen when the JSP technology page is
requested.
The include action:
JSP technology Syntax
<jsp:include page="{relativeURL | <%=
expression%>}" flush="true" />
or
<jsp:include page="{relativeURL | <%=
expression %>}" flush="true" >
<jsp:param name="parameterName" value="{parameterValue | <%= expression
%>}" />+
</jsp:include>
Examples
<jsp:include page="scripts/login.jsp"
/>
<jsp:include page="copyright.html"
/>
<jsp:include page="servlet/MyServlet"
/>
<jsp:include page="scripts/login.jsp">
<jsp:param name="username" value="jsmith" />
</jsp:include>
The include action works at request time - in other words, at the time
the JSP technology page is requested. Unlike the include directive, the include action
uses a relative URL to indicate the address of the resource that will be
the target of the include. The URL of the included resource is specified
with the page attribute of the include action. The included resource
can be anything that is capable of outputing data to an
HttpResponse stream and could therefore be a JSP technology page, an HTML file
or even a Servlet. The one limitation of the value for the included resource
is that it must be available within the same web application as the JSP
page.
When the include action is called, the output from the included resource
is added to the response stream that will ultimately be returned to the client
that made the original request. If the included resource is another JSP technology
page or a Servlet then that will be called and the output that it produces
will be added to the response stream. If the included resource is an HTML
file, then it's content will be added to the response stream.
The important thing to note here is that if the included resource is changed,
then these changes will be seen the next time the JSP technology page that included
it is called.
If the page output is being buffered (meaning you've declared a buffer
size using the page directive) and the flush attribute of the include action
is set to true, then the buffer will be flushed before the inclusion is made,
if the value is false then the buffer will not be flushed.
In JSP 1.1 technology the value for the flush attribute must be true
. In JSP 1.2 technology the value can be either true or false and the
default value is true. Although default values are defined in the
specifications, the flush atribute is mandatory.
The param action (<jsp:param>) can be used in conjunction with the
include action in order to pass parameters to the resource that is being
included. The parameters are added to the request object and the request object
is always accessible to the included resource. Provided that the included
resource knows the name of the parameter, then it can retrieve its value.
Back to Top
21. Can I create dynamic GIFs using JSP technology?
If GIFs are small you can code a switch statement and instead of
hard coding the GIF names you can determine which gif file will be used dynamically.
Example one:
<img src="<% case(gifNo){
case 0:%>zero.gif<%;
break;
case 1: %>one.gif<%;
break;
default: %>default.gif<%;
} %>" >
Using this piece of code, GIFs can be used dynamically inside a page with JSP technology.
In the above code fragment the gifNo is used
to decide which GIF image is to be displayed. The gifNo
can be obtained from the request. In Example One, the GIF files
have been hard coded into the JSP technology file: a more elegant way to handle this
would be to retrieve them at runtime as in Example 2.
Example Two:
<jsp:useBean id="imageBean" class="package.ImageBean" scope="page" />
<%
String imageNo = request.getParameter("ImageNo");
byte[] jpegArray = imageBean.getJPEG(Integer.parseInt(imageNo));
response.setContentType("image/jpeg");
ServletOutputStream op = response.getOutputStream();
op.write(jpegArray, 0, jpegArray.length);
%>
In this example the bean imageBean, contains
an array of JPEG/GIF images. These could be changed at runtime depending
on the occurrence of an event. For example, if the GIF images have to change
depending on a user's preference of language or style then the appropriate
images could be loaded into the bean and displayed wherever required. Here,
as in Example One, depending on the imageNo
parameter which is passed through the request, the correct JPEG/GIF
image is retrived from the array and sent as part of the response to the
client.
Back to Top
22. How to get client name and address from within a JSP technology page.
You can get the client address through the following methods of the
request object:
getRemoteAddr():
Returns the Internet Protocol (IP) address of the client that sent the request.
Returns: String - remote IP address
getRemoteHost(): Returns
the fully qualified name of the client that sent the request.
Returns: String - remote host
These methods can be used within a JSP technology page to output the Hostname
and IP address of the client that made the request.
For example:
<%
out.print( request.getRemoteAddr() );
out.print( request.getRemoteHost() );
%>
Back to Top
23. Are there any sample applications available that demonstrate the correct
use of JSP technology
pages as web components?
The Java[tm] Pet
Store application is a complete online store that was written
as a sample application for the
Java Blue Prints for J2EE architecture
program which is available both online and in published form as the book
"Designing Enterprise Applications with the Java 2 Platform, Enterprise
Edition".
. All of the presentation logic of the Pet Store is implemented using a
Java servlet along with several JSP technology
pages that represent views. The underlying business logic is implemened
using Enterprise JavaBeans[tm]
technology. The presentation logic is quite complex and demonstrates some
fairly advanced uses of JSP technology pages. You can download the Java Pet Store sample
application
here.
In order to run the Java Pet Store you'll need an application server
such as the J2EE Reference Implementation which can be downloaded
here.
Note that specific versions of the Java Pet Store application are designed
to run on a specific release of the Reference Implementation.
Back to Top
|