0% found this document useful (0 votes)
4 views

Murach s Java Servlets and JSP 3rd Edition Edition Joel Murach - Quickly access the ebook and start reading today

The document provides information about various Murach publications, including titles on Java, web development, and database programming, available for instant download at ebookgate.com. It includes links to specific editions and outlines the content structure of the 'Murach's Java Servlets and JSP 3rd Edition' book, detailing chapters and topics covered. Additionally, it lists other relevant books for Java programmers, web developers, .NET programmers, and database developers.

Uploaded by

boritlinja
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Murach s Java Servlets and JSP 3rd Edition Edition Joel Murach - Quickly access the ebook and start reading today

The document provides information about various Murach publications, including titles on Java, web development, and database programming, available for instant download at ebookgate.com. It includes links to specific editions and outlines the content structure of the 'Murach's Java Servlets and JSP 3rd Edition' book, detailing chapters and topics covered. Additionally, it lists other relevant books for Java programmers, web developers, .NET programmers, and database developers.

Uploaded by

boritlinja
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

Instant Ebook Access, One Click Away – Begin at ebookgate.

com

Murach s Java Servlets and JSP 3rd Edition Edition


Joel Murach

https://ebookgate.com/product/murach-s-java-servlets-and-
jsp-3rd-edition-edition-joel-murach/

OR CLICK BUTTON

DOWLOAD EBOOK

Get Instant Ebook Downloads – Browse at https://ebookgate.com


Click here to visit ebookgate.com and download ebook now
Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Murach s Java SE 6 1st Ed. Edition Joel Murach

https://ebookgate.com/product/murach-s-java-se-6-1st-ed-edition-joel-
murach/

ebookgate.com

Murach s C 2010 4th Edition Joel Murach

https://ebookgate.com/product/murach-s-c-2010-4th-edition-joel-murach/

ebookgate.com

Murach s HTML5 and CSS3 3rd Edition Anne Boehm

https://ebookgate.com/product/murach-s-html5-and-css3-3rd-edition-
anne-boehm/

ebookgate.com

Murach s JavaScript 2nd Edition Mary Delamater

https://ebookgate.com/product/murach-s-javascript-2nd-edition-mary-
delamater/

ebookgate.com
Murach s HTML5 and CSS3 1st Edition Zak Ruvalcaba

https://ebookgate.com/product/murach-s-html5-and-css3-1st-edition-zak-
ruvalcaba/

ebookgate.com

Murach s SQL Server 2012 for Developers 1st Edition Bryan


Syverson

https://ebookgate.com/product/murach-s-sql-server-2012-for-
developers-1st-edition-bryan-syverson/

ebookgate.com

Developing Java Servlets 2nd Edition James Goodwill

https://ebookgate.com/product/developing-java-servlets-2nd-edition-
james-goodwill/

ebookgate.com

Murach s ADO NET 4 Database Programming with VB 2010 4th


Edition Anne Boehm

https://ebookgate.com/product/murach-s-ado-net-4-database-programming-
with-vb-2010-4th-edition-anne-boehm/

ebookgate.com

Murach s ASP NET 4 Web Programming with VB 2010 4th


Edition Anne Boehm

https://ebookgate.com/product/murach-s-asp-net-4-web-programming-with-
vb-2010-4th-edition-anne-boehm/

ebookgate.com
I

3RD EDITION
TRAINING & REFERENCE

3RD EDITION

Joel Murach
Michael Urban

MIKE MURACH & ASSOCIATES, INC.


4340 N. Knoll Ave. • Fresno, CA 93722
www.murach.com • [email protected]
Authors: Joel Murach
Michael Urban
Editor: Ray Halliday
Production: Maria Spera

Books for Java programmers


Murach's Java Programming
Murach's Android Programming
Murach's Java Servlets and ISP (Jrd Edition)

Books for web developers


Murach's HTML5 and CSS3
Murach's Dreamweaver CC
Murach's JavaScript andjQuery
Murach's JavaScript and DOM Scripting
Murach's PHP and MySQL

Books for .NET programmers


Murach's C# 2012
Murach's ASP.NET 4.5 Web Programming with C# 2012
Murach's Visual Basic 2012
Murach's ASP.NET 4.5 Web Programming with VB 2012

Books for database developers


Murach's MySQL
Murach's Oracle SQL and PL!SQL
Murach's SQL Server 2012 for Developers

Books for IBM mainframe programmers


Murach's OS/390 and z/OS JCL
Murach's Mainframe COBOL
Murach's CfCS for the COBOL Programmer

Please check www.murach.com


for the most up-to-date Murach books

© 2014, Mike Murach & Associates, Inc.


All rights reserved.
Printed in the United States of America

10 9 8 7 6 5 4 3 2 1
ISBN-13: 978-1-890774-78-3
Content
Introduction

Section 1 Get started right


Chapter 1 An introduction to web programming with Java 3
Chapter 2 How to structure a web application with the MVC pattern 29
Chapter 3 How to use NetBeans and Tomcat 49

Section 2 Essential servlet and JSP skills


Chapter 4 A crash course in HTML5 and CSS3 89
Chapter 5 How to develop serv lets 127
Chapter 6 How to develop JavaServer Pages 173
Chapter 7 How to work with sessions and cookies 201
Chapter 8 How to use EL 243
Chapter 9 How to use JSTL 269
Chapter 10 How to use custom JSP tags 307

Section 3 Essential database skills


Chapter 11 How to use a MySQL database 347
Chapter 12 How to use JDBC to work with a database 377
Chapter 13 How to use JPA to work with a database 421

Section 4 Advanced servlet and JSP skills


Chapter 14 How to use JavaMail to send email 459
Chapter 15 How to use SSL to work with a secure connection 483
Chapter 16 How to restrict access to a web resource 501
Chapter 17 More security skills 525
Chapter 18 How to work with HTTP requests and responses 543
Chapter 19 How to work with listeners 571
Chapter 20 How to work with filters 587
Chapter 21 How to work with JavaServer Faces 613

Section 5 The Music Store website


Chapter 22 An introduction to the Music Store website 643
Chapter 23 The applications of the website 673

Appendixes
Appendix A How to set up your PC for this book 691
Appendix B How to set up your Mac for this book 711
••
Expanded contents VI I

Expanded contents
Section 1 Get started right
Chapter 1 An introduction to web applications
A typical web application ............................................................................................... 4
The components of a web application ............................................................................ 6
How static web pages work .............................................................................................8
How dynamic web pages work ..................................................................................... 10
Three approaches for Java web applications ................................ 12
Servlet/JSP .................................................................................................................... 12
JSF ................................................................................................................................. 12
Spring Framework ........................................................................................................ 12
An introduction to servlet/JSP web development ........................ 14
The software components ............................................................................................. 14
The architecture ............................................................................................................ 16
The standard directories and files ................................................................................. 18
Software for developing Java web applications ............................20
IDEs for developing Java web applications .................................................................. 20
Web servers for Java web applications ......................................................................... 22
Database servers for Java web applications .................................................................. 22
Tools for deploying Java web applications ................................................................... 24

Chapter 2 How to structure a web application


with the MVC patt'ern
Two patterns for servlet/JSP applications ..................................... 30
The Model 1 pattern ...................................................................................................... 30
The Model 2 (MVC) pattern ......................................................................................... 32
A servlet/JSP application that uses the MVC pattern ................... 34
The user interface ......................................................................................................... 34
The HTML for the first page ........................................................................................ 36
The CSS for both web pages ......................................................................................... 38
The servlet for the back-end processing ....................................................................... 40
The web.xml file ........................................................................................................... 42
The User class ............................................................................................................... 44
The JSP for the second page .........................................................................................46

Chapter 3 How to use NetBeans and Tomcat


How to get started with NetBeans .................................................. 50
How to start NetBeans .................................................................................................. 50
How to create a new web application ........................................................................... 52
How to use the Projects window ................................................................................... 56
How to open and close projects .................................................................................... 58
How to build , deploy, and run a web application ......................................................... 60
How to work with HTML and JSP files ............................................ 62
How to add an HTML or JSP' file ................................................................................. 62
How to edit an HTML or JSP file .................................................................................64
•••
VI 11 Expanded contents

How to work with Java files ............................................................. 66


How to add a Java class ................................................................................................. 66
How to add a servlet...................................................................................................... 68
How to edit a Java file ................................................................................................... 70
How to work with XML files .............................................................. 72
How to edit the web.xml file......................................................................................... 72
How to edit other XML files ......................................................................................... 72
Other skills for working with web applications ............................. 74
How to add existing files to a project............................................................................ 74
How to deploy a web application to a remote server .................................................... 74
How to work with a web application server .................................................................. 76
How to add a class library or a JAR file to a project .................................................... 78
How to register a database connection ......................................................................... 80

Section 2 Essential servlet and JSP skills


Chapter 4 A crash course in HTMLS and CSS3
How to work with HTML ................................................................... 90
The starting HTML for a web page.............................................................................. 90
How to code HTML elements ...................................................................................... 92
How to use the HTML5 semantic elements ................................................................. 94
How to use the div and span elements with HTML5 ................................................... 96
How to ensure cross-browser compatibility ................................................................. 98
How to code links ....................................................................................................... 100
How to include images ................................................................................................ 102
How to code tables ...................................................................................................... 104
How to work with CSS .................................................................... 106
How to provideCSS styles for an HTML page .......................................................... 106
How to code the basic CSS selectors .......................................................................... 108
How to codeCSS rule sets and com ments ................................................................. 110
How to useCSS to format a table ............................................................................... 112
How to code HTML forms ............................................................... 114
How to code a form ..................................................................................................... 114
How to code text boxes ............................................................................................... 116
How to code buttons ................................................................................................... 118
How to code check boxes and radio buttons............................................................... 120
How to code combo boxes and list boxes ................................................................... 122

Chapter 5 How to develop servlets


How to create and map a servlet ................................................... 128
How to create a servlet ................................................................................................ 128
How to map a servlet with the web.xml file ............................................................... 130
How to map a servlet with an annotation ................................................................... 132
How to request a servlet ................................................................ 134
How to use the HTTP GET method ........................................................................... 134
How to use the HTTP POST method ......................................................................... 136
When to use the HTTP GET and POST methods ...................................................... 136
Skills for working with servlets ..................................................... 138
How to get the values of the parameters..................................................................... 138
How to get the real path for a file ............................................................................... 140
Expanded contents IX

How to get and set request attributes .......................................................................... 142


How to forward requests ............................................................................................. 144
How to redirect responses........................................................................................... 144
How to validate data ....................................................................... 146
How to validate data on the client .............................................................................. 146
How to validate data on the server ............................................................................. 146
How to work with the web.xml file ................................................. 150
A complete web.xml file ............................................................................................. 150
How to work with initialization parameters ............................................................... 152
How to implement custom error handling .................................................................. 156
More skills for working with servlets ............................................ 160
How the methods of a servlet work ............................................................................ 160
Why you shouldn't use instance variables in servlets ................................................ 162
How to work with servlet errors .................................................... 164
How to solve common servlet problems ..................................................................... 164
How to print debugging data to the console ............................................................... 166
How to print debugging data to a log file ................................................................... 168

Chapter 6 How to develop JavaServer Pages


