|
Source Code Archive
More Servlets and JavaServer Pages
Chapter 3: A Fast Introduction to Basic JSP Programming
To view source code for other chapters in this book, mouse over the table of contents bar on the left.
Source Code from Chapter
Note: right-click or shift-click on the links to download the associated file.
- Expressions.jsp.
Page that illustrates the use of JSP expressions. Uses
the JSP-Styles style sheet.
- JSP-Styles.css.
Style sheet used by
Expressions.jsp. Note: Most of the remaining JSP
pages in Chapter 3 use this style sheet.
- BGColor.jsp.
JSP page that uses the
bgColor request parameter to set the background
color of the page. Illustrates scriptlets.
- AccessCounts.jsp.
Page that uses a JSP declaration to implement a simplistic hit counter.
- ImportAttribute.jsp.
Page that illustrates use of the
import attribute
of the page directive. Requires the
ServletUtilities
and
LongLivedCookie
classes from the previous chapter.
- Excel.jsp.
JSP page that generates Excel instead of HTML. Requires you
to have Microsoft Office or the Excel browser plugin.
- WhatsNew.jsp.
News report page that uses
jsp:include
to include the headlines.
- Item1.html.
Headline 1.
- Item2.html.
Headline 2.
- Item3.html.
Headline 3.
- PluginApplet.jsp.
Page that uses
jsp:plugin to instruct
the browser to invoke a Java 2 applet.
- PluginApplet.java.
Applet that uses Swing and Java 2D and thus requires
the Java Plug-In. Requires the
TextPanel,
DrawingPanel, and
WindowUtilities
classes.
- TextPanel.java.
Class used by
PluginApplet.java.
- DrawingPanel.java.
Class used by
PluginApplet.java.
- WindowUtilities.java.
Class used by
PluginApplet.java.
- StringBean.java.
A simple bean that has a single
String property
called message. Remember: since this (and many other server-side classes
in this chapter) is in the moreservlets package,
it must be placed in the moreservlets directory.
- StringBean.jsp.
JSP page that uses the
StringBean
class.
- SaleEntry.java.
Simple bean to illustrate the various forms
of
jsp:setProperty.
- SaleEntry1.jsp.
Page that uses explicit scripting expressions to read request
parameters and put the values into the
SaleEntry
class.
- SaleEntry2.jsp.
Page that uses the
param attribute of
jsp:setProperty to get rid of the explict Java code
needed to read request
parameters and put the values into the
SaleEntry
class.
- SaleEntry3.jsp.
Page that uses
property="*" in
jsp:setProperty to further simplify the way to
read request parameters and put the values into the
SaleEntry
class.
- AccessCountBean.java.
Simple bean to illustrate sharing beans through
use of the
scope attribute of jsp:useBean
and the difference between conditional and unconditional uses
of jsp:setProperty.
- SharedCounts1.jsp.
The first of three pages that use the
AccessCountBean.
- SharedCounts2.jsp.
The second of three pages that use the
AccessCountBean.
- SharedCounts3.jsp.
The third of three pages that use the
AccessCountBean.
- ExampleTag.java.
Very simple JSP tag that just inserts a string
("Custom tag example...") into the output. Note: since this
(and other tag implementation classes
in this chapter) is in the
moreservlets.tags package,
it must be placed in the tags
subdirectory of the moreservlets directory.
- msajsp-taglib.tld.
The tag library descriptor file used for the various tags in
this chapter.
- SimpleExample.jsp.
Page that uses the tag that is implemented in
ExampleTag.java
and has the tag name given in
msajsp-taglib.tld.
- SimplePrimeTag.java.
Tag that generates a prime number of approximately 50 digits. Requires
the Primes class.
- Primes.java.
A few utilities to generate a large random
BigInteger
and to find the next prime number above a given BigInteger.
Note that this class is in the moreservlets package,
not moreservlets.tags.
- SimplePrimeExample.jsp.
Page that uses the tag that is implemented in
SimplePrimeTag.java
and has the tag name given in
msajsp-taglib.tld.
- PrimeTag.java.
Tag that generates an N-digit random prime (default N = 50).
Extends
SimplePrimeTag, adding a length attribute
to set the size of the prime. The doStartTag
method of the parent class uses the len field
to determine the length of the prime.
- PrimeExample.jsp.
Page that uses the tag that is implemented in
PrimeTag.java
and has the tag and attribute information given in
msajsp-taglib.tld.
- HeadingTag.java.
Tag that generates an HTML heading with the specified background
color, foreground color, alignment, font, and font size.
All attributes except the background color are optional.
- HeadingExample.jsp.
Page that uses the tag that is implemented in
HeadingTag.java
and has the tag and attribute information given in
msajsp-taglib.tld.
- DebugTag.java.
A tag that includes the body content only if
the
debug request parameter is set.
- DebugExample.jsp.
Page that uses the tag that is implemented in
DebugTag.java
and has the tag name given in
msajsp-taglib.tld.
- FilterTag.java.
Tag that replaces <, >, ", and & with their HTML
character entities (<, >, ", and &).
Requires the
ServletUtilities
class from the previous chapter.
- FilterExample.jsp.
Page that uses the tag that is implemented in
FilterTag.java
and has the tag name given in
msajsp-taglib.tld.
- RepeatTag.java.
Tag that repeats the body the specified number of times.
- RepeatExample.jsp.
Page that uses the tag that is implemented in
RepeatTag.java
and has the tag and attribute information given in
msajsp-taglib.tld.
- IfTag.java.
Tag that acts like an if/then/else.
- IfConditionTag.java.
The condition part of an if tag.
- IfThenTag.java.
The then part of an if tag.
- IfElseTag.java.
The else part of an if tag.
- IfExample.jsp.
Page that uses the if tag three different ways. In the
first instance, a value of true is hardcoded for the condition.
In the second instance,
a parameter from the HTTP request is used for the condition,
and in the third case, a
random number is generated and compared to a fixed cutoff. The
tag and attribute information are given in
msajsp-taglib.tld.
- quick-search.html.
Front end to the online travel agency. Requires four images
(airplane.gif,
bed.gif,
car.gif, and
passport.gif)
and the
travel-styles.css
style sheet. Links to the
accounts.jsp
placeholder.
- Travel.java.
Top-level travel-processing servlet. This servlet sets up
the customer data as a bean, then forwards the request
to the airline booking page, the rental car reservation
page, the hotel page, the existing account modification
page, or the new account page.
- BookFlights.jsp.
Display page for the plane flights part of the travel-processing
servlet. Uses the
travel-styles.css
style sheet. There are also several placeholder pages:
RentCars.jsp,
FindHotels.jsp,
EditAccounts.jsp, and
IllegalRequest.jsp.
- TravelCustomer.java.
Describes a travel services customer. Implemented
as a bean with methods that return data in HTML
format, suitable for access from JSP. Uses the
FrequentFlyerInfo.java,
HotelInfo.java,
RentalCarInfo.java, and
TravelData.java classes.
URLs Referenced in Chapter
More Information
-
J2EE training courses from the author. Available on-site at your
company or at public venues.
- Free online version of
Core Servlets & JavaServer Pages.
Complete text of book in PDF.
-
Home page for Core Servlets and JavaServer Pages 2nd Edition (Vol 1).
Includes the table of contents, index, sample chapters, source code archive, etc.
-
Home Page for More Servlets and JavaServer Pages.
Includes the table of contents, index, source code archive, etc.
-
Free online version of More Servlets and JavaServer Pages.
- Servlet and JSP Programming Resources.
Download sites, servers, IDEs, tutorials, books, job listings, and more.
-
Tutorials and lecture notes on servlets, JSP, Struts, JSF, and Java 5.
PDF version free for all. PowerPoint version free for qualified university instructors.
- Servlet and JSP
programming resources. Specs, documentation, servers, IDEs,
hosting providers, books, training, etc.
- Java Programming Resources.
General resources on Java technology. Compilers, editors, IDEs, tutorials, books,
user forums, and more.
|