Customer Service 1-800-221-5528

Murach’s Java Servlets and JSP (3rd Edition)

by Joel Murach and Michael Urban
23 chapters, 744 pages, 270 illustrations
Published June 2014
ISBN 978-1-890774-78-3
List price: $57.50

Once your students have Java skills like those presented in our core Java book, you can use our servlets and JSP book to teach them how to develop Java web applications. Dozens of schools have adopted this book, and what instructors like most is the book’s logical, straightforward approach and its comprehensive treatment of Tomcat, MySQL, JSP, and servlets. As one instructor put it, "Thanks to you, we no longer have to cobble together HTML, Tomcat, and JSP material."

Buy This Book

You are currently on the Murach site for instructors. To buy this book, please visit our retail site.

 

This book takes you through a well-structured learning journey of JSP, Servlets, and related technologies such as Netbeans, Tomcat, and MySQL for developing complete web apps. The book has provided me with the skill and confidence to start building my own web-app. The book finishes with a completed e-commerce example that builds on the earlier work, and gives the reader a basis for their own future development.”

Posted at an online bookseller

  • About this Book
  • Table of Contents
  • Courseware
  • FAQs
  • Corrections

Book description

Section 1: Get started right

In this section, your students will learn:

  • the concepts and terms that they need for Java web programming with servlets and JSPs
  • how to use the MVC pattern to get the most from servlets and JSPs
  • how to use the NetBeans IDE for developing servlet/JSP applications more efficiently
  • how to use the Tomcat web server that lets you use servlets and JSPs for web applications

By the time your students finish with this section, they will be able to set up their own development environments for coding and running servlets and JSPs.

Section 2: The essential servlet and JSP skills

This section starts with a crash course in HTML, which is essential to the use of JSPs. Then, your students will learn the skills for creating servlets and JSPs that they’ll use in almost every application. These chapters move from the simple to the complex as they present the use of servlets, JSPs, sessions, cookies, JavaBeans, Expression Language (EL), the JSP Standard Tag Library (JSTL), and custom JSP tags.

Section 3: The essential database skills

Here, your students will learn how to use servlets and JSPs to work with a database using either JDBC or the newer JPA. Since MySQL is a popular open-source database that works well with Java and is commonly used for web applications, this section presents the details for working with MySQL. However, these principles can be applied to the use of any database management system, including Oracle and Microsoft SQL Server.

Section 4: Advanced servlet and JSP skills

In this section, your students will learn the advanced servlet and JSP skills that are needed for certain types of web applications. This includes the use of JavaMail, SSL, authentication, encryption, advanced HTTP skills, listeners, and filters. Then, the last chapter is an introduction to creating web applications with JavaServer Faces (JSF), if you want to cover this alternative to using JSPs. Since the chapters in this section have been designed to work independently, you can assign as many as you want, in any order you want.

Section 5: The Music Store website

This section presents an e-commerce website that puts the skills presented in the first four sections into context. This downloadable application illustrates best practices and provides code that your students can use in their own applications.

Book features

Like all our books, this one has features that you won’t find in competing books. Here, though, are a few of the features that are unique to this book:

  • Chapter 2 shows how to use the MVC pattern (or Model 2 architecture) to get the most from JSPs and servlets. From that point on, your students will use servlets when they’re appropriate and JSPs when they’re appropriate. As a result, they won’t waste time learning how to use servlets for tasks that should be handled by JSPs, or vice versa.
  • Chapter 3 shows how to use the NetBeans IDE with a Tomcat server to develop web applications on your own computer. By using this IDE, your students will learn faster and better than they would without an IDE.
  • Chapter 4 provides a crash course in HTML5 and CSS3, which this is essential background for the use of JSPs. This means your students won’t need a second book to learn HTML and CSS.
  • Like all of our books, this one includes dozens of examples that range from the simple to the complex. That way, your students can quickly see how a feature works from the simple examples, but they’ll also see how the feature is used in more complex, real-world examples, including the complete e-commerce application that’s presented in section 5.