A crash course in EL and JSTL ..................................................... 174
How to code a JavaBean ............................................................................................. 174
How to use EL to get attributes and JavaBean properties .......................................... 176
How to enable the core JSTL library .......................................................................... 178
How to use the JSTL if tag ......................................................................................... 178
How to use JSP tags ....................................................................... 180
How to code directives, scriptlets, and expressions ................................................... 180
How to code comments in a JSP ................................................................................. 182
How to use standard JSP tags with Java Beans .......................... 184
An introduction to standard JSP tags ......................................................................... 184
How to code the useBean tag ...................................................................................... 186
How to code the getProperty and setProperty tags .................................................... 188
How to include a file in a JSP ........................................................ 190
A JSP that includes a header and footer file ............................................................... 190
Three techniques for including files in a JSP ............................................................. 194
How to fix common JSP errors...................................................... 196
Chapter 7 How to work with sessions and cookies
An introduction to session tracking .............................................202
Why session tracking is difficult with HTTP ............................................................. 202
How session tracking works in Java ...........................................................................202
An application that needs session tracking.................................................................204
How to work with sessions ............................................................206
How to set and get session attributes .......................................................................... 206
More methods of the session object. ........................................................................... 208
How to provide thread-safe access to the session object............................................ 210
How to work with cookies .............................................................. 212
An introduction to cookies ......................................................................................... 212
How to create and use cookies.................................................................................... 214
How to view and delete cookies ................................................................................. 216
X Expanded contents

Four methods for working with cookies ..................................................................... 218


A utility class for working with cookies ..................................................................... 220
How to work with URL rewriting and hidden fields ..................... 222
How to use URL rewriting to pass parameters .......................................................... 222
How to use hidden fields to pass parameters .............................................................. 224
The Download application ............................................................. 226
The user interface ....................................................................................................... 226
The file structure ......................................................................................................... 228
The web.xml file ......................................................................................................... 228
The code for the JSPs .................................................................................................. 230
The code for the servlet .............................................................................................. 234

Chapter 8 How to use EL


An introduction to JSP Expression Language ............................ 244
Advantages of EL........................................................................................................244
Disadvantages of EL ...................................................................................................244
Essential skills for working with EL.............................................. 246
How to use the dot operator to work with JavaBeans and maps ................................246
How to use EL to specify scope ................................................................................. 248
How to use the [ ] operator to work with arrays and lists ........................................... 250
How to use the dot operator to access nested properties ............................................ 252
Other skills for working with EL .................................................... 254
How to use the [ ] operator to access attributes .......................................................... 254
How to work with the other implicit EL objects ........................................................ 256
How to work with other EL operators ........................................................................ 260
How to disable EL....................................................................................................... 264
How to disable scripting ............................................................................................. 264

Chapter 9 How to use JSTL


An introduction to JSTL ................................................................. 270
The JSTL libraries ...................................................................................................... 270
How to make the JSTL JAR files available to your application ................................. 270
How to code the taglib directive ................................................................................. 270
How to code a JSTL tag .............................................................................................. 270
How to view the documentation for a library ............................................................. 272
How to work with the JSTL core library ....................................... 274
How to use the out tag ................................................................................................. 274
How to use the for Each tag ......................................................................................... 276
How to use the forTokens tag ...................................................................................... 278
Four more attributes for looping ................................................................................. 280
How to use the if tag ................................................................................................... 282
How to use the choose tag .......................................................................................... 284
How to use the url tag ................................................................................................. 286
Other tags in the JSTL core library ............................................................................ 288
The Cart application ....................................................................... 290
The user interface ....................................................................................................... 290
The code for the business classes ............................................................................... 292
The code for the servlets and JSPs .............................................................................. 296
Expanded contents XI

Chapter 10 How to use custom JSP tags


How to code a custom tag that doesn't have a body .................. 308
The tag ........................................................................................................................ 308
The tag element ........................................................................................................... 310
The tag class................................................................................................................ 312
How to code a custom tag that has a body .................................. 314
The tag ........................................................................................................................ 314
The tag element ........................................................................................................... 316
The tag class................................................................................................................ 316
How to code a custom tag that has attributes ............................. 318
The tag ........................................................................................................................ 318
The tag element ........................................................................................................... 320
The tag class................................................................................................................ 322
How to code a custom tag that reiterates its body ..................... 324
The tag ........................................................................................................................ 324
The tag element ........................................................................................................... 326
The tag class................................................................................................................ 326
How to work with scripting variables............................................330
An introduction to scripting variables ........................................................................ 330
The TEI class for four scripting variables .................................................................. 332
Classes, methods, and fields for working with custom tags ..... 334
Methods and fields of the Tag Support class ............................................................... 334
Methods and fields of the PageContext class.............................................................. 336
Methods and fields of the BodyTagSupport class ....................................................... 338
Methods and fields of the BodyContent class............................................................. 340

Section 3 Essential database skills


Chapter 11 How to use a MySQL database
An introduction to MySQL .............................................................348
What MySQL provides ............................................................................................... 348
Two ways to interact with MySQL ............................................................................. 350
How to use MySQL Workbench ..................................................... 352
The Home tab of MySQL Workbench ........................................................................ 352
How to open a database connection............................................................................ 354
How to start and stop the MySQL ser ver ................................................................... 356
How to enter and execute a SQL statement ................................................................ 358
How to enter and execute a SQL script....................................................................... 360
The SQL statements for creating a database ..............................362
How to create, select, and drop a database ................................................................. 362
How to create and drop a table ................................................................................... 364
How to insert multiple rows into a table ..................................................................... 366
The SQL statements for data manipulation ................................. 368
How to select data from a single table ........................................................................ 368
How to select data from multiple tables ..................................................................... 370
How to insert, update, and delete data........................................................................ 372
••
XI I Expanded contents

Chapter 12 How to use JDBC to work with a database


How to work with JDBC .................................................................. 378
An introduction to database drivers ............................................................................ 378
How to connect to a database ..................................................................................... 380
How to return a result set and move the cursor through it ......................................... 382
How to retrieve data from a result set. ........................................................................ 384
How to insert, update, and delete data ........................................................................ 386
How to work with prepared statements ...................................................................... 388
The SQL Gateway application .......................................................390
The user interface ....................................................................................................... 390
The code for the JSP ................................................................................................... 392
The code for the servlet .............................................................................................. 394
The code for the utility class ....................................................................................... 398
How to work with connection pooling .......................................... 400
How connection pooling works .................................................................................. 400
How to make a connection pool available .................................................................. 400
How to implement a connection pool .........................................................................402
How to use a connection pool .....................................................................................404
The Email List application .............................................................406
The user interface .......................................................................................................406
The code for the JSP ...................................................................................................406
The code for the servlet .............................................................................................. 408
The code for the database class .................................................................................. 410
The code for the utility class ....................................................................................... 416

Chapter 13 How to use JPA to work with a database


An introduction to JPA ................................................................... 422
A summary of JPA implementations .......................................................................... 422
Entities and the entity manager .................................................................................. 422
How to configure NetBeans to work with JPA ........................................................... 424
How to configure a persistence unit. ........................................................................... 426
How to code JPA entities ............................................................... 428
How to code the class for an entity .. ........................................................................... 428
How to use getter and field annotations ...................................................................... 430
How to code relationships between entities ................................................................ 432
How to work with dates and times .............................................................................. 434
How to retrieve data........................................................................ 436
How to get an entity manager factory ......................................................................... 436
How to retrieve an entity by primary key ................................................................... 438
How to retrieve multiple entities ................................................................................. 440
How to retrieve a single entity .................................................................................... 442
How to modify data ......................................................................... 444
How to insert, update, or delete a single entity ..........................................................444
How to update or delete multiple entities ...................................................................446
A complete JPA class.....................................................................448
The methods that modify data ....................................................................................448
The methods that retrieve data ................................................................................... 450
•••
Expanded contents XIII

Section 4 Advanced servlet and JSP skills


Chapter 14 How to use JavaMail to send mail
An introduction to the JavaMail API ............................................. 460
How email works ........................................................................................................460
How to install the JavaMail APL................................................................................ 462
Code that uses the JavaMail API to send an email message ...................................... 464
How to create and send an email message ................................. 466
How to create a mail session ....................................................................................... 466
How to create a message ............................................................................................. 468
How to address a message .......................................................................................... 470
How to send a message ............................................................................................... 472
Example classes that send an email message ............................ 474
A helper class for sending an email with a local SMTP server.................................. 474
A servlet that uses a helper class to send an email message ...................................... 476
A helper class for sending an email with a remote SMTP server .............................. 480

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


An introduction to SSL ................................................................... 484
How SSL works........................................................................................................... 484
How TLS works .......................................................................................................... 484
When to use a secure connection................................................................................ 484
How SSL authentication works................................................................................... 486
How to get a digital secure certificate ........................................................................ 488
How to configure a testing environment for SSL ........................ 490
How to create a certificate for testing ......................................................................... 490
How to enable SSL in Tomcat..................................................................................... 492
How to test a local SSL connection ............................................................................ 492
How to work with a secure connection ........................................ 494
How to request a secure connection ........................................................................... 494
A JSP that uses a secure connection ........................................................................... 496
How to return to a regular HTTP connection ............................................................ 496
How to switch from a local system to an Internet server ........................................... 496

Chapter 16 How to restrict access to a web resource


An introduction to authentication ................................................. 502
How container-managed authentication works........................................................... 502
T hree types of authentication ..................................................................................... 504
How to restrict access to web resources ..................................... 506
How to add a security role .......................................................................................... 506
How to add a security constraint ................................................................................ 506
How to implement a security realm .............................................. 508
How to implement the UserDatabaseRealm ............................................................... 508
How to implement the JDBCRealm ........................................................................... 510
How to implement the DataSourceRealm .................................................................. 514
How to allow access to authorized users ..................................... 516
How to use basic authentication.................................................................................. 516
How to use digest authentication ................................................................................ 516
How to use form-based authentication ....................................................................... 518
XIV Expanded contents

Chapter 17 More security skills


An introduction to website security.............................................. 526
Common website attacks ............................................................................................ 526
How to prevent social engineering attacks ................................................................. 526
An introduction to cryptography ................................................................................ 528
Common password attacks ......................................................................................... 530
How to protect passwords ............................................................. 532
How to hash passwords ............................................................................................... 532
How to salt passwords ................................................................................................. 534
A utility class for hashing and salting passwords ....................................................... 536
How to enforce password strength requirements ....................................................... 538

Chapter 18 How to work with HTTP requests and responses


An introduction to HTTP ................................................................ 544
An HTTP request and response .................................................................................. 544
Common MIME types ................................................................................................ 546
Common HTTP request headers ................................................................................ 548
Common HTTP status codes ...................................................................................... 550
Common HTTP response headers .............................................................................. 552
How to work with the request ........................................................ 554
How to get a request header ........................................................................................ 554
How to display all request headers ............................................................................. 556
How to work with the response ..................................................... 558
How to set status codes ............................................................................................... 558
How to set response headers ....................................................................................... 558
Practical HTTP skills ...................................................................... 560
How to return a spreadsheet ....................................................................................... 560
How to control caching ............................................................................................... 560
How to compress a response with GZIP..................................................................... 562
How to return a binary file as an attachment ............................................................. 564
How to create virtual HTML pages............................................................................ 566

Chapter 19 How to work with listeners


How to use a ServletContextlistener ........................................... 572
How to code a class for the listener ............................................................................ 572
How to register the listener ......................................................................................... 574
How to code a JSP that uses the attributes set by the listener .................................... 576
How to work with other types of listeners.................................... 578
A summary of the listener interfaces ......................................................................... 578
The methods of the listener interfaces ........................................................................ 580
The methods of the event objects ............................................................................... 582

Chapter 20 How to work with fliters


An introduction to filters ................................................................ 588
How filters work .......................................................................................................... 588
Two benefits of filters .................................................................................................. 588
When to use filters ...................................................................................................... 588
How to add a filter ........................................................................... 590
How to code a filter ..................................................................................................... 590
How to configure a filter ............................................................................................. 592
Expanded contents XV

Two filter classes ............................................................................ 596


How to code a filter that performs request-side processing ....................................... 596
How to code a filter that performs response-side processing ..................................... 598
Other skills for workin,g with filters............................................... 600
How to wrap a request or response ............................................................................. 600
How to use an initialization parameter ....................................................................... 604
How to restrict access by IP address .......................................................................... 606

