My Cart (0)

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
Print: $57.50
eBook: $52.50
Print + eBook: $70.00

From the start, servlets and JSPs have been a training problem because web programming with them requires so many different skills and so much conceptual background. But the first edition of this book solved that training problem: It presented the critical skills in the right order with plenty of examples, allowing developers to master all the complexities in a manageable way.

Now, this improved and updated 3rd Edition makes it even easier and faster for you to learn. And to prove to yourself that you will master all the servlet and JSP skills that you need to develop e-commerce applications, you can download the book’s e-commerce website that ties all the skills together.

College Instructors

Go to our instructor’s site to learn more about this book and its instructor’s materials.

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

  • About this Book
  • Table of Contents
  • FREE Downloads
  • Book FAQs
  • Corrections
  • Reviews

Who this book is for

This book is for anyone who wants to develop professional websites using Java servlets and JSPs. The only prerequisite is a basic understanding of the Java programming language, roughly equivalent to chapters 1 through 14 of our core Java book, Murach’s Java Programming. But you don’t need any web programming experience at all.

What you’ll learn in this book

Section 1: Get started right

In this section, you’ll learn:

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

By the time you’re through with this section, you’ll be ready to use the IDE to code and run servlets and JSPs on your own computer.

Section 2: The essential servlet and JSP skills

In this section, you’ll get a crash course in HTML and CSS, which are essential to the use of JSPs. Then, you’ll learn the skills for creating servlets and JSPs that you’ll use in almost every application. These chapters move from the simple to the complex as you learn how to work with 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, you’ll learn how to use both JDBC (Java Database Connectivity) and JPA (Java Persistence API) to work with a database. Although this section focuses on the use of MySQL databases, JDBC and JPA can be used for working with any database management system, including Oracle and SQL Server.

Section 4: Advanced servlet and JSP skills

In this section, you’ll learn the advanced servlet and JSP skills that you will need for certain types of web applications. This includes the use of JavaMail, SSL, authentication, encryption, HTTP, listeners, and filters. Then, the last chapter in this section shows you how to use JavaServer Faces, which is an alternative to using JSPs.

Since the chapters in this section have been designed to work independently of each other, you can read them in any order you want. This makes it easy for you to learn new skills whenever you need them.

Section 5: The Music Store website

This section presents an e-commerce website that puts the skills in the first four sections into context. This downloadable application illustrates best practices and provides code that you can use in your own applications. Once you understand how this website works, you will have all the skills you need for creating your own web applications.

Why you’ll learn faster and better with this book

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, you’ll use servlets when they’re appropriate and JSPs when they’re appropriate. As a result, you won’t waste your 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, you’ll learn faster and better than you would without one. In contrast, most competing books let you figure this out on your own.
  • Chapter 4 provides a crash course in HTML5 and CSS3. Since this is essential background for the use of JSPs, this means you won’t have to use a second book to figure out how HTML and CSS work.
  • Like all of our books, this one includes dozens of examples that range from the simple to the complex. That way, you can quickly see how a feature works from the simple examples, but you’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 instructional approach that starts by presenting the MVC pattern in chapter 2. That way, you will use the MVC pattern for all exercises and projects, and you won’t learn programming practices that you won’t or shouldn’t use on the job.
  • New chapters on how to use JPA (Java Persistence API) for database programming, 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 software you need

To create and use the web applications in this book, you need to install this software on your PC:

  • 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 you need for doing that if you’re working on a Windows or Mac system:

  • 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

If you’re using a Linux system, we assume that you’ll be able to install this software on your own. If not, you can use appendix B as a general guide and use the Internet to get any other information that you need.

Companion books

Murach’s Java Programming

Murach’s Java Programming is the perfect companion to our Servlets and JSP book. It presents all the Java skills that you need for using servlets and JSP. It lets you learn new Java skills whenever you need them. And it’s the best on-the-job Java reference that money can buy.

Murach’s HTML5 and CSS3 (Third Edition)

Murach’s HTML5 and CSS3 is a book that every web developer should have. It will help you expand your HTML and CSS skills in a professional way whenever you have some extra time. It covers today’s best practices for using HTML5 and CSS3. And it will answer your HTML and CSS questions as they arise.

Murach’s JavaScript and jQuery

Today, knowing a server-side language is not enough to be a top web developer. So Murach’s JavaScript and jQuery teaches you how to write client-side code for your web pages to enhance the user experience. Another great book for training and on-the-job reference.

Murach’s MySQL (Second Edition)
Murach’s Oracle SQL and PL/SQL for Developers (Second Edition)

If you use MySQL or Oracle Database with your web applications, you’ll want to have a copy of Murach’s MySQL (Second Edition) or Murach’s Oracle SQL and PL/SQL for developers (Second Edition) at your side. Each book is a complete course in the SQL and database administration skills you need as a web developer.

What people have said about the previous editions

“This is an excellent tutorial that will painlessly teach you how to write complex web applications. I doubt that there is another book available that makes the subject this easy to understand.”
-- Thomas Paul, JavaRanch.com

"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…. In short, I cannot recommend Murach’s Java Servlets and JSP (2nd Edition) 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

"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’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 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

“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.”
-- 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

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

Sample chapters

Chapter 1: An introduction to web programming with Java

This chapter introduces you to the terms and concepts that you need for working with Java servlets and JavaServer Pages (JSPs).

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

This chapter shows how to use the MVC pattern (or Model 2 architecture) to get the most from JSPs and servlets. From that point on, you’ll use servlets when they’re appropriate and JSPs when they’re appropriate.

Chapter 1 PDF (1.3Mb) Download Now

Chapter 2 PDF (0.5Mb) Download Now

Book applications and exercises

This download includes:

  • The source code and data for all the book applications, including the Music Store e-commerce application
  • The starting source code and data for the exercises in the book
  • The solutions to the book exercises so you can check your work

Appendix A for Windows users and appendix B for Mac users show how to install and use these files.

Exe file for Windows (21.1Mb) Download Now

Zip file for any system (21.0Mb) Download Now

What if you don’t use the NetBeans IDE?

Because we use the NetBeans IDE throughout our Servlets and JSP book, the downloadable files are arranged in the directory and file structure that NetBeans requires.

However, you can use another IDE like Eclipse with this book. In that case, you’ll just need to convert the NetBeans directory and file structure so it’s appropriate for your IDE.

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!

There are no reviews for this product yet.

To leave a review, please log in to your account.     Log In Here

Our Ironclad Guarantee

You must be satisfied. Try our print books for 30 days or our eBooks for 14 days. If they aren't the best you've ever used, you can return the books or cancel the eBooks for a prompt refund. No questions asked!

Contact Murach Books

For orders and customer service:

1-800-221-5528

Weekdays, 8 to 4 Pacific Time

College Instructors

If you're a college instructor who would like to consider a book for a course, please visit our website for instructors to learn how to get a complimentary review copy and the full set of instructional materials.