What’s new in this edition

  • An improved didactic approach that starts by presenting the MVC pattern in chapter 2. That way, your students will use the MVC pattern for all exercises and projects, they won’t learn skills that they will have to unlearn or relearn later on, and they won’t learn programming practices that they won’t or shouldn’t use on the job.
  • New chapters on how to use JPA (Java Persistence API) for database programming, other security skills that weren’t covered in the second edition, and JavaServer Faces (JSF).
  • An improved Music Store website in two versions: one that uses JDBC and one that uses JPA.
  • Technical enhancements throughout the book, thanks to co-author Michael Urban, who has a wealth of Java web programming experience.

What courses this book can be used for

This book assumes that your students have basic Java skills, the kind they should get from any core Java book or course, like chapters 1-14 of our own Murach’s Java Programming.

With a set of basic Java skills as the prerequisite, this book can be used for a first web programming course. Or it can be combined with our core Java book for a two- or three-term sequence. And if you want to teach SQL as part of that sequence, you can add Murach’s MySQL to the mix. Unlike the books of other publishers, all of these books are designed to work together.

What software your students need

To create and use the web applications in this book, your students need this software:

  • Java SE
  • NetBeans
  • Tomcat
  • MySQL
  • MySQL Workbench

This software is available for Windows, Mac OS X, and Linux systems.

Although all of this software is free, it can be difficult to install and get started with it. So this book provides all the support your students will need for doing that:

  • Appendix A shows how to install the software on Windows systems.
  • Appendix B shows how to install the software on Mac OS X systems
  • Chapter 3 shows how to use NetBeans and Tomcat

What if you want to use another IDE for the course

Because this book shows how to use the NetBeans IDE to develop servlets and JSPs, that’s the best IDE for a course that’s based on this book.

However, if you prefer to use another IDE such as Eclipse with this book, you can do that. You just need to:

  • import the source code for this book into that IDE so your students can compile and run the book applications and complete the exercises
  • teach your students how to use that IDE if they haven’t used it in an earlier course

What people say about this book

"I love the layout, style, organization, thoroughness, ease of understanding, and overall excellence of the Murach books. They explain everything very clearly, step by step, in a mentor/instructor conversational style, and in a problem-solving context. The problem-solving context is especially valuable, as it really drills the topic into one’s brain. It’s one thing to read about an API and see how it works; it’s another thing to see it being used to solve a common business process or problem....In short, I cannot recommend Murach’s Java Servlets and JSP enough. This book is a pleasure to read, and I’ve learned a ton, and solidified my knowledge and skills regarding Java web development. Get it. You’ll like it. It’s well worth the price tag."
- Jeff Salter, TheServerSide.com

"This book is very practical, and it will make Servlets and JSP fun to learn. It is so enjoyable that you’ll finish reading it in no time. I wish I had such a book when I started developing web applications. Highly recommended."
- Christophe Verre, JavaRanch.com

"I’ve read a lot of computer technology books, and rarely have I felt so solidly prepared as this one to transfer what I’ve learned into real projects."
- Posted at an online bookseller

"A very strong point your book has is putting crystal-clear comments on the left page, with short but realistic examples and a summary on the right. The idea is simple, but very efficient: it allowed me to progress at light speed and still proves to be very convenient when I need to refresh my memory within seconds. It makes me a more productive programmer. Very good index, too!"
- Xavier Mercier, Software Designer, Galway, Ireland

"I have to admit I was a bit intimidated by JSP and servlets. But Murach’s treatment of the topic is excellent. It goes step-by-step, starting with simple examples, but the pace doesn’t feel overly slow. You always feel like you’re making good progress.... Overall a great book."
- Posted at an online bookseller

