JavaServer Pages (JSP) 1.0
JavaServer Pages (JSP) lets you separate the dynamic part of
your pages from the static HTML. You simply write the regular HTML in the normal manner,
using whatever Web-page-building tools you normally use.
You then enclose the code for the dynamic parts
in special tags, most of which start with "<%"
and end with "%>". For example, here is a section
of a JSP page that results in something like "Thanks for
ordering Core Web Programming" for a URL of
http://host/OrderConfirmation.jsp?title=Core+Web+Programming:
Thanks for ordering
<I><%= request.getParameter("title") %></I>
You normally give your file a .jsp extension, and typically
install it in any place you could place a normal Web page. Although what
you write often looks more like a regular HTML file
than a servlet, behind the scenes, the JSP page just gets converted
to a normal servlet, with the static HTML simply being printed
to the output stream associated with the servlet's service
method. This is normally done the first time the page is requested,
and developers can simply request the page themselves when first
installing it if they want to be sure that the first real user
doesn't get a momentary delay when the JSP page is translated
to a servlet and the servlet is compiled and loaded.
Note also that many Web servers let you define
aliases that so that a URL that appears to reference an HTML file
really points to a servlet or JSP page.
Aside from the regular HTML, there are three main types of
JSP constructs that you embed in a page: scripting elements,
directives, and actions. Scripting elements let you
specify Java code that will become part of the
resultant servlet, directives let you control the overall
structure of the servlet, and actions let you
specify existing components that should be used,
and otherwise control the behavior of the JSP engine. To
simplify the scripting elements, you have access to a number of
predefined variables such as request in the snippet above.
Note that this tutorial covers version 1.0 of the JSP specification.
JSP has changed dramatically since version 0.92, and although
these changes were almost entirely for the better, you should
note that version 1.0 JSP pages are almost totally incompatible with
the earlier JSP engines. Note that this JSP tutorial is part of
a larger tutorial on servlets and JSP at
http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/.
NEXT
This tutorial is now available as a book: Core Servlets and JavaServer Pages by Marty Hall, published by Sun Microsystems Press.
Read all about it at CoreServlets.com
Server-Side Web Applications using Java Servlets versions 2.1/2.2 and JavaServer Pages (JSP) version 1.0: A Tutorial
© 1999-2000 Marty Hall.
All source code freely available for unrestricted use.
Created for work in the Research and Technology Development Center of the Johns Hopkins University Applied Physics Lab, for courses in the Johns Hopkins Part-Time MS Program in Computer Science, and for various industry seminars and on-site Java short courses.
Please note that this is a first draft of the tutorial, so please send corrections, comments, and suggestions to me at hall@apl.jhu.edu.
Reprinted with permission from the author. Click here to visit the original version
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.