table of contents
CSAJSP/2

Source Code Archive

Core Servlets and JavaServer Pages

Second Edition

Volume 1: Core Technologies


Chapter 15: Integrating Servlets and JSP: The Model View Controller (MVC) Architecture

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.

  • RequestForwardingSnippet.java. Section of code demonstrating RequestDispatcher.forward. Not a complete Java class.
  • ShowBalance.java. Servlet that reads a customer ID and displays information on the account balance of the customer who has that ID. Stores results in the BankCustomer bean. Uses NegativeBalance.jsp, NormalBalance.jsp, HighBalance.jsp, and UnknownCustomer.jsp to present results. Presents various images in the JSP pages.
  • BankCustomer.java. Bean to represent a bank customer. Used by the ShowBalance servlet.
  • NegativeBalance.jsp. JSP page that displays information on customers that owe money on their accounts. Used by the ShowBalance servlet.
  • NormalBalance.jsp. JSP page that displays information on customers that have small-to-moderate positive balances in their accounts. Used by the ShowBalance servlet.
  • HighBalance.jsp. JSP page that displays information on customers that have large positive balances in their accounts. Used by the ShowBalance servlet.
  • UnknownCustomer.jsp. JSP page that indicates that the customer ID is unrecognized. Used by the ShowBalance servlet.
  • Images and style sheet used by the bank-account JSP pages.
  • First example comparing bean-sharing approaches. The goal is to display a random number to the user. Each request should result in a new number, so request-based sharing is appropriate.
  • Second example comparing bean-sharing approaches. The goal is to display users’ first and last names. If the users fail to tell us their name, we want to use whatever name they gave us previously. If the users do not explicitly specify a name and no previous name is found, a warning should be displayed. Data is stored for each client, so session-based sharing is appropriate.
  • Third example comparing bean-sharing approaches. The goal is to display a prime number of a specified length. If the user fails to tell us the desired length, we want to use whatever prime number we most recently computed for any user. Data is shared among multiple clients, so application-based sharing is appropriate.

More Information

Java

JSF (JavaServer Faces)

Servlets & JSP
Ajax, GWT, & JavaScript

Spring, Hibernate, & JPA

Struts