"I have been a developer for over 10 years in many different languages and usually for each language or topic I buy lots of books, most of which, sad to say, are fairly boring, overly complex, teach useless stuff, or are way too cluttered and disorganized to get the points across. Usually I find a couple of books that really stand out and become tattered and ragged with use. This is such a book."
- Posted at an online bookseller

"Every so often you find a technical book that is so superbly written you actually enjoy reading it, because you know you’re going to be able to understand and learn more each time you pick it up. From the start of this book, through to the end, I found myself feeling so glad I found this book and so grateful to the authors, because the care and skill with which it was written makes it very easy to read and understand."
- Posted at an online bookseller

"There is a line written on this book, ‘No other book teaches you so much, so fast, so thoroughly,’ and I must tell you that this is 100% correct. Congrats !! on coming up with this amazing work of yours.... Looking forward to more books on other languages as well."
- Ravi Nathani, Software Engineer Wireless and Multimedia Products

“This book takes you through a well-structured learning journey of JSP, Servlets and related technologies such as Netbeans, Tomcat and MySQL for developing complete web apps. The book has provided me with the skill and confidence to start building my own web-app. The book finishes with a completed e-commerce example that builds on the earlier work, and gives the reader a basis for their own future development.”
- Posted on Amazon

View the table of contents for this book in a PDF: Table of Contents (PDF)

Click on any chapter title to display or hide its content.

Section 1 Get started right

Chapter 1 An introduction to web applications

A typical web application

The components of a web application

How static web pages work

How dynamic web pages work

Three approaches for Java web applications

Servlet/JSP

JSF

Spring Framework

An introduction to servlet/JSP web development

The software components

The architecture

The standard directories and files

Software for developing Java web applications

IDEs for developing Java web applications

Web servers for Java web applications

Database servers for Java web applications

Tools for deploying Java web applications

Chapter 2 How to structure a web application with the MVC pattern

Two patterns for servlet/JSP applications

The Model 1 pattern

The Model 2 (MVC) pattern

A servlet/JSP application that uses the MVC pattern

The user interface

The HTML for the first page

The CSS for both web pages

The servlet for the back-end processing

The web.xml file

The User class

The JSP for the second page

Chapter 3 How to use NetBeans and Tomcat

How to get started with NetBeans

How to start NetBeans

How to create a new web application

How to use the Projects window

How to open and close projects

How to build, deploy, and run a web application

How to work with HTML and JSP files

How to add an HTML or JSP file

How to edit an HTML or JSP file

How to work with Java files

How to add a Java class

How to add a servlet

How to edit a Java file

How to work with XML files

How to edit the web.xml file

How to edit other XML files

Other skills for working with web applications

How to add existing files to a project

How to deploy a web application to a remote server

How to work with a web application server

How to add a class library or a JAR file to a project

How to register a database connection

Section 2 Essential servlet and JSP skills

Chapter 4 A crash course in HTML5 and CSS3

How to work with HTML

The starting HTML for a web page

How to code HTML elements

How to use the HTML5 semantic elements

How to use the div and span elements with HTML5

How to ensure cross-browser compatibility

How to code links

How to include images

How to code tables

How to work with CSS

How to provide CSS styles for an HTML page

How to code the basic CSS selectors

How to code CSS rule sets and comments

How to use CSS to format a table

How to code HTML forms

How to code a form

How to code text boxes

How to code buttons

How to code check boxes and radio buttons

How to code combo boxes and list boxes

Chapter 5 How to develop servlets

How to create and map a servlet

How to create a servlet

How to map a servlet with the web.xml file

How to map a servlet with an annotation

How to request a servlet

How to use the HTTP GET method

How to use the HTTP POST method

When to use the HTTP GET and POST methods

Skills for working with servlets

How to get the values of the parameters

How to get the real path for a file

How to get and set request attributes

How to forward requests

How to redirect responses

How to validate data

How to validate data on the client

How to validate data on the server

How to work with the web.xml file