Chapter 21 How to work with JavaServer Faces


An introduction to JSF ................................................................... 614
A summary of JSF versions ........................................................................................ 614
How to add a JSF library to a project ......................................................................... 614
How to used managed beans ........................................................ 616
How to create a managed bean ................................................................................... 616
How to set the scope of a bean ................................................................................... 618
How to use standard JSF tags ...................................................... 620
How to code the head and body tags .......................................................................... 620
How to display data from a managed bean................................................................. 622
How to code the inputText tag .................................................................................... 624
How to validate data ................................................................................................... 626
How to code a form action .......................................................................................... 628
The Email List application ............................................................. 630
The user interface ....................................................................................................... 630
The EmailList bean..................................................................................................... 632
The index.xhtml file .................................................................................................... 634
The thanks.xhtml file .................................................................................................. 636

Section 5 The Music Store website


Chapter 22 An introduction to the Music Store website
The user interface ........................................................................... 644
The Home and Catalog pages ..................................................................................... 644
The code for the Home page ....................................................................................... 644
The business layer .......................................................................... 648
The class diagrams ...................................................................................................... 648
The Product class ........................................................................................................ 648
The controller layer......................................................................... 652
The CatalogController class ....................................................................................... 652
The structure ................................................................................... 656
The directory structure ............................................................................................... 656
The web.xml file ......................................................................................................... 658
The context.xml file .................................................................................................... 658
The database ................................................................................... 662
The database diagram ................................................................................................. 662
The SQL script for the database ................................................................................. 662
The data layer .................................................................................. 666
The class diagrams...................................................................................................... 666
The ProductDB class .................................................................................................. 666
XVI Expanded contents

The JPA version compared to the JDBC version ........................ 670


The similarities ........................................................................................................... 670
The differences ........................................................................................................... 670

Chapter 23 The applications of the website


The user interface for end users ................................................... 674
The Download application.......................................................................................... 674
The Cart application ................................................................................................... 674
The user interface for administrators ........................................... 680
The Ad min Login page ............................................................................................... 680
The Ad min Menu page ............................................................................................... 682
The Process Invoices application................................................................................ 684
The Reports application .............................................................................................. 684

Appendix A How to set up your PC for this book


How to install the source code for this book .............................................................. 692
How to install the JDK ............................................................................................... 694
How to install NetBeans ............................................................................................. 696
How to install Tomcat ................................................................................................. 698
How to configure a Tomcat server .............................................................................. 700
How to test NetBeans and Tomcat .............................................................................. 704
How to install MySQL ................................................................................................ 706
How to create the databases for this book .................................................................. 708
How to restore the databases for this book................................................................. 708

Appendix B How to set up your Mac for this book


How to install the source code for this book .............................................................. 712
How to install the JDK ............................................................................................... 714
How to install NetBeans ............................................................................................. 716
How to install Tomcat ................................................................................................. 718
How to configure a Tomcat server .............................................................................. 720
How to test NetBeans and Tomcat .............................................................................. 724
How to install the MySQL Community Server .......................................................... 726
How to install MySQL Workbench ............................................................................ 728
How to create the databases for this book .................................................................. 730
How to restore the databases for this book................................................................. 730
How to update the password for the root user ............................................................ 732
Introduction
Java servlets and JavaServer Pages (JSPs) came into widespread use in the
late 1990s. For many years, servlets and JSPs were the dominant technology for
building web applications, especially for large enterprises. Although servlets and
JSPs are no longer the dominant approach to web programming, they have some
advantages over other newer approaches. In addition, since there are still many
legacy web applications powered by them, servlets and JSPs will continue to be
relevant for many years to come.
A quick search on a typical job website shows that there is still plenty
of demand for servlet and JSP developers. In addition, many of the skills for
working with servlets and JSPs also apply to newer approaches to Java web
development such as JavaServer Faces (JSF). As a result, learning servlets and
JSPs is still a great way to get started with Java web programming.

Who this book is for


This book is for anyone who wants to learn how to develop web applications
using servlets and JSP. 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. Once you have the necessary Java
skills, this book should work for you even if you have no experience developing
web applications.

Why you'll learn faster and better with this book


When we started writing this book, we knew we had to take a new approach
if we wanted to teach you everything you need to know in a way that's faster and
better than the other books. Here, then, are a few of the ways in which our book
differs from the others:
• Chapter 2 shows how to use the MVC pattern (or Model 2 architecture) to
get the most from JSPs and servlets. This allows you to 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.
•••
XVI 11 Introduction

• 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 leave you to figure this out on your own.
• Chapter 4 of this book 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.
• This book 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.
• At the end of most chapters, you'll find exercises that help you practice what
you've learned. They also encourage you to experiment and challenge you to
apply what you've learned in new ways. To help you get the most practice in
the least time, you'll start these exercises from existing applications.
• If you page through this book, you'll see that all of the information is
presented in "paired pages," with the essential syntax, guidelines, and
examples on the right page and the perspective and extra explanation on the
left page. This helps you learn faster by reading less... and this is the ideal
reference format when you need to refresh your memory about how to do
something.

What you'll learn in this book


• In section 1, you'll learn the concepts and terms that you need for web
programming. You'll learn how to use the MVC pattern to structure your
web applications. And you'll learn how to use the NetBeans IDE with a
Tomcat server to develop servlets and JSPs for web applications. When
you're done with this section, you'll be ready to learn how to code and run
servlets and JSPs on your own computer.
• In section 2, you'll get a crash course in HTML and CSS, which is essential
to the use of JSPs. Then, you'll learn the skills for creating servlets and JSPs
that you'll need for almost every application. These chapters move from the
simple to the complex as they show you how to work with servlets, JSPs,
sessions, cookies, JavaBeans, Expression Language (EL), the JSP Standard
Tag Library (JSTL), and custom JSP tags.
• In section 3, you'll learn how to use both JDBC (an older access method)
and the newer Java Persistence API (JPA) to work with a database. Since
MySQL is a popular open-source database that is commonly used for web
applications, this section shows how to work with it, but these principles can
be applied to the use of any database.
Introduction XIX

• In section 4, 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, it ends with an introduction to JavaServer Faces (JSF), an alternate
approach to JSP. Since we designed the chapters in this section to work
independently of each other, you can read them in any order you want. This
makes it easy to learn new skills whenever you need them.
• To complete your Java web programming skills, section 5 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 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.

What operating systems this book supports


The software you need for developing web applications with servlets and JSP
is available for Windows, Mac OS X, and Linux. If you're using Windows, you
can use appendix A to download and install this software. If you're using Mac
OS X, appendix B shows how to download and install this software. If you're
using another platform such as Linux, you probably already know how to install
this software! If not, you can use appendix B as a general guide and search the
Internet for more information if you need it.

How to get the software you need for this book


You can download all of the software that you need for this book for free
from the Internet. To make that easier for you, appendix A (PC) and B (Mac)
show how to download and install the software for this book. This software
includes Java SE, NetBeans, Tomcat, MySQL, and MySQL Workbench.

How our downloadable files make learning easier


To make learning easier, you can download the source code, files, and
databases for all the web applications presented in this book from our website
(www.murach.com). This includes the Music Store e-commerce application.
Then, you can view the complete code for these applications as you read each
chapter; you can compile and run these applications to see how they work; and
you can copy portions of code for use in your own web applications.
You can also download the starting points and solutions for the exercises
in this book. That way, you don't have to start every exercise from scratch.
This takes the busywork out of doing these exercises. As a result, you get more
practice in less time. In addition, if you encounter a problem, you can easily
check the solution. This helps you to keep moving forward with less chance that
you'll get stuck on a minor issue. For more information about these downloads,
please see appendix A (PC) or appendix B (Mac).
XX Introduction

Support materials for trainers and instructors


If you're a corporate trainer or a college instructor who would like to use
this book for a course, we offer an Instructor's CD that includes: (1) PowerPoint
slides, (2) test banks, (3) objectives, (4) additional exercises that aren't in this
book, (5) solutions to those exercises, (6) projects, and (7) solutions to those
projects.
To learn more about this Instructor's CD and to find out how to get it, please
go to our website at www.murach.com. Or, if you prefer, you can call Kelly at
1-800-221-5528 or send an email to [email protected].

Please let us know how this book works for you


When we started the first edition of this book, our goal was to teach you
how to develop real-world web applications with servlets and JSPs as quickly
and easily as possible. Now, with this third edition of this book, we hope we've
taken that to a new level. So if you have any comments, please email us at
[email protected].
Thanks for buying this book. Thanks for reading it. And good luck with your
web programming.

Joel Murach
Author
ection

Get started right


The three chapters in this section provide the background information that
you need for developing web applications with servlets and JavaServer
Pages (JSPs). In chapter 1, you'll learn what web programming is and how
servlets and JSPs work. In chapter 2, you'll learn how to use the MVC
pattern to structure a web application that uses servlets and JSPs.
Then, in chapter 3, you'll learn how to use the NetBeans IDE
(Integrated Development Environment) to work with the HTML, servlet,
JSP, and XML files that make up a servlet/JSP application. In addition,
you'll learn how to use NetBeans to run a Java web application on a
Tomcat server that's running on your computer.
An introduction to web
programming with Java
This chapter introduces some concepts and terms that you should learn before
you start web programming with servlets and JavaServer Pages (JSPs). In addi­
tion, it describes three approaches that you can use for developing Java web
applications. Finally, it describes some software that you can use to develop
and deploy serv let/JSP applications.

An introduction to web applications ....................................4


A typical web application ................................................................................4
The components of a web application .............................................................6
How static web pages work .............................................................................8
How dynamic web pages work ...................................................................... 10
Three approaches for Java web applications ................... 12
Servlet/JSP ..................................................................................................... 12
JSF.................................................................................................................. 12
Spring Framework ......................................................................................... 12
An introduction to servlet/JSP web development ............ 14
The software components.............................................................................. 14
The architecture ............................................................................................. 16
The standard directories and files ................................................................. 18
Software for developing Java web applications ...............20
IDEs for developing Java web applications ...................................................20
Web servers for Java web applications .......................................................... 22
Database servers for Java web applications................................................... 22
Tools for deploying Java web applications ................................................... 24
Perspective ...........................................................................26
4 Section 1 Get started right

An introduction to web applications


A web application is a set of web pages that are generated in response to
user requests. The Internet has many different types of web applications, such as
search engines, online stores, auctions, news sites, discussion groups, and games.

A typical web application


Figure 1-1 shows the first two pages of the shopping cart application that's
available from www.murach.com. Here, the first page presents some information
about our Java book. This page contains an Add To Cart link. When you click on
this link, the web application adds the book to your cart and displays the second
page, which shows all of the items in your cart.
The second page lets you change the quantity for an item or remove an item
from the cart. It also lets you continue shopping or begin the checkout process.
In this book, you'll learn all the skills you need to create a shopping cart applica­
tion like this one.
If you take a closer look at these web pages, you can learn a little bit about
how this application works. For the first page, the Address box of the browser
shows an address that has an htm extension. This means that the HTML code for
this page is probably stored in a file with an htm extension.
In contrast, the Address box for the second page shows the address of a
servlet that was mapped to the ordering/cart URL. This means that the HTML
code for this page was generated by a servlet. After the servlet address, you can
see a question mark and one parameter named productCode that has a value of
"htm5". This is the parameter that was passed from the first page.
Chapter 1 An introduction to web programming with Java 5

The first page of a shopping cart application


CJ @}

--
I:] Murach'sJava Progammi x

Cl
:=·
n1urach.cor11/books/javp/index.htm
Apps For quick acces�, place your bookmarks here on the bookmark� bar. Import bookmark� now... L] Other bookmarks

