table of contents
CSAJSP/2

Source Code Archive

Core Servlets and JavaServer Pages

Second Edition

Volume 1: Core Technologies


Chapter 11: Invoking Java Code with JSP Scripting Elements

Complete source code for every example from this chapter, available free for unrestricted use. Live links to all URLs cited in the chapter. More information. 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. JSP page to demonstrate simple expressions and the use of the most straightforward type of relative URL. Uses the JSP-Styles.css style sheet.
  • JSP-Styles.css. Style sheet used by many of the JSP pages in this chapter and throughout the book.
  • ThreeParams.java. A servlet that collects and displays three request parameters. For comparison with the equivalent JSP version. Remember that this class is in the coreservlets package and thus needs to be placed in the coreservlets directory.
  • ThreeParams.jsp.
  • BGColor.jsp. A JSP page that demonstrates the use of scriptlets that contain one or more complete statements.
  • DayWish.jsp. A JSP page that demonstrates the use of scriptlets that contain incomplete statements and thus make part of the "static" HTML conditional.
  • AccessCounts.jsp. A JSP page that uses JSP declarations to create a simple hit counter.
  • RanUtilities.java. A utility class used by the following four JSP pages. This page (like all classes used by JSP, as discussed in the book!) is in a package. This particular class is in the coreservlets package and thus needs to be placed in the coreservlets directory.
  • RandomNums.jsp. JSP page to output a bulleted list of five random integers from 1 to 10. Since the structure of this page is fixed and we use a separate helper class for the randomInt method, JSP expressions are all that is needed.
  • RandomList1.jsp. JSP page to generate a list of between 1 and 10 entries (selected at random), each of which is a number between 1 and 10. Because the number of entries in the list is dynamic, a JSP scriptlet is needed. This first variation uses a single scriptlet to generate the list items; the second variation below uses the dangling-brace approach described in the chapter.
  • RandomList2.jsp. JSP page to generate a list of between 1 and 10 entries (selected at random), each of which is a number between 1 and 10. Because the number of entries in the list is dynamic, a JSP scriptlet is needed. This second variation uses the dangling-brace approach described in the chapter; the first variation above uses a single scriptlet to generate the list items.
  • SemiRandomNum.jsp. JSP page to generate a random number on the first request, then show the same number to all users until the server is restarted. Instance variables (fields) are the natural way to accomplish this persistence, so JSP declarations are used.

More Information

Java

JSF (JavaServer Faces)

Servlets & JSP
Ajax, GWT, & JavaScript

Spring, Hibernate, & JPA

Struts