A complete web.xml file

How to work with initialization parameters

How to implement custom error handling

More skills for working with servlets

How the methods of a servlet work

Why you shouldn’t use instance variables in servlets

How to work with servlet errors

How to solve common servlet problems

How to print debugging data to the console

How to print debugging data to a log file

Chapter 6 How to develop JavaServer Pages

A crash course in EL and JSTL

How to code a JavaBean

How to use EL to get attributes and JavaBean properties

How to enable the core JSTL library

How to use the JSTL if tag

How to use JSP tags

How to code directives, scriptlets, and expressions

How to code comments in a JSP

How to use standard JSP tags with JavaBeans

An introduction to standard JSP tags

How to code the useBean tag

How to code the getProperty and setProperty tags

How to include a file in a JSP

A JSP that includes a header and footer file

Three techniques for including files in a JSP

How to fix common JSP errors

Chapter 7 How to work with sessions and cookies

An introduction to session tracking

Why session tracking is difficult with HTTP

How session tracking works in Java

An application that needs session tracking

How to work with sessions

How to set and get session attributes

More methods of the session object

How to provide thread-safe access to the session object

How to work with cookies

An introduction to cookies

How to create and use cookies

How to view and delete cookies

Four methods for working with cookies

A utility class for working with cookies

How to work with URL rewriting and hidden fields

How to use URL rewriting to pass parameters

How to use hidden fields to pass parameters

The Download application

The user interface

The file structure

The web.xml file

The code for the JSPs

The code for the servlet

Chapter 8 How to use EL

An introduction to JSP Expression Language

Advantages of EL

Disadvantages of EL

Essential skills for working with EL

How to use the dot operator to work with JavaBeans and maps

How to use EL to specify scope

How to use the [ ] operator to work with arrays and lists

How to use the dot operator to access nested properties

Other skills for working with EL

How to use the [ ] operator to access attributes

How to work with the other implicit EL objects

How to work with other EL operators

How to disable EL

How to disable scripting

Chapter 9 How to use JSTL

An introduction to JSTL

The JSTL libraries

How to make the JSTL JAR files available to your application

How to code the taglib directive

How to code a JSTL tag

How to view the documentation for a library

How to work with the JSTL core library

How to use the out tag

How to use the forEach tag

How to use the forTokens tag

Four more attributes for looping

How to use the if tag

How to use the choose tag

How to use the url tag

Other tags in the JSTL core library

The Cart application

The user interface

The code for the business classes

The code for the servlets and JSPs

Chapter 10 How to use custom JSP tags

How to code a custom tag that doesn’t have a body

The tag

The tag element

The tag class

How to code a custom tag that has a body

The tag

The tag element

The tag class

How to code a custom tag that has attributes

The tag

The tag element

The tag class

How to code a custom tag that reiterates its body

The tag

The tag element

The tag class

How to work with scripting variables

An introduction to scripting variables

The TEI class for four scripting variables

Classes, methods, and fields for working with custom tags

Methods and fields of the TagSupport class

Methods and fields of the PageContext class

Methods and fields of the BodyTagSupport class

Methods and fields of the BodyContent class

Section 3 Essential database skills

Chapter 11 How to use a MySQL database

An introduction to MySQL

What MySQL provides

Two ways to interact with MySQL

How to use MySQL Workbench

The Home tab of MySQL Workbench

How to open a database connection

How to start and stop the MySQL server

How to enter and execute a SQL statement

How to enter and execute a SQL script

The SQL statements for creating a database

How to create, select, and drop a database

How to create and drop a table

How to insert multiple rows into a table

The SQL statements for data manipulation

How to select data from a single table

How to select data from multiple tables

How to insert, update, and delete data

Chapter 12 How to use JDBC to work with a database

How to work with JDBC

An introduction to database drivers

How to connect to a database

How to return a result set and move the cursor through it

How to retrieve data from a result set