Home I Books I Dov,nloads I Trainers I Instructors I Customer Service I view cart I


Murach's Java Programming
by Joel t,lu ra ch
23 chapters, 802 pages, S40 illustrations
Published November 2011
ISBN: 978-1-890774-65-'3

Book price: S57.50; SAVE 30%, now just S4-0.25


eBook price: S47.50; SAVE 30%, nov, just S33.25
Book• eBook: S67.50; B-est Value! SAVE 30% 1 now Just 547.25

"f Jove your Java book. ft cuts :right to the essential information,
provjding the perfect balance betli'een too many details and too
little information. I bought another wel/-knovl'n Java book, but I
spent several hours trying to tearn what r learned from your book
in about 45 minutes." I add book I
I add ebook I
FREE do1Nnload of
sample chapters That's what one developer wrote us about an earlier edition of our
FREE download of the
�ook applications
core Java book. Now, you can expect th1at same practical, time­
saving approach in the current edition that covers the latest
I add both I
'.'\/hat soft,,vare you release of Java Standard Edition, Java SE 7 (or JDK 1.7).
More about the eBook
n��r1

The second page of a shopping cart application


CJ @}
Cl Mike Murach & AssociatE: x
Cl n1urach.cor11/ordering/cart?productCode = htmS --
:=· Apps For quick access, place your bookmarks here on the bookmark� bar. Import bookmark� now... L] Other bookmarks

Home I Books I Oov1nloads I Trainers I Instructors I Customer Service I view cart I


Your cart

Qty Description