How to insert, update, and delete data

How to work with prepared statements

The SQL Gateway application

The user interface

The code for the JSP

The code for the servlet

The code for the utility class

How to work with connection pooling

How connection pooling works

How to make a connection pool available

How to implement a connection pool

How to use a connection pool

The Email List application

The user interface

The code for the JSP

The code for the servlet

The code for the database class

The code for the utility class

Chapter 13 How to use JPA to work with a database

An introduction to JPA

A summary of JPA implementations

Entities and the entity manager

How to configure NetBeans to work with JPA

How to configure a persistence unit

How to code JPA entities

How to code the class for an entity

How to use getter and field annotations

How to code relationships between entities

How to work with dates and times

How to retrieve data

How to get an entity manager factory

How to retrieve an entity by primary key

How to retrieve multiple entities

How to retrieve a single entity

How to modify data

How to insert, update, or delete a single entity

How to update or delete multiple entities

A complete JPA class

The methods that modify data

The methods that retrieve data

Section 4 Advanced servlet and JSP skills

Chapter 14 How to use JavaMail to send mail

An introduction to the JavaMail API

How email works

How to install the JavaMail API

Code that uses the JavaMail API to send an email message

How to create and send an email message

How to create a mail session

How to create a message

How to address a message

How to send a message

Example classes that send an email message

A helper class for sending an email with a local SMTP server

A servlet that uses a helper class to send an email message

A helper class for sending an email with a remote SMTP server

Chapter 15 How to use SSL to work with a secure connection

An introduction to SSL

How SSL works

How TLS works

When to use a secure connection

How SSL authentication works

How to get a digital secure certificate

How to configure a testing environment for SSL

How to create a certificate for testing

How to enable SSL in Tomcat

How to test a local SSL connection

How to work with a secure connection

How to request a secure connection

A JSP that uses a secure connection

How to return to a regular HTTP connection

How to switch from a local system to an Internet server

Chapter 16 How to restrict access to a web resource

An introduction to authentication

How container-managed authentication works

Three types of authentication

How to restrict access to web resources

How to add a security role

How to add a security constraint

How to implement a security realm

How to implement the UserDatabaseRealm

How to implement the JDBCRealm

How to implement the DataSourceRealm

How to allow access to authorized users

How to use basic authentication

How to use digest authentication

How to use form-based authentication

Chapter 17 More security skills

An introduction to website security

Common website attacks

How to prevent social engineering attacks

An introduction to cryptography

Common password attacks

How to protect passwords

How to hash passwords

How to salt passwords

A utility class for hashing and salting passwords

How to enforce password strength requirements

Chapter 18 How to work with HTTP requests and responses

An introduction to HTTP

An HTTP request and response

Common MIME types

Common HTTP request headers

Common HTTP status codes

Common HTTP response headers

How to work with the request

How to get a request header

How to display all request headers

How to work with the response

How to set status codes

How to set response headers

Practical HTTP skills

How to return a spreadsheet

How to control caching

How to compress a response with GZIP

How to return a binary file as an attachment

How to create virtual HTML pages

Chapter 19 How to work with listeners

How to use a ServletContextListener

How to code a class for the listener

How to register the listener

How to code a JSP that uses the attributes set by the listener

How to work with other types of listeners

A summary of the listener interfaces

The methods of the listener interfaces

The methods of the event objects

Chapter 20 How to work with fliters

An introduction to filters

How filters work

Two benefits of filters

When to use filters

How to add a filter

How to code a filter

How to configure a filter

Two filter classes

How to code a filter that performs request-side processing

How to code a filter that performs response-side processing

Other skills for working with filters

How to wrap a request or response

How to use an initialization parameter

How to restrict access by IP address

Chapter 21 How to work with JavaServer Faces

An introduction to JSF

A summary of JSF versions

How to add a JSF library to a project

How to used managed beans

How to create a managed bean

How to set the scope of a bean

How to use standard JSF tags

How to code the head and body tags

How to display data from a managed bean

How to code the inputText tag

How to validate data

How to code a form action

The Email List application

The user interface

The EmailList bean

The index.xhtml file

The thanks.xhtml file

Section 5 The Music Store website

Chapter 22 An introduction to the Music Store website

The user interface

The Home and Catalog pages

The code for the Home page

The business layer

The class diagrams

The Product class

The controller layer

The CatalogController class

The structure

The directory structure

The web.xml file

The context.xml file

The database

The database diagram

The SQL script for the database

The data layer

The class diagrams

The ProductDB class

The JPA version compared to the JDBC version

The similarities

The differences

Chapter 23 The applications of the website

The user interface for end users

The Download application

The Cart application

The user interface for administrators

The Admin Login page

The Admin Menu page

The Process Invoices application

The Reports application

Appendixes

Appendix A How to set up your PC for this book

How to install the source code for this book

How to install the JDK

How to install NetBeans

How to install Tomcat

How to configure a Tomcat server

How to test NetBeans and Tomcat

How to install MySQL

How to create the databases for this book

How to restore the databases for this book

Appendix B How to set up your Mac for this book

How to install the source code for this book

How to install the JDK

How to install NetBeans

How to install Tomcat

How to configure a Tomcat server

How to test NetBeans and Tomcat

How to install the MySQL Community Server

How to install MySQL Workbench

How to create the databases for this book

How to restore the databases for this book

How to update the password for the root user

If you aren’t already familiar with the supporting courseware that we provide for a book, please go to About our Courseware. As you will see, our courseware consists of the end-of-chapter activities in the book, the files in the student download at our retail site, and the instructor’s materials. These components provide everything that other publishers provide in a way that delivers better results.

If you are familiar with our courseware, here’s a quick summary of the courseware for this book. For a detailed description in PDF format, please read the Instructor’s Summary.

End-of-chapter activities in the book

  • Chapter summaries
  • Practice exercises

Student download at our retail site

  • Source code and data for the applications in the book
  • Starting code and data for the exercises in the book
  • Solutions to the book exercises

In the book, appendix A (for Windows) and appendix B (for Mac) give your students complete instructions for downloading and installing these items on their own systems.

Instructor’s materials

  • Instructional objectives by chapter
  • PowerPoint slides for classroom presentations
  • Test banks in multiple formats
  • Extra exercises that aren’t in the book, and their solutions
  • Projects and their solutions; these projects are a true test of the competence of your students because they provide minimal guidance
  • The files that students can download at our retail site: (1) the book applications, (2) starting code and data for the exercises in the book, and (3) solutions to the exercises in the book

Below are the answers to the questions that have come up most often about this book. If you have any questions that aren't answered here, please email us. Thanks!

Whenever I run the SQLGateway application, I get an error that says “Unable to load authentication plugin 'caching_sha2_password' ”. How can I fix this?

This error is occurring because you have installed MySQL 8.0 or later. Unfortunately, the NetBeans projects for this book use Connector/J drivers that are designed to work with MySQL 5.x. The easiest way to fix this problem is to uninstall MySQL 8.0 and install an earlier version of MySQL such as MySQL 5.7.

Whenever I run an application that attempts to use a connection pool to get a connection to a database, the ConnectionPool class throws a NullPointerException and the application crashes. How can I fix this?

This error is occurring because you have installed MySQL 8.0 or later. Unfortunately, the NetBeans projects for this book use Connector/J drivers that are designed to work with MySQL 5.x. The easiest way to fix this problem is to uninstall MySQL 8.0 and install an earlier version of MySQL such as MySQL 5.7.

To view the corrections for this book in a PDF, just click on this link: View the corrections

Then, if you find any other errors, please email us, so we can correct them in the next printing of the book. Thank you!

Murach college books and courseware since 1974