!1 I [ Update I Murach's Java Programming [ Remove j


E � [ Update I Murach's HTML5 and CSS3 [ Remove j
To change the quantity, enter the new quantity and click on the Update button.

[ Continue Shopping ] I Proc eed t o Checkout ]

Do you have a pron1otion code to apply to this order?


If so, enter it here: [ =1
Other books related to what you just picked

Figure 1-1 A typical web application


6 Section 1 Get started right

The components of a web application


Figure 1-2 shows the basic components that make up a web application.
Because a web application is a type of c lientlserver application, the compo­
nents of a web application are stored on either the client computer or the server
computer.
To access a web application, you use a web browser that runs on a client
computer. One widely used web browser is Google Chrome, and a popular
alternative is Mozilla Firefox.
The web application itself is stored on the server computer. This computer
runs web server software that enables it to send web pages to web browsers.
Although there are many web servers, the Apache Software Foundation's Apache
HTTP Server is one of the most popular. Many developers refer to it just as
Apache.
Because most web applications work with data that's stored in a database,
most servers also run a database management system (DBMS), which is also
known as a database server. Two of the most popular for Java development are
MySQL and Oracle. When you use a database server, it doesn't have to run on
the same server as the web server software. In fact, a separate database server is
often used to improve an application's overall performance.
Although this figure shows the client and server computers connected via the
Internet, this isn't the only way a client can connect to a server in a web applica­
tion. If the client and the server are on the same Local Area Network (LAN), they
function as an intranet. Since an intranet uses the same protocols as the Internet,
a web application works the same on an intranet as it does on the Internet.
Chapter 1 An introduction to web programming with Java 7

Components of a web application


Client Server
computer computer

Internet

- connection
- I

Web Web server


browser Database server

Description
• Web applications are a type of client/server application. In a client/server applica­
tion, a user at a client computer accesses an application at a server computer. For a
web application, the client and server computers are connected via the Internet or
an intranet.
• In a web application, the user works with a web browser at the client computer. The
web browser provides the user interface for the application. One widely used web
browser is Google Chrome, but other web browsers such as Mozilla Firefox and
Internet Explorer are also widely used.
• A web application runs on the server computer under the control of web server
software. The Apache server is one of the most widely used web servers.
• For most web applications, the server computer also runs a database management
system (DBMS), which is also known as a database server. For servlet and JSP
applications, Oracle and MySQL are two of the most popular database management
systems.

Figure 1-2 The components of a web application


8 Section 1 Get started right

How static web pages work


HTML (Hypertext Markup Language) is the language that the browser
renders to the web pages that make up a web application's user interface. Some
web pages are static web pages, which are the same each time they are viewed.
In other words, they don't change in response to user input.
Figure 1-3 shows how a web server handles static web pages. The process
begins when a user at a web browser requests a web page. This can occur when
the user enters a web address into the browser's Address box or when the user
clicks a link that leads to another page. In either case, the web browser uses a
standard Internet protocol known as Hypertext Transfer Protocol (HTTP) to send
a request known as an HTTP request to the website's server.
When the web server receives an HTTP request from a browser, the server
gets the requested HTML file from disk and sends the file back to the browser
in the form of an HTTP response. The HTTP response includes the HTML
document that the user requested along with any other resources specified by the
HTML code such as graphics files.
When the browser receives the HTTP response, it renders the HTML
document into a web page that the user can view. Then, when the user requests
another page, either by clicking a link or typing another web address in the
browser's Address box, the process begins again.
Chapter 1 An introduction to web programming with Java 9

How a web server processes static web pages


Client Server
HTTP
request

HTTP
response

Description
• Hypertext Markup Language (HTML) is the language that the web browser converts
into the web pages of a web application.
• A static web page is an HTML document that's stored in a file and does not change
in response to user input. Static web pages have a filename with an extension of
.htm or .html.
• Hypertext Transfer Protocol (HTTP) is the protocol that web browsers and web
servers use to communicate.
• A web browser requests a page from a web server by sending the server a message
known as an HTTP request. For a static web page, the HTTP request includes the
name of the HTML file that's requested.
• A web server replies to an HTTP request by sending a message known as an HTTP
response back to the browser. For a static web page, the HTTP response includes
the HTML document that's stored in the HTML file.

Figure 1-3 How static web pages work


10 Section 1 Get started right

How dynamic web pages work


In contrast to a static web page, a dynamic web page changes based on the
parameters that are sent to the web application from another page. For instance,
when the Add To Cart button in the first page in figure 1-1 is clicked, the static
web page calls the web application and sends one parameter to it. Then, the web
application generates the dynamic web page and sends the HTML for it back to
the browser.
Figure 1-4 shows how this works. When a user enters data into a web page
and clicks the appropriate button, the browser sends an HTTP request to the
server. This request contains the address of the next web page along with any
data entered by the user. Then, when the web server receives this request and
determines that it is a request for a dynamic web page, it passes the request back
to the web application.
When the web application receives the request, it processes the data that the
user entered and generates an HTML document. Next, it sends that document to
the web server, which sends the document back to the browser in the form of an
HTTP response. Then, the browser displays the HTML document that's included
in the response so the process can start over again.
Chapter 1 An introduction to web programming with Java 11

How a web server processes dynamic web pages


Client Server
HTTP
request

HTTP
response

Description
• A dynamic web page is an HTML document that's generated by a web applica­
tion. Often, the web page changes according to parameters that are sent to the web
application by the web browser.
• When a web server receives a request for a dynamic web page, the server passes
the request to the web application. Then, the application generates a response, such
as an HTML document, and returns it to the web server. The web server, in turn,
wraps the generated HTML document in an HTTP response and sends it back to
the browser.
• Most modern web applications store and retrieve data from a database that runs on
a database server.
• The browser doesn't know or care whether the HTML was retrieved from a static
HTML file or was dynamically generated by the web application. Either way, the
browser displays the HTML document that is returned.

Figure 1-4 How dynamic web pages work


12 Section 1 Get started right

Three approaches
for Java web applications
There are many ways to develop Java web applications. Figure 1-5 describes
three approaches that are commonly used today. When developing Java web
applications, you typically use parts of the Java Enterprise Edition (Java EE)
specification. This specification describes how web servers can interact with all
Java web technologies including servlets, JavaServer Pages (JSP), JavaServer
Faces (JSF), Java Persistence API (JPA), Enterprise JavaBeans (EJB), and more.

Servlet/JSP
In a well-structured servlet/JSP application, servlets store the Java code that
does the server-side processing, and JavaServer Pages (JSPs) store the HTML
that defines the user interface. This HTML typically contains links to CSS and
JavaScript files. To run a web application that uses servlets and JSPs, you only
need to work with the servlet/JSP part of the Java EE specification.
Since the servlet/JSP API is a relatively low-level API, it doesn't do as much
work for the developer as the other two APis. However, the servlet/JSP API gives
the developer a high degree of control over the HTML, CSS, and JavaScript
that's returned to the browser. In addition, the servlet/JSP API is the foundation
for the other two approaches. As a result, it's a good place to get started with
Java web programming. As you progress through this book, you'll learn how to
develop servlet/JSP applications.

JSF
JavaServer Faces (JSF) is a newer technology that's designed to replace
both servlets and JSPs. It provides a higher-level API that does more work for
the programmer. When you use JSF, you typically use more Java EE features
than you do with the servlet/JSP approach.
When you use JSF, you can also use Enterprise JavaBeans (EJBs) to define
server-side components. Although there are some benefits to using EJBs, they're
overkill for most websites. As a result, this book doesn't show how to use them.

Spring Framework
Like JSF, the Spring Framework is a higher-level API that does more work
for the programmer than the servlet/JSP API. However, due to the way it's struc­
tured, the Spring Framework still gives the developer a high degree of control
over the HTML/CSS/JavaScript that's returned to the browser. As a result, if
control over HTML/CSS/JavaScript is a priority for your website, the Spring
Framework might be the right approach for you.
Chapter 1 An introduction to web programming with Java 13

Three approaches for developing Java web apps


Servlet/JSP
- Is a lower-level API that does less work for the programmer.
- Provides a high degree of control over the HTML/CSS/JavaScript that's
returned to the browser.
JSF
- Is a higher-level API that does more work for the programmer.
- Makes it more difficult to control the HTML/CSS/JavaScript that's returned to
the browser.
Spring Framework
- Is a higher-level API that does more work for the programmer.
- Provides a high degree of control over the HTML/CSS/JavaScript that's
returned to the browser.

Description
• The Java Enterprise Edition (Java EE) specification describes how web servers can
interact with all Java web technologies including servlets, JavaServer Pages (JSP),
JavaServer Faces (JSF), Java Persistence API (JPA), and Enterprise JavaBeans
(EJB).
• In a well-structured servlet/JSP application, servlets store the Java code that does
the server-side processing, and JavaServer Pages (JSPs) store the HTML that
defines the user interface. This typically includes links to the CSS and JavaScript
for the user interface.
• JavaServer Faces (JSF) is a newer technology than servlet/JSP that provides a
higher -level API that replaces both servlets and JSPs. For more on JSF, see chapter
21.
• Java Persistence AP/ (IPA) is an API for working with databases. It can be used
with servlet/JSP, JSF, or Spring. For more on JPA, see chapter 13.
• Enterprise JavaBeans (EJB) can be used to define server-side components. Since
these components are overkill for most websites, they aren't described in this book.

Figure 1-5 Three approaches for developing Java web apps


14 Section 1 Get started right

An introduction to servlet/JSP
web development
This topic introduces you to servlet/JSP development. In particular, it pres­
ents the software components, application architecture, and standard directories
that you typically use when you develop Java web applications.

The software components


Figure 1-6 shows the primary software components for a servlet/JSP web
application. By now, you should understand why the server must run web server
software. In addition, to work with servlets and JSPs, the server must also run a
servlet/JSP engine, which is also known as a servlet/JSP container. In this book,
you'll learn how to use the Tomcat server. This server is one of the most popular
servers for Java web applications, and it includes both a web server and a
servlet/JSP engine.
For a servlet/JSP engine to work properly, the engine must be able to access
the Java Development Kit (JDK) that comes as part of the Java Standard Edition
(Java SE). The JDK contains the Java compiler and the core classes for working
with Java. It also contains the Java Runtime Environment (IRE) that's necessary
for running compiled Java classes. Since this book assumes that you already
have some Java experience, you should already be familiar with the JDK and the
JRE.
Since all servlet/JSP engines must implement the servlet/JSP part of the Java
EE specification, all servlet/JSP engines should work similarly. In theory, this
makes servlet/JSP code portable between servlet/JSP engines and application
servers. In practice, though, there are minor differences between each servlet/JSP
engine and web server. As a result, you may need to make some modifications to
your code when switching servlet/JSP engines or web servers.
Since most servlet/JSP web applications store their data in a database, the
server typically runs a database server too. In this book, you'll learn how to use
MySQL as the database server. This software is open-source and commonly used
with servlet/JSP applications.
Chapter 1 An introduction to web programming with Java 15

The components of a servlet/JSP application


Client

HTTP HTTP
request response

Server

Description
• A servlet/JSP application must have a web server and a servlet/JSP engine, also
known as a servlet/JSP container, to process the HTTP request and return an HTTP
response, which is typically an HTML page. Most servlet/JSP applications use
Tomcat as both the web server and the servlet/JSP engine.
• Most servlet/JSP applications use a database to store the data that's used by the
application. Many servlet/JSP applications use MySQL as the database, though
there are many other databases to use.
• For a servlet/JSP engine to work, it must have access to Java's Java Development
Kit (JDK), which comes as part of the Java Standard Edition (Java SE). Among
other things, the JDK contains the core Java class libraries, the Java compiler, and
the Java Runtime Environment (IRE).

Figure 1-6 The components of a servlet/JSP application


16 Section 1 Get started right

The architecture
Figure 1-7 shows the architecture for a typical web application that uses
servlets and JSPs. This architecture uses three layers: (1) the presentation layer,
or user interface layer, (2) the business rules layer, and (3) the data access
layer. In theory, the programmer tries to keep these layers as separate and
independent as possible. In practice, though, these layers are often interrelated,
and that's especially true for the business and data access layers.
The presentation layer consists of HTML pages and JSPs. Typically, a web
designer works on the HTML stored in these pages to create the look and feel of
the user interface. Later, a Java programmer may need to edit these pages so they
work properly with the servlets of the application.
The business rules layer uses servlets to control the flow of the application.
These servlets may call other Java classes to store or retrieve data from a data­
base, and they may forward the results to a JSP or to another servlet. Within the
business layer, Java programmers often use a special type of Java class known as
a JavaBean to temporarily store and process data. A JavaBean is typically used
to define a business object such as a User or Invoice object.
The data layer works with the data of the application on the server's disk.
Typically, this data is stored in a relational database such as MySQL. However,
this data can also be stored in text files, binary files, and XML files. Or, it can
come from web services running on the other servers.
Chapter 1 An introduction to web programming with Java 17

The architecture for a typical servlet/JSP application


Presentation layer

Business rules layer

Data access layer

Description
• The presentation layer for a typical servlet/JSP web application consists of HTML
pages and JSPs.
• The business rules layer for a typical servlet/JSP web application consists of
servlets. These servlets may call other Java classes including a special type of Java
class known as a JavaBean. As you progress though this book, you'll learn how to
use several special types of tags within a JSP to work with JavaBeans.
• The data access layer for a typical Java web application consists of classes that
read and write data that's stored on the server's disk drive.
• For most web applications, the data is stored in a relational database such as
MySQL. However, it may also be stored in binary files, text files, or XML files.

Figure 1-7 The architecture for a servlet/JSP web application


18 Section 1 Get started right

The standard directories and files


Figure 1-8 shows a simplified version of the directory structure for the
Music Store application that's presented at the end of this book. Some of these
directories are part of the servlet and JSP specifications. As a result, they are
standard for all web applications. For example, all web applications that use
servlets must have the WEB-INF and WEB-INF\classes directories. In addition,
you can optionally include other standard directories such as the WEB-INF\lib
directory or the META-INF directory.
Of course, to organize and structure an application, a programmer can create
other directories within these directories. In this figure, for example, the admin,
cart, and download directories organize the Administration, Cart, and Download
sections of the Music Store application.
To start, each web application must have a root directory. This directory
can be referred to as the document root directory, or just document root. In this
figure, the document root directory is named musicStore, and it is subordinate
to Tomcat's webapps directory. Then, all of the other directories and files for the
application must be subordinate to this document root directory.
The WEB-INF directory that's subordinate to the document root directory
typically contains a web.xml file for the application. You'll learn more about
this file in the next chapter. In addition, you can use this directory or any of its
subdirectories to store files that you don't want to be directly accessible from the
web. For example, some applications in this book use the WEB-INF directory to
store data files. This prevents users from directly accessing these files.
The WEB-INF directory also has a few standard directories that are subor­
dinate to it. In particular, the WEB-INF\classes directory is the root directory
for all Java classes for the application that aren't stored in JAR files, including
servlets. Typically, these are the classes that you write. In contrast, the
WEB-INF\lib directory contains the JAR files that contain any Java class librar­
ies for the application. Typically, you get these JAR files from a third party.
Remember, though, that Tomcat's lib directory stores the JAR files for the class
libraries that are available to all web applications running on the web server. As a
result, you only use the WEB-INF\lib directory if you want to make the JAR file
available to just that one application.
To organize the classes that you create for the application, you can store
them in packages. In that case, you need to create one subdirectory for each
package. For example, this figure shows five packages. T hree of these packages
(music.admin, music.cart, and music.download) contain servlets that work with
the Administration, Cart, and Download sections of the application while the
other two contain the Java classes that provide the business objects
(music.business) and data access objects (music.data) for the application.
As you progress through this book, you'll learn how to use some other
standard directories and files to deploy web applications. For example, if you
want to use the database connection pool that's available from Tomcat, you can
modify the context.xml file that's stored in the META-INF directory as described
in chapter 12. For now, though, this figure should give you a general idea of what
it takes to deploy a web application.
Chapter 1 An introduction to web programming with Java 19

The directory structure for a web application named musicStore


W tomcat
:...... webapps
:......• musicStore (the root directory for HTML and JSP files)
····· admin
····· cart
····· catalog
···· META-INF (content.xml file)
:
:....• WEB-INF (the web.xml file)
:...... classes (the root directory for Java classes)
:......• music
business
controllers
.. . . . data
. ····· util
i ......• lib (JAR files for Java class libraries)

A summary of the directories and files for a web application


Directory Description
(root) This directory and its subdirectories typically contain the
HTML and JSP files for the application.
\WEB-INF This directory typically contains a file named web.xml.
You can use this file to configure the servlets and other
components that make up the application. In addition, this
directory is not directly accessible from the web.
\WEB-INF\classes This directory and its subdirectories contain the servlets
and other Java classes for your application. Each subdirec­
tory must correspond with the package for the Java class.
\WEB-INF\lib This directory contains any JAR files that contain Java
class libraries that are used by the web application.
\META-INF This directory contains the context.xml file. You can use
this file to configure the web application context.

Description
• The top-level directory for a web application is known as its root directory.
• A Java web application is a hierarchy of directories and files in a standard layout
defined by the Java EE specification. All Java web applications must use the first
three directories that are summarized above.
• To make classes within a JAR file availa ble to more than one web application, you
can put the JAR file in Tomcat's lib directory.

Figure 1-8 The standard directories and files for a servlet/JSP web application
20 Section 1 Get started right

Software for developing Java


web applications
This topic presents some of the software options that you have for develop­
ing Java web applications.

IDEs for developing Java web applications


In the early days of Java web programming, programmers commonly used
text editors to enter, edit, compile, and test the HTML, JSP, Java, servlet, and
XML files that make up a web application. Today, however, many Integrated
Development Environments (IDEs) are available that make Java web program­
f
ming more ef icient.
Two of the most popular IDEs for developing Java web applications are
NetBeans and Eclipse. Both are open-source, and both are available for free.
Of the two, we think that NetBeans is easier to use, especially when you're
getting started with web programming. That's why we recommend that you use
NetBeans with this book.
In figure 1-9, for example, you can see the NetBeans IDE with the project
for chapter 2 in the Projects window, the code for a servlet class in the editor
window, and runtime messages in the Output window. This is similar to what
you'll find in most IDEs. As a result, once you're done with this book, you can
easily apply the skills that you learn with NetBeans to another IDE.
Although we recommend using NetBeans with this book, you should be able
to use another IDE with this book if you prefer. To do that, though, you will need
to figure out how to import the source code for this book into your IDE so you
can compile and run the sample applications and complete the exercises. In addi­
tion, you will need to use your IDE to perform the tasks presented in chapter 3.
Since the JDK, N etBeans, Tomcat, and MySQL can be run by most operat­
ing systems, Java web developers aren't tied to a specific operating system. In
fact, developers often use Windows or Mac OS X during development. However,
when the applications are ready for release, they are often deployed to a Linux or
Unix server.
Chapter 1 An introduction to web programming with Java 21

The NetBeans IDE


0 ch02e-mail - NetBe-ans IOE B.O I= I @J :·
cv, I

File Edit View Navigate Source Re-factor Run Debug Profile Team Tools Window Help IQ.• Search (Ctrl+I)

Projects • Files I I Services I g


� index.html •I� I
x Ll:!IIL.-�...;...;�-1..
Emaillistservlet.java rll1 thanks.jsp i:& I 818 G@J
s-� ch02email I '1? �
�����������������__,::::::::....:::...::::,
% I <::iii �� I O D 11/Q! !
I� •
Source History I � (B • � • I to_ '¢ � � :::::� I EB
$m Web Pages package murach.email;
! El META-INF �
! iii � WEB-INF 3 S import java.io. ";
i 13...� styles 4 import javax.servlet.*;
i !· [!I
! L....�
index.html
thanks.jsp
s import javax. servlet.http."; -
6
$@ Source Packages 7 import murach.business.User; -
! El··· E!3 murach.business
e - import m.urach.data.OserDB;
i iii § murach.data 9
! El
§3 murach.email 10 public class EmailLi.stSerwlet extends HttpServlet {
i L. Ii E maillistservlet.java 11
$ (R "J:est Packages 12 @override
9.. � Libraries @ protected void doPost(HttpServletRequest request,
i:p � TestL1braries 14 HttpServletResponse response)
El··� Configuratiori Files 1s G throws ServletException, IOException {
i!J-� ch04email

do Post - Navigator x I
16
17 String url = "/index.htnl"; -
..-11 ..-1
Q
18
Members <empty> LaJ 19 t/ get c�rre�t act10�
&'.> Emaillistservlet : : HttpServlet 20 String action= request.getParameter("action"); ...
!·· 'ft:>
doGet(HttpSe-rvletRequestrequest, H
L.t:J doPost(HttpServletRequest request, I :===::;::: = ===============
t)
� Emaillistservlet )

Output I Ii
=============== =======:
doPost ) url ) X

• ch02emai (run) n I Tomcat 8.0 Log R I Tomcat8.0 ae I


• J .o--��.��������������-����--,
11-Apr-2014 15: 48: 44 _394 INFO (:m&i. n] erg_ apac:h@ _ceyetoLAb:!ltrac:tPretocel _!ltart Starting Protoc:oll •
11-Apr-2014 15: 48: 44 _ 399 INFO (:m&i.n] erg_apac:h@ _ cata.lina _,.ta.rtup.Catali.na_ :!ltart S@rv@r Bta.rtup :
11-Apr-2014 15:48:46_047 INFO lihttp-nio-8080-exec-41 org_apache_catalina_core_StandardContext.r1
11-Apr-2014 15: 48: 47. l 7f> INFO llhttp-nio-8080-exec-4 I org .apache- ca:calina._ c:ore. Sta.nda.rdContext. rc
c::::i

�1 rrr J

17:36 I INS

Popular IDEs for Java web development


NetBeans
Eclipse
IntelliJ IDEA

Description
• An Integrated Development Environment (/DE) is a tool that provides all of the
functionality that you need for developing web applications.
• NetBeans and Eclipse are popular IDEs for Java web development that are
open-source and free.
• Chapter 3 shows how to use NetBeans for developing Java web applications. We
recommend using this IDE with this book.

Figure 1-9 IDEs for developing Java web applications


22 Section 1 Get started right

Web servers for Java web applications


Figure 1-10 describes two popular web servers for Java web applications.
This book shows how to use the Tomcat server, which is the most popular server
for Java web applications. Tomcat includes a web server named Coyote and a
servlet/JSP engine named Catalina. As a result, this server can work with the
servlet/JSP part of the Java EE specification.
In contrast, the GlassFish server implements the complete Java EE specifica­
tion. Since it's more than just a servlet/JSP engine, it's known as an application
server. The advantage of using an application server like GlassFish is that it
provides more features for working with other parts of the Java EE specification
such as JSF and JPA. One disadvantage is that it requires more system resources
than Tomcat. As a result, it may not run as quickly on your computer.
This figure also lists four other popular web servers for Java applications.
These web servers include WildFly, which was formerly known as JBoss, Jetty,
Oracle WebLogic, and IBM WebSphere. Each server implements some or all of
the Java EE specification, and each server has its advantages and disadvantages.

Database servers for Java web applications


This figure also describes the most popular database server for Java web
applications, the MySQL database server. This is the database server that you'll
learn to use in this book. Like Tomcat and GlassFish, MySQL is open-source
and runs on all modern operating systems. In addition, MySQL implements most
of the SQL standard. As a result, database code developed for the MySQL server
should be mostly portable between database servers.
Although many Java web applications use a MySQL database, some devel­
opers prefer other open-source databases, such as PostgreSQL. On the other
hand, some large enterprises prefer using a proprietary database like Oracle to
store mission-critical data.
Chapter 1 An introduction to web programming with Java 23

Two popular web servers


Tomcat
- Is a servlet/JSP engine that includes a web server.
- Is free, open-source, and runs on all modern operating systems.
- Is a popular web server for Java web applications.

GlassFish
- Is a complete Java EE application server.
- Is free, open-source, and runs on all modern operating systems.
- Provides more features than Tomcat.
- Requires more system resources than Tomcat.

Other popular web servers


- WildFly (formerly JBoss)
- Jetty
- Oracle WebLogic
- IBM WebSphere

A popular database server


MySQL
- Is a relational database server that implements most of the SQL standard.
- Is free, open-source, and runs on all modern operating systems.
- Is the most popular database server for Java web applications.

Other popular database servers


- PostgreSQL
- Oracle

Description
• A servlet/JSP engine is the software that allows a web server to work with the
servlet/JSP part of the Java EE specification.
• Tomcat is one of the most popular servlet/JSP engines. It includes a web server
named Coyote and a servlet/JSP engine named Catalina.
• A Java EE application server is the software that allows the web server to work
with the entire Java EE specification including servlets, JSP (JavaServer Pages),
JSF (JavaServer Faces), JPA (Java Persistence API), EJB (Enterprise JavaBeans),
and so on.
• GlassFish is one of the most popular application servers. It includes a web server, a
servlet/JSP engine that's based on Tomcat's servlet/JSP engine, and more.
• MySQL is one of the most popular database servers.

Figure 1-10 Web and database servers for Java web applications
24 Section 1 Get started right

Tools for deploying Java web applications


Once you've tested your servlets and JSPs on your own computer or an
intranet, you may want to deploy your web application on the Internet. To do
that, you need to get a web host. One way to do that is to find an Internet service
provider (ISP) that provides web hosting that supports servlets and JSPs. If you
read the text for the ISP on the web page shown in figure 1-11, for example, you
can see that this ISP supports servlets and JSPs.
If you search the web, you'll be able to find many other ISPs and web hosts.
Just make sure that the one you choose not only supports servlet and JSP devel­
opment, but also the database management system that your application requires.
When you select a web host, you get an IP address like 64.71.179.86 that
uniquely identifies your website (IP stands for I nternet Protocol). Then, you can
get a domain name like www.murach.com. To do that, you can use any number
of companies that you can find on the Internet. Until you get your domain name,
you can use the IP address to access your site.
After you get a web host, you need to transfer your files to the web server.
To do that, you can use File Transfer Protocol (FTP). The easiest way to use
FTP is to use an FTP client such as the FileZilla client shown in this figure. An
FTP client like this one lets you upload files from your computer to your web
server and download files from your web server to your computer.
Chapter 1 An introduction to web programming with Java 25

An ISP that provides web hosting that supports servlets and JSPs
E] JSP Web Hosting and Sel'\ )(

C [j www.mmaweb.net --
•••
:· Apps For quick access, place your bookmarks here on the bookmarks bar. Import bookmarks now ... D Other bookmarks

web bostios sales FAQs Account Log11


(716) 689-1593

,-. HOHE HOSTING SERVICES S\JPPORT ORDER A.BOUT US SOFTWARE

Private JVM with Every


Account!
Don't have a domain yet? See if
yours is available by checking
our whois gateway:

Domain (.com. .net, .org)

L I ,--1 $49.99
--.
C-h e- ck j JSP hosting and servlet hosting accounts ·with CCOUNT
per..-.Ch'
advanced, scalable server technologies like Servlets,
Java Server Pages (JSP). Enterprise JavaBeans
(EJB) and XML are what MMA specializes in.
Java Developer Links
The result is a continuous upgrade • Plu, one-month setup fee st
• SeNlets.com
path that lets small businesses ,isJt of first month.
launch websites built on proven
• JsvaWotld
technology that can grow as you
• Official SeNlet Home achieve success without the need
• JsvaSeN!H Pages Home
_.......,_
to rebuild and redeploy your core

The FileZilla program


fi) murach.com - classes - [email protected] m - FileZilla
File Edit Vi� Transfer Server Bookmarks. Help

I � ·ILC1iltiiJI � -. 13 �I��� n
I Host:
Status:
Respoose:
User.name: Password:
Connection established, waiting for welcome message ...
227 Entering Passive !Mode (72,9,137,30, 138,150)
Port: [ Quick.connect ] r:;l
-
Command: MLSD
Response: 150 Accepted data connection
Respoose: 226-0ptions: ..a�
Response: 226 4 matches total D
Status: !Directory listing successful

Local site: 1t\Web Site'vnurach_web4\/:,uild'"'eb\\�/EB-,INF\dassesvnurach\fv\ ..- Remote site: /htclocs/WEB-INF/dasses/mur.ach/fv


,customers j ... ?, customers
,custserv I ... ? custserv
downloads D L. .? downloads D
.... /..... • fv

fv
i
Filename Filesize Filetype Filename Filesize Filetype
- ..
D Financial Calculations.class 747 CLASS File D Financial Calculations.class 747 CLASS Fil
Dlliliiiilli lllliltilli LJ FutureValueServlet.class 2,389 CLASS Fil

m
t-----
" < I Ill
Selected 1 file. Total size: 2,389 Open 2 files.Total size: 3,136 byte.s
Edit
Server/local file Size Priority Status
Create directory
Refresh

Queued files Failed tra Delete


Rename
[!] IHI Queue: empty

Figure 1-11 Tools for deploying Java web applications


Exploring the Variety of Random
Documents with Different Content
The Project Gutenberg eBook of Usury; Or,
Interest, Premium and Discount
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.

Title: Usury; Or, Interest, Premium and Discount

Author: S. H. Crittenden

Release date: June 23, 2020 [eBook #62459]


Most recently updated: October 18, 2024

Language: English

Credits: Produced by deaurider, David E. Brown, and the Online


Distributed Proofreading Team at https://www.pgdp.net
(This
file was produced from images generously made available
by The Internet Archive)

*** START OF THE PROJECT GUTENBERG EBOOK USURY; OR,


INTEREST, PREMIUM AND DISCOUNT ***
USURY:
OR
INTEREST, PREMIUM AND
DISCOUNT.

A LECTURE
DELIVERED
BEFORE THE STUDENTS
OF
CRITTENDEN’S
Philadelphia Commercial College,

BY
S. H. CRITTENDEN,
Attorney at Law,
CONSULTING ACCOUNTANT AND PRINCIPAL.

PHILADELPHIA:
RINGWALT & BROWN, STEAM-POWER BOOK AND
JOB PRINTERS,
Nos. 111 & 113 SOUTH FOURTH STREET.
1863.
USURY:
OR

Interest, Premium and Discount.

A LECTURE[A]

DELIVERED BEFORE THE STUDENTS OF

CRITTENDEN’S PHILADELPHIA COMMERCIAL


COLLEGE,
BY

S. H. CRITTENDEN, Attorney at Law,


PRINCIPAL.

Our subject to-day is Usury.

We will first speak of this subject in its direct relation to Book-


Keeping. That is, as to its treatment under different forms, on the
Ledger, since this is in reality the phase in which it is of most
importance for us to consider it. Afterwards we will glance at the
matter in the view of utility, economy and legality.
The ledger titles which embrace this subject, are Interest, Discount
and Premium. These are all often, and indeed generally, embodied in
one account, headed Interest, yet they are radically different
divisions of the account, both in their nature and manner of
computation; although all tending to one point, when placed upon
the merchant’s books, viz: to add to his total gains or losses.
McCullock’s Commercial Dictionary has the following definitions of
Interest and Discount:
“Interest, is the sum paid by the borrower of a sum of money, or of
any sort of valuable produce, to the lender, for its use.”
“Discount, is an allowance made on account of an immediate
advance of a sum of money, not due till some future period.”
Premium, according to Webster’s Dictionary, is “a bounty, or
something offered or given for the loan of money, usually a sum
beyond the interest.”
These definitions, though not full, will yet serve as a foundation on
which to construct an explanation that may make these terms more
easy of comprehension. You perceive that in order to apply the
definition of Interest, which I have quoted, we must look upon every
person who is indebted to another, as a borrower; that is, as having
in his possession, certain property which belongs of right to that
other person; and for retaining the use of which he must pay him an
equivalent. If you consider in this light all transactions in which
Interest is demanded and paid, this portion of the subject will
perhaps be sufficiently plain without additional comment.
It is in relation to the second division of the account that most
confusion usually arises. There are not less than three distinct
transactions, which are all included in the usual language of business
men, under the single term Discount. They are:
1st. When a deduction is made for payment of a note or account
before due; 2d. When a per centage is taken off from a sale, in
consideration of ready money; 3d. When money is remitted from
one country to another, at an additional expense or at a loss.
If at an expense, it is sometimes called Premium.
For illustration, under the 1st division; suppose A holds a note
against B for $500 due in four months, and B comes to-day and
proffers payment; the custom is, for A to deduct the interest on
$500 for four months, from the face of the note; and to accept the
balance as payment in full: thus considering the use of the
remainder of the amount, sufficient to compensate for the deficiency
in the payment of the face of the bill. But this is manifestly incorrect,
if we take the existing law of this State, which declares the value of
the money to be but six per cent. per annum, to be founded on just
principles. For the interest on the remainder of the note, after
deducting the interest on the face of the note therefrom, is not
sufficient at the same rate per cent. to make up the original sum. So
that B, by paying thus in advance, secures a larger rate of interest
than is lawful. Yet this is the usage, and it is an old adage, and well
established, that usage makes law. This is what is termed Bank
Discount. True Discount, is such a sum, as, when deducted from the
original debt, the interest on the balance will just equal the amount
deducted. The method of ascertaining this is by proportion, or, as it
is called in arithmetics, rule of three. Thus we would say, as the
amount of $100. and interest for the given time and rate is to the
interest on $100. for the same time and rate, so is the total sum to
the amount of discount to be deducted therefrom. Stated thus,—
102.00 : 2.00 :: 500.00 : the answer.
2d. If C sells goods to D and within a certain limited time, usually
among the jobbing trade of our city 30 days after purchase, D pays
for them in cash, usage again allows him a deduction from the face
of the invoice of say 5 per cent. This is also called Discount, but it is
not properly such. For it is only a deduction of such a proportion or
per centage of the bill, on fulfillment of certain conditions; while
Discount is reckoned with reference to time to run, as well as rate
per cent.; in fine, Discount is simple Interest paid beforehand.
3d. The term Discount is also applied to that sum which is advanced
beyond or deducted from the amount of a debt, in remitting money
from one country to another.
Thus, if I wish to remit a sum of money to any foreign country, it is
needful for me to ascertain what is the difference of valuation at the
present time between money of the denominations used and
ordinarily obtainable here, and those in the country to which the
remittance is to be made. This valuation I suppose you all
understand is a merely arbitrary one, fixed at the will of the supreme
power in any State, and varying according to circumstances and the
ideas of the law makers. If, for instance, owing to the different
amounts of alloy used in coining pieces of corresponding value in
different countries, there is say 5 per cent. more precious metal in
the coin of that country to which I wish to remit than in that of our
own country, I must necessarily pay this difference in addition to the
original sum, in order to render the account of my correspondent
good according to the valuation in his country. If on the other hand
the intrinsic value of our coin is 5 per cent. the greater, then one
hundred dollars of our coin will pay one hundred and five dollars of
the other.
The proper term for this is Exchange, and if this name were
universally adopted, there would be far less of confusion in the ideas
associated with such transactions, in the minds of most persons.
We will now turn to a consideration of the peculiar nature of
Interest, or more properly Usury, and the reasons assigned for a
limitation of its rate by law. Formerly, the amount received in
payment for the loan of capital, was denominated Usury; that is to
say, rent for its use and enjoyment.
This is the correct term, for Interest is only the rent, or price paid for
the enjoyment of an object of value.
But this word has acquired an odious meaning, and is now
understood to express an illegal and oppressive rate of interest only,
the milder but less expressive term being substituted by common
usage.
In earlier times, before the advantage and utility of a reserve capital
was known and appreciated, the demand of a rent for its use by
lenders, was looked upon as an abuse of power, and an oppression
towards the needy. And, more still, it seems from the accounts
handed down to us by the writers of those days, that even that
frugality, without which capital cannot be amassed, was looked upon
as parsimony, and deemed a public injury, by the populace, who
looked upon all sums not spent by the great proprietors, as lost to
themselves. They could not comprehend that money laid by, as a
capital for some profitable employment, was to all intents equally
spent; and that to in a way far more beneficial to the poor. For a
laboring man is never sure of earning a subsistence save where
there is a capital in reserve for him to work upon. This inability to
understand its use gave rise to strong prejudice against rich
individuals, who do not spend their whole income as it comes in;
such a feeling still exists to a great extent: formerly it was universal.
Lenders themselves were infected by it, and were so much ashamed
of the part they were acting as to employ the most disreputable
agents in the collection of profits perfectly just, and highly useful to
society.
There have been from time to time various species and modifications
of statutes, and enactments for the promotion of public liberty, and
the advancement of happiness, both private and public.
Yet, though these ordinances have been provided in all good faith,
by the legislators, it is evident to every person who observes closely,
and compares causes and effects, that oftentimes their operation is
inefficient for the end aimed at; and often directly the reverse in
effect from the original intention of their makers. Especially, it seems
to me, is this the case in the matter of those laws relating to Usury.
There exists almost universally, a sort of hereditary prejudice against
the very name of Usury. Almost every one will plead guilty to such
feelings as these: “Usury is a bad thing, and as such ought to be
prevented; Usurers are a bad sort of men, a very bad sort of men,
and as such ought to be punished and suppressed.” Now, it is not
wonderful that men fall into such opinions, and become firmly
grounded in them, when they hear them handed down and repeated
by those to whom they are in the habit of looking with confidence
for correct ideas.
For it cannot be expected that the mass of mankind should find
leisure, even had they the ability, to examine into the grounds of a
hundredth part of the rules and maxims which they find themselves
compelled to follow and observe. The fact is, that wherever it has
been attempted to limit the rate of Interest, or to abolish it
altogether by law, there the practice of Usury has uniformly revived.
And, as might naturally be expected, the more severe the penalties,
and the more rigid their execution, the higher the rate of interest
was sure to rise. Because the risk being so much greater, the lender
must needs have a larger premium of insurance to tempt him to
incur it. It is a matter of history, that at Rome, during the
continuance of the republican form of government the rates of
interest were enormous. The simple and plain reason of this was,
that the debtors who were always plebeians, were continually
threatening their patrician creditors.
So also, in those Christian countries where Interest on loans has
been forbidden, or what is equivalent, where it has been placed by
law at so low a point as would not suffice to pay the risk of loss to a
lender, the practice has been made over almost entirely to the Jews;
while at the same time so great has been the extortion, oppression,
and humiliation to which this people were exposed that nothing
short of a very heavy rate of Interest could indemnify them for such
risks and repeated losses.
Thus in any case the ratio of the Premium of insurance, which
frequently forms the greater portion of what is called Interest, will
depend upon the degree of security presented to the lender. The
greater the risk, the higher will be the rate of Interest. When we
detach from the rate of interest all that is paid as a security to the
lender against the risk of partial or total loss of his capital, it remains
to consider that part which is purely and simply Interest: that is to
say, rent paid for the use of capital.
This is the point upon which many wise legislators have endeavored
to lay down laws as infallible guides, and many learned economists
have advocated such restrictive enactments, as even to this day
obtain in most civilized countries. The Romans seem, according to
Cato, to have considered an Usurer, as worse than a thief. For, says
he, “Our Ancestors, enacted in their laws, that a thief should be
condemned to pay double, but an Usurer, quadruple.”
Even that most learned commentator on law, Sir Henry Blackstone,
pronounces that a legal limit ought to be placed to this branch of
trade.
I will quote from Blackstone, on this subject. He says, when
speaking of the general points in the contract of hiring and
borrowing: [2 Com., p. 454,] “There is one species of this price or
reward, the most usual of any, but concerning which many good and
learned men have in former times very much perplexed themselves,
and other people, by raising doubts about its legality in foro
conscientie.
“That is, when money is lent on a contract, to receive not only the
principal sum again, but also an increase by way of compensation
for the use; which is generally called Interest by those who think it
lawful, and Usury by those who do not so; for those enemies to
Interest, in general, make no distinction between that and Usury,
holding any increase of money to be indefensibly usurious. And this
they ground, as well on the prohibition of it by the law of Moses
among the Jews, as also upon what is said to be laid down by
Aristotle, that money is naturally barren, and to make it breed
money is preposterous and a perversion of the end of its institution,
which was only to serve the purposes of Exchange, and not of
increase. Hence the school divines have branded the practice of
taking Interest as being contrary to the divine law, both natural and
revealed: and the canon law has proscribed the taking any, the least,
increase for the loan of money, as a mortal sin.
“But in answer to this it hath been observed, that the Mosaical
precept was clearly a political, and not a moral precept. It only
prohibited the Jews from taking Usury from their brethren, the Jews:
but in express words, permitted them to take it of a stranger; which
proves that the taking of moderate Usury, or a reward for the use,
for so the word signifies, is not malum in se, (a sin in itself
considered,) since it was allowed where any but an Israelite was
concerned. And as to the reason given by Aristotle, and deduced
from the natural barrenness of money, the same may with equal
force be alleged of houses, which never breed houses; and twenty
other things, which nobody doubts it is lawful to make profit of, by
letting them to hire.
“And though money was originally used only for the purposes of
exchange, yet the laws of any State may be well justified in
permitting it to be turned to the purposes of profit, if the
convenience of society, (the great end for which money was
invented,) shall require it. And that the allowance of moderate
Interest tends greatly to the benefit of the public, especially in a
trading country, will appear from that generally acknowledged
principle, that commerce cannot subsist without mutual and
extensive credit. Unless money, therefore, can be borrowed, trade
cannot be carried on: and if no Premium were allowed for the hire of
money, few persons would care to lend it; or, at least, the ease of
borrowing at a short warning, (which is the life of commerce,) would
be entirely at an end.
“And as to any scruples of conscience, since all other conveniences
of life may be either bought or hired, there seems to be no greater
oppression in taking a recompense or price for the hire of this, than
of any other convenience.”
For the taking of such recompense we have moreover, the very
highest authority in the words of our Saviour, who, in the parable of
the talents, censures the slothful servant in these words: “Thou
wicked and slothful servant, thou knewest that I reap where I sowed
not, and gather where I have not strewed. Thou oughtest therefore
to have put my money at the exchangers, and then at my coming I
should have received mine own with Usury.”
Dr. Adam Smith, in his work entitled “Wealth of Nations,” [Vol. 1, p.
429,] published in 1776, and which has been long a text book for
political economists, says: “A capital lent at Interest may, in this
manner, be considered as an assignment from the lender to the
borrower of a certain considerable portion of the annual produce;
upon condition that the borrower in return shall, during the
continuance of the loan, annually assign to the lender a smaller
portion, called the Interest; and at the end of it a portion equally
considerable with that which had originally been assigned to him,
called the repayment. Though money, either coin, or paper, serves
generally as the deed of assignment, both to the smaller and to the
more considerable portion, it is of itself altogether different from
what is assigned by it.” And again: “As such capitals are commonly
lent out, and paid back in money, they constitute what is called the
monied interest.” “In some countries the Interest of money has been
prohibited by law. But as something can everywhere be made by the
use of money, something ought everywhere to be paid for the use of
it. This regulation instead of preventing, has been found from
experience, to increase the evil of Usury; the debtor being obliged to
pay, not only for the use of the money, but for the risk which his
creditor runs by accepting a compensation for that use. He is
obliged, if one may say so, to insure his creditor from the penalties
of Usury.”
“In countries where Interest is permitted, the law, in order to
prevent the extortion of Usury, generally fixes the highest rate which
can be taken without incurring a penalty. This rate ought always to
be somewhat above the lowest market price, or the price which is
commonly paid for the use of money by those who can give the
most undoubted security.”
“If this legal rate should be fixed below the lowest market rate, the
effects of this fixation must be nearly the same as those of a total
prohibition of Interest.”
“The creditor will not lend his money for less than the use of it is
worth, and the debtor must pay him for the risk which he runs by
accepting the full value of that use. If it is fixed precisely at the
lowest market price, it ruins, with honest people, who respect the
laws of their country, the credit of all those who cannot give the very
best security, and obliges them to have recourse to exorbitant
usurers.”
“The legal rate, it is to be observed, though it ought to be somewhat
above, ought not to be much above the lowest market rate. If the
legal rate of interest in Great Britain, for example, were fixed so high
as eight or ten per cent. the greater part of the money which was to
be lent, would be lent to prodigals and projectors, who alone would
be willing to give this high rate of Interest. Sober people, who will
give for the use of money no more than a part of what they are
likely to make by the use of it, would not venture into the
competition. A great part of the capital of the country, would thus be
kept out of the hands most likely to make a profitable and
advantageous use of it, and thrown into those most likely to waste
and destroy it. Where the legal rate of Interest, on the contrary, is
fixed but a very little above the lowest market rate, sober people are
universally preferred as borrowers to prodigals and projectors. The
person who lends money gets nearly as much Interest from the
former, as he dare take from the latter, and his money is much safer
in the hands of the one set of people, than in those of the other. A
great part of the capital of the country is thus thrown into the hands
in which it is most likely to be employed with advantage. “No law
can reduce the common rate of Interest below the lowest ordinary
market rate at the time when that law is made. Notwithstanding the
edict of 1766, by which the French king attempted to reduce the
rate of Interest from five to four per cent., money continued to be
lent in France at five per cent.: the law being evaded in several
different ways.”
Puffendorf, whose treatise on the “Laws of Nature and of Nations,”
was published in England in 1710, says: “The arguments which are
brought against Usury are easily answered. It is urged that the loan
of a consumable commodity ought to be given gratis, because the
loan of all other things is so. But I answer that I have the power of
granting the use of my goods that are not consumable either gratis,
or for rent: whereof, the one is a loan, the other a letting. So what
should hinder me from granting the use of my money also, either
gratis, or for a certain recompense? When one man borrows to
increase his wealth, or improve his condition, why should another
lend to him for nothing? Nay, ’tis an unreasonable thing, when you
vastly improve your fortune with my money, not to admit me to
some share of the gain. For I, in the meantime, am debarred from
making that advantage which I might have otherwise expected, by
applying it to my own use. Besides, I have parted with something
valuable, which ought therefore to be considered: for in lieu of my
money, I have only an action against your person, which cannot be
prosecuted without some trouble. It may also happen by some
accident that the debt may be lost. Nay, sometimes the debtor must
be courted and caressed, that it be not lost. And some borrow on
purpose to make their creditors dependent on them. As, the
Marechal de Rochelause, when he was taxed by Louis XIII. with
taking part with the Duke of Mayenne, pleaded in excuse, that he
did not follow the Duke, but his money: for his debt would be in a
desperate condition if he did not stick close to his debtor.
“Besides, it is not seldom that we lend to persons who are utterly
unable to pay; and therefore some are of the opinion that it would
be for the advantage of the public, to allow none but merchants to
take up money at use; for this would make the poor industrious, and
force them to frugality, who, some of them, are not afraid to pay
Interest for money to maintain their extravagancies. And monied
men, rather than let their money lie dead, would either take to
merchandise themselves or would put out their money to those who
do: which would make trade flourish to the great benefit of the
commonwealth.
Grotius is of the opinion, “that the legal interest ought to be stated,
not according to the gains of the borrower, but the loss that thereby
accrues to the lender: as in buying and selling, and other contracts,
no regard is had to what the receiver may make of the commodity,
but what goes away from the seller.”
“And in this case so much goes away as every man in his own calling
might, and usually does, make of his money; allowance being made
for hazards, which in some cases are more, and in others less. With
this, I so far agree: that no man can complain, if his debtor makes a
vast and unexpected return of his money; but yet there is no doubt
but I may demand higher Interest of him that makes a very gainful
trade, than I can of another who drives a poor one.”
These are the opinions of men learned in the science of political
economy; and are entitled to weighty consideration; but it seems to
me, they do not, any of them, reach quite far enough into the
subject. All of them appeared to be fettered by the pressure of that
same generally recognized opinion to which I have before adverted.
The proposition I am inclined to favor on this much mooted point is
aptly expressed in the words of Jeremy Bentham. It is, “that no man
of ripe years, and of sound mind, acting freely, and with his eyes
open, ought to be hindered, with a view to his advantage, from
making such a bargain in the way of obtaining money, as he thinks
fit, nor, (what is a necessary consequence,) anybody hindered from
supplying him, upon any terms he thinks proper to accede to.”
There are but two definitions which can be given to Usury. One is,
taking a larger rate of Interest than the law allows; this is the legal
or, political definition. The other is taking more Interest than is usual
for other people to give and take; this is the moral one. And now, in
order that the law may touch the point, and actually prohibit Usury,
it is needful first that the law should supercede morals, or
conventional custom, and fix that point.
One thing is certain, that antecedently to custom, which has grown
to be established conventionally, there could not be such a thing as
Usury. For what rate of interest is more right than another? In one
land ten per cent. is the legal and therefore (as the advocates of
limitation would say) the proper rate; in an another five per cent. is
the utmost which the tender consciences of the legislators will allow.
Even in the same country, from time to time, the rates are and have
been varied as the wants of the community, the exigencies of the
times, or the whims of the legislators prompted.
It is, then, convenience which has produced whatever there is of
custom in the matter. “And what, (asks Bentham appropriately,) is
there in custom, to make it so much more deserving of observance
than convenience, which first gave it birth?”
It is convenient for me to give 8 per cent. for money. “No,” says the
law, “you shall not.” Why? “Because it is not convenient for your
neighbor to give more than 6 per cent. for it.” Can anything be more
absurd?
Then again, as to the opprobrious name. No appellation or particular
stigma of disrepute affixes to a man who being the owner of a
house, gets as high a rent for it as he can. Indeed this is the
common practice with such persons, and nobody is ashamed to do
so, or professes to do otherwise. Now, why a man who possesses
money, and takes as much as he can get for it, say 8, 10 or 12 per
cent. should be loaded with vile epithets, any more than if he had
bought a house with it, and then made the same profit from renting
the house, is more than I can see.
Another point, in which the good policy of the existing restrictive
laws upon this subject, seems doubtful, is that they operate in only
one direction. If it is wrong, and worthy of punishment, to take more
than the fixed maximum of interest for the use of money, why not
make it a penal offence to offer less than that amount, as well as to
accept more?
There are divers reasons given by the advocates of the laws
restricting the rates of Interest why they are beneficial and ought to
be enforced. Among these are: that they prevent prodigality, and
protect the poor and simple from extortion and imposition.
As to preventing prodigality: does not every one know that so long
as a person has money, or property of any sort, with which it is
possible for him to display prodigality, no Usury laws will stop him
from expending it; and, that after his property is gone and he has no
more to expend, none are more ready to promise the largest
Interest, providing he can thereby obtain additional money to
spend? for what he gets is clear gain, he having nothing to lose.
This, it would seem is a hopeless class, for whose protection or
advantage to legislate.
Besides prodigals, there are three other classes, to whose benefit
such restrictive laws are supposed by their authors to insure. They
are the indigent, the rashly enterprising, and the simple. That is to
say, those whose pecuniary necessities are so pressing, as to render
them willing to pay an Interest, above the ordinary rate, rather than
not to have the money; those who from rashness, may be disposed
to venture upon the giving such a rate without duly considering the
consequence; and those whose natural carelessness combined with
ignorance would lead them to acquiesce in it.
Let us look at the conditions of these classes a few moments. Here
is a small trader we will say, whose stock in trade consists of only a
small amount of property, combined with an, as yet, perfectly
untarnished reputation for punctuality in payments. This last, all who
know anything of business, will at once admit to be the principal,
and most important item of his stock. For with such a character, no
merchant will refuse to credit him for articles needful to carry on his
business; and thus all goes well with him.
But now his carefully cherished credit is in danger. He has been
disappointed in his expectations of a ready sale for some part of his
goods, or in obtaining money promised him for a debt, and finds
himself without the means to promptly meet an obligation falling
due to-morrow.
His position is such in the matter of property as not to render it
worth anybody’s while to lend him at the legal rate; in short he
cannot raise money to meet this obligation at that rate, and must do
one of two things—either lose his credit, which will ruin utterly his
prospects of making a comfortable subsistence for his family; or he
must obtain the means of saving this cherished treasure intact, by
paying somewhat more for the use of the money. We can at once
see what he, who has every motive and means for judging rightly in
the matter, would decide to be the wisest course, and the one
nearest the path of rectitude. As a matter of course, if he could
obtain the money at a low rate, he would not pay the higher one.
But now the legislator who knows nothing of any of these
circumstances, but whose heart overflows with prudence, and loving
kindness for the poor man, steps in, and says: “It signifies nothing;
you shall not have the money, for it would be doing you a mischief
to allow you to borrow on such terms.” There might be worse
cruelty, but not easily greater folly.
Next, in regard to the ignorant and simple, for whose protection
from imposition or fraud, these laws are enacted. First, could any
degree of simplicity or want of tact be greater or more evident than
that displayed in such a case as we have just spoken of; where a
legislator could confine a man under such circumstances, to a given
rate of Interest?
Second, suppose the wisdom of the legislator to be never so much
greater than that of the individual, no matter how weak that may be,
how useless is the exertion of it in this case only, while there
remains so many other occasions where the simplicity of the sufferer
would make him the victim of injustice, and where the legislator
cannot interpose to protect him. In every day affairs, in the matter
of buying and selling, whether with money, or on credit, such
persons are liable to be overreached; and yet none have thought
that for this reason, a legal price ought to be set upon all goods, of
whatever description. Nor, supposing that even this endless
undertaking were accomplished by the legislator, would it avail
anything unless he also should regulate the exact amount of each
article which each man should buy.
When matters arrive at this point, we find the person in the position
of those for whom the law provides entirely, as not being fit to take
care of themselves: such are usually denominated idiots.
And now, as we have considered at some length the needlessness
and inefficiency of such legislation, let us for a few moments, look at
some of its evil results.
We will speak at first of those who are by this means virtually
prohibited from obtaining money on loans. Consider for a moment,
what distress and inconvenience it would produce were the privilege
of borrowing denied to everybody. Just that inconvenience is
occasioned to those people whose security would, if they were
allowed to add a little of the rate of Interest, be sufficient to obtain
the needed funds, but is not sufficient for that purpose when such
liberty is denied. Thus the misfortune of not happening to be
possessed of that amount of property which is considered a
sufficient security, is made the ground, under such legislation, of
inflicting hardships upon a man, which those who are so fortunate as
to have such security do not suffer.
The only point of distinction between the two classes, is that the
necessity of one is greater than that of the other. For were this not
the case, they would not be willing, as we have supposed, to pay
more to be rid of it.
Another ill effect, is that of rendering the terms of obtaining money
so much the worse for many whose circumstances are such that
they are not altogether precluded from obtaining it, at some rate.
Those who cannot borrow, may get what they want, so long as they
have anything to sell. But, while out of loving kindness, or other
motive, the law precludes a man from borrowing, upon terms too
disadvantageous, it does not forbid him from selling at any, even the
most ruinous rates.
Everybody knows that forced sales are attended with loss: and to
this loss an amount of Interest, which would at first seem exorbitant,
would bear but a small proportion.
When a man’s goods are taken, and sold under an execution, it is
considered a good sale if the net amount reaches two-thirds what it
would take to replace them again. In this way the kindness of the
law, costs him directly 331⁄3 per cent. at least; supposing, what is
seldom the case, that no more property was taken than just enough
to satisfy the claim. Now, if he had been permitted to hire the
money at, say 12 per cent. per annum it would require nearly three
years for the same amount to accrue, as interest, while the
probabilities are that he would be able to pay off the whole debt
long before the expiration of that period.
To the laws prohibiting Usury, too, we may look, as the prime cause
of the establishment, and the strongest supporter of that branch of
business, which is ordinarily looked upon as so disreputable, and at
whose door are laid so many and grievious complaints of oppression,
&c., viz: pawn-broking:—a business based only on the unsatisfied
wants and necessities of that very class for whose protection from
imposition such laws are made.
So we might multiply cases and arguments, but perhaps sufficient
has already been said to lead those who think, to the conclusion that
is embodied in our proposition: viz: that every man ought to have
the same right to buy and sell money at a profit, as he has to do so
with merchandise or other property.
CRITTENDEN’S PHILADELPHIA
COMMERCIAL COLLEGE.
Established, 1844. Incorporated, 1855.
FOOTNOTE:
[A] Entered according to Act of Congress, in the year 1863, by S.
H. Crittenden, in the Clerk’s Office of the District Court, for the
Eastern District of Pennsylvania.

TRANSCRIBER’S NOTES:
Obvious typographical errors have been corrected.
Archaic or alternate spelling has been retained from the original.
*** END OF THE PROJECT GUTENBERG EBOOK USURY; OR,
INTEREST, PREMIUM AND DISCOUNT ***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund
from the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears,
or with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning
of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebookgate.com

You might also like