100% found this document useful (2 votes)
43 views65 pages

Beginning Java MVC 1 0 Model View Controller Development To Build Web Cloud and Microservices Applications 1st Edition Peter Spath Späth Peter

The document promotes the ebook 'Beginning Java MVC 1.0' by Peter Späth, which focuses on Model View Controller development for web, cloud, and microservices applications. It provides links to download the ebook and mentions other related titles available on the same platform. The book is targeted at both beginner and advanced developers familiar with Java and Jakarta EE, aiming to enhance their skills in enterprise software development.

Uploaded by

allscogulnyr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
43 views65 pages

Beginning Java MVC 1 0 Model View Controller Development To Build Web Cloud and Microservices Applications 1st Edition Peter Spath Späth Peter

The document promotes the ebook 'Beginning Java MVC 1.0' by Peter Späth, which focuses on Model View Controller development for web, cloud, and microservices applications. It provides links to download the ebook and mentions other related titles available on the same platform. The book is targeted at both beginner and advanced developers familiar with Java and Jakarta EE, aiming to enhance their skills in enterprise software development.

Uploaded by

allscogulnyr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Explore the full ebook collection and download it now at textbookfull.

com

Beginning Java MVC 1 0 Model View Controller


Development to Build Web Cloud and Microservices
Applications 1st Edition Peter Spath Späth Peter

https://textbookfull.com/product/beginning-java-
mvc-1-0-model-view-controller-development-to-build-web-
cloud-and-microservices-applications-1st-edition-peter-
spath-spath-peter/

OR CLICK HERE

DOWLOAD EBOOK

Browse and Get More Ebook Downloads Instantly at https://textbookfull.com


Click here to visit textbookfull.com and download textbook now
Your digital treasures (PDF, ePub, MOBI) await
Download instantly and pick your perfect format...

Read anywhere, anytime, on any device!

Beginning Java MVC 1.0: Model View Controller Development


to Build Web, Cloud, and Microservices Applications Peter
Späth
https://textbookfull.com/product/beginning-java-mvc-1-0-model-view-
controller-development-to-build-web-cloud-and-microservices-
applications-peter-spath/
textbookfull.com

Beginning Quarkus Framework: Build Cloud-Native Enterprise


Java Applications and Microservices 1st Edition Tayo
Koleoso
https://textbookfull.com/product/beginning-quarkus-framework-build-
cloud-native-enterprise-java-applications-and-microservices-1st-
edition-tayo-koleoso/
textbookfull.com

Programming C 8 0 Build Cloud Web and Desktop Applications


Ian Griffiths

https://textbookfull.com/product/programming-c-8-0-build-cloud-web-
and-desktop-applications-ian-griffiths/

textbookfull.com

Beginning Jakarta EE - Enterprise Edition for Java From


Novice to Professional. Peter Späth

https://textbookfull.com/product/beginning-jakarta-ee-enterprise-
edition-for-java-from-novice-to-professional-peter-spath/

textbookfull.com
Learn Java for Android Development: Migrating Java SE
Programming Skills to Mobile Development 4th Edition Peter
Späth
https://textbookfull.com/product/learn-java-for-android-development-
migrating-java-se-programming-skills-to-mobile-development-4th-
edition-peter-spath/
textbookfull.com

Learn Java for Web Development Modern Java Web Development


Layka Vishal

https://textbookfull.com/product/learn-java-for-web-development-
modern-java-web-development-layka-vishal/

textbookfull.com

Beginning JSP JSF and Tomcat Java Web Development Expert s


Voice in Java 2 New Edition Zambon Giulio

https://textbookfull.com/product/beginning-jsp-jsf-and-tomcat-java-
web-development-expert-s-voice-in-java-2-new-edition-zambon-giulio/

textbookfull.com

Pro ASP.NET Core MVC 2: Develop cloud-ready web


applications using Microsoft’s latest framework, ASP.NET
Core MVC 2 — Seventh Edition Adam Freeman
https://textbookfull.com/product/pro-asp-net-core-mvc-2-develop-cloud-
ready-web-applications-using-microsofts-latest-framework-asp-net-core-
mvc-2-seventh-edition-adam-freeman/
textbookfull.com

Blazor Revealed: Building Web Applications in .NET 1st


Edition Peter Himschoot

https://textbookfull.com/product/blazor-revealed-building-web-
applications-in-net-1st-edition-peter-himschoot/

textbookfull.com
Peter Spä th

Beginning Java MVC 1.0


Model View Controller Development to Build Web,
Cloud, and Microservices Applications
1st ed.
Peter Spä th
Leipzig, Sachsen, Germany

Any source code or other supplementary material referenced by the


author in this book is available to readers on GitHub via the book’s
product page, located at www.​apress.​com/​9781484262795. For more
detailed information, please visit http://​www.​apress.​com/​source-code.

ISBN 978-1-4842-6279-5 e-ISBN 978-1-4842-6280-1


https://doi.org/10.1007/978-1-4842-6280-1

© Peter Spä th 2021

This work is subject to copyright. All rights are reserved by the


Publisher, whether the whole or part of the material is concerned,
specifically the rights of translation, reprinting, reuse of illustrations,
recitation, broadcasting, reproduction on microfilms or in any other
physical way, and transmission or information storage and retrieval,
electronic adaptation, computer software, or by similar or dissimilar
methodology now known or hereafter developed.

The use of general descriptive names, registered names, trademarks,


service marks, etc. in this publication does not imply, even in the
absence of a specific statement, that such names are exempt from the
relevant protective laws and regulations and therefore free for general
use.

The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.

Distributed to the book trade worldwide by Apress Media, LLC, 1 New


York Plaza, New York, NY 10004, U.S.A. Phone 1-800-SPRINGER, fax
(201) 348-4505, e-mail [email protected], or visit
www.springeronline.com. Apress Media, LLC is a California LLC and the
sole member (owner) is Springer Science + Business Media Finance Inc
(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
To Nicole
Introduction
Starting at the very infancy of software creation, developers tried to
modularize their applications in order to streamline their projects and
increase the maintainability of the software they created. Soon, a very
basic segregation scheme was identified: One part of the software must
deal with data and persistence, another part must deal with presenting
the data to the user, and one last part must handle data input and
frontend view propagation.
This segregation scheme showed up in so many projects that it was
promoted to a common software design pattern, called Model-View-
Controller, or MVC for short. Its power also manifested in its versatility,
even with big paradigm changes, like the onset of the Internet age. With
database products for the model layer, browsers for the view layer, and
some kind of user input processing for the controller layer, the pattern’s
accuracy and applicability to the majority of software projects became
even more apparent with web applications.
Interestingly, even though most web application frameworks under
the hood apply some kind of MVC layer demarcation, Java Server
products up to JEE 7 did not include a dedicated MVC framework. With
JSR-371 (Java Specification Request number 371) only recently and
starting with JEE 8/Jakarta EE 8, an MVC specification entered the Java
Enterprise application realm, which is one of the reasons this book was
born. It does not describe all MVC Frameworks that you can add to Java
EE/Jakarta EE as an external library. There are just too many of them
and you can learn about them by looking at each library’s
documentation. Instead, we talk about the genuine Java MVC library as
described by JSR-371.
The target version of Java MVC is 1.0, and we use a Jakarta EE
version 8.0 compliant server to run Java MVC on it.

The Book’s Targeted Audience


The book is for beginning or advanced enterprise software developers
with knowledge of Java Standard Edition version 8 or later and some
experience in Jakarta EE (or JEE) development. It is also assumed that
the reader is able to use the online API references, as this book is not a
reference in the sense that all API classes and methods are listed.
Instead, it presents techniques and technologies that help professional
Java Enterprise level developers leverage web application programming
by including Java MVC in their software.
The book uses the Linux operating system as the development
platform, although the code can be run on other platforms (Windows
and macOS) without complex adaptions. This book also does not talk
about hardware issues (in case you don’t use a laptop, a PC, or a server).
The readers will in the end be able to develop and run Java MVC
programs of mid- to high-level complexity.

Sources
All sources shown or referred to in this book can be accessed via the
Download Source Code button located at
www.apress.com/9781484262795 .

How to Read This Book


You can read this book sequentially from the beginning to the end, or
you can read chapters on an ad hoc basis if your work demands special
attention on a certain topic.
Table of Contents
Chapter 1:​About MVC:​Model, View, Controller
The History of MVC
MVC in Web Applications
MVC for Java
Finally, Java MVC (JSR-371)
Why MVC
Where Is Hello World?​
Exercises
Summary
Chapter 2:​Prerequisite:​Jakarta EE/​Java EE
The Nature of Java for Enterprise Applications
GlassFish, a Free Java Server
Getting GlassFish
GlassFish Shell Administration
GlassFish GUI Administration
GlassFish REST Interface Administration
Using a Preinstalled Java Server
Learning Java for Enterprise Applications
RESTful Services
Exercises
Summary
Chapter 3:​Development Workflow
Using Gradle as a Build Framework
Using Eclipse as an IDE
Installing Eclipse
Configuring Eclipse
Adding Java Runtimes
Adding Plugins
Eclipse Everyday Usage
More About Gradle
A Basic Gradle Project
Gradle Main Concepts
Standard Gradle Project Layout
The Central Gradle Build File
Running Gradle Tasks
Gradle Tasks Explained
Gradle Plugins
More About Repositories
More About Dependencies
Changing the Project Structure
The Gradle Build File Is a Groovy Script
Script Variables
Custom Tasks
The Gradle Wrapper
Multi-Project Builds
Adding a Deploy Task
Developing Using the Console
Installing MVC
Exercises
Summary
Chapter 4:​Hello World for Java MVC
Starting the Hello World Project
The Hello World Model
The Hello World View
The Hello World Controller
Using Gradle to Build Hello World
Starting a Jakarta EE Server
Deploying and Testing Hello World
Exercises
Summary
Chapter 5:​Start Working with Java MVC
Handling User Input from Forms
Exception Handling in Java MVC
Non-String POST Parameters
Handling Query Parameters
Exercises
Summary
Chapter 6:​In-Depth Java MVC
The Model
CDI in Java MVC
Model Object Scopes
The Simplified Model Data Container
The View:​JSPs
JSP Basics
Directives
Static Content
Java Scriptlets and Java Expressions
Implicit Objects
JavaBeans Components
Expression Languages
Output
Variables
Loops
Conditional Branching
Cookies
The View:​Facelets
Facelets Files
Facelets Configuration
Templating via Facelets
The <ui:​decorate> Tag
An Example Facelets Project
Mixing Facelets and JSTL
Unified Expressions
The Controller
Controller Basics
Getting Pages
Preparing the Model
Posting Data into Controllers
Exercises
Summary
Chapter 7:​In-Depth Java MVC:​Part II
Adding Bean Validation
Injectable Context
Persisting State
Dealing with Page Fragments
Observers
Configuration
Exercises
Summary
Chapter 8:​Internationaliza​tion
Language Resources
Adding Localized Messages to the Session
Formatting Data in the View
Using JSF for Formatting
Localized Data Conversion
Exercises
Summary
Chapter 9:​Java MVC and EJBs
About Session EJBs
Defining EJBs
Accessing EJBs
EJB Projects
EJBs with Dependencies
Asynchronous EJB Invocation
Timer EJBs
Exercises
Summary
Chapter 10:​Connecting Java MVC to a Database
Abstracting Away Database Access with JPA
Setting Up a SQL Database
Creating a Datasource
Preparing the Member Registration Application
Adding EclipseLink as ORM
Controllers
Adding Data Access Objects
Updating the View
Adding Entities
Adding Relations
Exercises
Summary
Chapter 11:​Logging Java MVC Applications
System Streams
JDK Logging in GlassFish
GlassFish Log Files
Adding Logging Output to the Console
Using the Standard Logging API for Your Own Projects
Logging Levels
The Logger Hierarchy and Thresholds
The Logging Configuration
The Logging Format
Using JDK Standard Logging for Other Servers
Adding Log4j Logging to Your Application
Adding Log4j Server-Wide
Changing the Logging Format
Adding Log4j to Jakarta EE Web Applications
Using Log4j in the Coding
Exercises
Summary
Chapter 12:​A Java MVC Example Application
The BooKlubb Database
The BooKlubb Eclipse Project
The BooKlubb Infrastructure Classes
Configuring BooKlubb Database Access
The BooKlubb Internationaliza​tion
The BooKlubb Entity Classes
BooKlubb Database Access via DAOs
The BooKlubb Model
The BooKlubb Controller
The BooKlubb View
Fragment Files
Landing Page
Member-Related View Files
Book-Related View Files
Deploying and Testing BooKlubb
Summary
Appendix:​
Solutions to the Exercises
Chapter 1 Exercises
Chapter 2 Exercises
Chapter 3 Exercises
Chapter 4 Exercises
Chapter 5 Exercises
Chapter 6 Exercises
Chapter 7 Exercises
Chapter 8 Exercises
Chapter 9 Exercises
Chapter 10 Exercises
Chapter 11 Exercises
Index
About the Author
Peter Späth
graduated in 2002 as a physicist and soon afterward became an IT
consultant, mainly for Java-related projects. In 2016, he decided to
concentrate on writing books on various aspects, but with a main focus
on software development. With two books about graphics and sound
processing, three books on Android app development, and a beginner’s
book on Jakarta EE development, the author continues his effort in
writing software development-related literature.
About the Technical Reviewer
Luciano Manelli
was born in Taranto, Italy, where he
currently resides with his family. He
graduated in Electronic Engineering at
the Polytechnic of Bari at 24 years of age
and then served as an officer in the Navy.
In 2012, he earned a PhD in computer
science from the IT department,
University of Bari - Aldo Moro. His PhD
focused on grid computing and formal
methods, and he published the results in
international publications. He is a
professionally certified engineer and an
innovation manager, and in 2014, he began working for the Port
Network Authority of the Ionian Sea – Port of Taranto, after working for
13 years for InfoCamere SCpA as a software developer. He has worked
mainly in the design, analysis, and development of large software
systems; research and development; testing; and production with roles
of increasing responsibility in several areas over the years. Luciano has
developed a great capability to make decisions in technical and
business contexts and is mainly interested in project management and
business process management. In his current position, he deals with
port community systems and digital innovation.
Additionally, he has written several IT books and is a contract
professor at the Polytechnic of Bari and at the University of Bari - Aldo
Moro. You can find out more at his LinkedIn page:
it.linkedin.com/in/lucianomanelli.
© Peter Späth 2021
P. Späth, Beginning Java MVC 1.0
https://doi.org/10.1007/978-1-4842-6280-1_1

1. About MVC: Model, View, Controller


Peter Spä th1
(1) Leipzig, Sachsen, Germany

MVC is a software design pattern. It describes the separation of software into three
elements:
Model : Manages the data of an application. This is to be understood in a narrow sense.
Of course, any part of a less than trivial application deals with the application’s data in
one way or another, but the model from MVC corresponds to data items viewable to the
user and possibly subject to change by user interactions. The model is agnostic to the
way the data is represented to the user or any application workflow, so it can be said
that the model is the central part of a MVC application. It is not surprising that
developing a model is among the first steps of any MVC software project.
View : Describes the presentation of the data and control elements (inputs, buttons,
check boxes, menus, and so on) to the user. A view may provide different modes, like
paged or non-paged tables, a formatted list or a link list, and so on. A view also may use
different technologies, like a GUI component installed on the user’s PC, an app on a
mobile phone, or a web page to be viewed in a browser.
Controller : Handles user input and prepares the data set necessary for the view part to
do its work. While a view shows model items, the view never has to know how data is
stored and retrieved from some persistent storage (database). This is the controller’s
responsibility. Because the user input determines what an application has to do next,
the controller also contains the application logic. Any calculation and data
transformation happens in the control part of MVC.
For example, consider a book club application. In this case, the model consists of
elements such as books (including rental status), book storage location (building, room, or
shelf), and member. For search application modules, you normally define lists of books,
users, and so on, as model values.
The view part of the book club application will contain pages that show books, show
members, show book locations, enable members to rent books, add club members, show
book and member lists, as well as various search functionalities, and so on. Technically,
this will often go hand in hand with a templating engine that defines placeholders for
model elements, shortcuts for loops (for tables and lists), and other view elements like
menus and buttons.
The controller handles the data the user enters. If, for example, the view currently
shows a search page for books and the user enters a book’s name and clicks on the Search
button, the controller is informed as to which button was clicked. The controller then
reads the request parameters (the book’s name in this case) and possibly some model
values (for example, the username and whether the user is logged in), queries the
database, builds a result list, creates a model from this list, and finally decides which view
page to show next.
There exists some fluffiness concerning the implementation details. This comes from
the technical details of the data flow between view elements and model elements. MVC
makes no assumption about when updates to view elements and model elements actually
happen and which procedure is chosen to keep them synchronized. This is why, for MVC,
you find many different diagrams in the literature.
For Java MVC, we can narrow our ideas about MVC to the following—a model (stored in
memory) defines the application’s state; a view shows model values and sends user
interactions to a controller; and the controller prepares model data, handles user input
and accordingly changes model values, and then decides which view page to show next.
This kind of MVC model is depicted in Figure 1-1.

Figure 1-1 The Java MVC design pattern

The History of MVC


The advent of MVC dates back to the 1970s. It was introduced into the computer language
Smalltalk as a programming concept. At that time, it did not have a name. Only later, in the
late 1980s, was the moniker MVC explicitly used. It appeared in an article in the periodical
Journal of Object Technology.
MVC steadily became more and more widespread, and its ideas were so widely adopted
that variants evolved from MVC. We don’t talk about these variants in this book, but a short
list includes:
PAC (Presentation-Abstraction-Control) and HMVC (Hierarchical MVC) . This is a
variation of MVC, where submodules have their own MVC-like structure and only later is
a view page constructed from them.
MVA (Model-View-Adapter) . In this pattern, the view and the model are separated and
only the controller (called an adapter in this case) mediates between the model and the
view. The view has no direct access to model values.
MVP (Model-View-Presenter) . In MVP, the view contains logic to inform the controller
(called a presenter in this case) about view-related data changes. The presenter then
performs some activities and eventually calls back to the view in order to inform the
user about data changes.
MVVM (Model-View-View-Model) . In MVVM, some automatism is introduced, which
translates model values to view elements and vice versa.
The real power of MVC was revealed in the 1990s with the rise of the Internet.
Although some technical details changed—such as the exact technical characteristics of
the data flow and the point in time when data traverses the layer boundaries—the idea
remained the same: a model holds the application state, a view presents the browser
pages, and a controller handles the interaction between the browser and the model, and
decides which view page to show.
Various MVC web frameworks were invented;
https://en.wikipedia.org/wiki/Comparison\_of\_web\_frameworks
shows you a comprehensive list (further down on the page, MVC capabilities are also
listed).

MVC in Web Applications


Web applications impose some restrictions if we try to let them work the MVC way. The
most important distinction comes from the stateless nature of the HTTP protocol, which is
used for communication between the view (browser window) and the controller (HTTP
server). In fact, the way web application frameworks handle the HTTP protocol leads to
decisive differences between the different MVC implementations.
In more detail, important questions concerning MVC for web applications are as
follows:
Sessions: We already pointed out the stateless nature of HTTP. So, if the browser sends
a request, maybe because the user entered some string into a text field and then pressed
the Submit button, how would the server know which user is performing the request?
This usually gets handled by a session, which is identified by a session ID transmitted as
a cookie, request, or POST parameter. Sessions are transparently handled by the
framework, so you don’t have to create and maintain sessions from inside the
application’s code.
Accessing model values from the view: With web applications, some kind of
templating engine usually handles the view generation. There, we could have
expressions like ${user.firstName} to read the contents of a model entry.
Transmitted data extent: If data is submitted from the web page to the server, we
basically have two options. First, the complete form could be transmitted. Second, only
the data that changed could be sent to the server. The latter reduces network traffic, but
requires some script logic (JavaScript) to perform the data collection on the web page.
Updating the view: With web applications, the way a view is updated is crucial. Either
the complete page is loaded after the controller works a request, or only those parts of a
web page that actually need an update are transmitted from the server to the browser.
Again, the latter method reduces network traffic.
From these points, you can see that programming a MVC framework for web
applications is not an utterly trivial task. This is also why there are quite a large number of
different MVC frameworks you can use for web applications. In the rest of the book, I will
show you why choosing Java MVC is not the worst thing you can do if you need MVC
software for your Java platform .

MVC for Java


In the Java ecosystem, a framework named Struts entered the software world around
2000. It is a MVC framework aimed at web applications and integrating with Java
EE/Jakarta EE and Tomcat (a server product boiled down to web functionalities). It has
been used in many software projects and is still being used, albeit it is not part of the Java
EE/Jakarta EE specification. Instead, Java EE/Jakarta EE names JSF (Java Server Faces) as
the dedicated web framework. JSF, in contrast to MVC, uses a component-oriented
approach for creating web applications.
JSF works out-of-the-box for any Java EE/Jakarta EE 8 or later product. Up to version 7,
if you wanted to use MVC, Struts was one of the prominent frameworks you could use.
However, in order for Struts to work, an external library had to be added to the
application, and Struts always felt like an extension and not so much like something that
seamlessly integrated with Java EE/Jakarta EE.
With Java EE 8/Jakarta EE 8, the MVC world reentered the game in form of a Java MVC
specification. It is still kind of a second-class citizen in the Java EE/Jakarta EE world, but
there are reasons to favor MVC over JSF. We talk about the merits and disadvantages of
MVC over other frameworks like JSF at the end of this chapter.

Finally, Java MVC (JSR-371)


The latest Java EE/Jakarta EE MVC implementation operates under the name Java MVC and
is governed by JSR-371. It is the first MVC framework available for Java EE/Jakarta EE
servers version 8 or higher. In fact, the JSR describes an interface. For Java MVC to actually
work, you need to add an implementation library.
Note We use Eclipse Krazo as the Java MVC implementation library. See
https://projects.eclipse.org/proposals/eclipse-krazo
or
https://projects.eclipse.org/projects/ee4j.krazo

We will later see how to install Eclipse Krazo for your web application.
Java MVC is a lean and clever extension of the REST technology JAX-RS included within
Java EE/Jakarta EE. This relationship gives Java MVC a modern touch and allows for a
concise and highly comprehensive programming style.
We already learned that MVC allows for some fluffiness concerning the implementation
details. Figure 1-1 describes how Java MVC works quite well: A request for a first page in
the browser window routes to the controller, which prepares model values (with or
without querying some backend for additional data). The controller then decides which
view page (browser page) to show next (maybe a login page). The view can access model
values. With a data set entered by the user and submitted to the controller, the controller
takes request parameters (for example, the login name and password), possibly queries
the backend (the user database), updates the model, and finally selects a new view page
(for example, a welcome page after successful authentication).
But there is an additional feature that seamlessly integrates with Java MVC. Instead of
always loading a complete new page after each HTTP request, you can decide to let parts
of your web application use AJAX for more fine-grained frontend-backend communication.
Because we use Java MVC in a Java EE/Jakarta EE 8 (or later) environment, we can use JAX-
RS for that aim out-of-the-box.

Why MVC
With so many web frontend technologies out there, it is not easy to decide which to use for
your project. The new Java MVC certainly is an option and it might very well suit your
needs. In order to help you make a decision, here is a list of pros and cons of Java MVC .
Cons:
MVC seems to be a old-fashioned design pattern. Although this is true, it also has been
proven to work well for many projects, and Java MVC allows developers to mix in more
modern web development techniques.
MVC forces the developer to be aware of HTTP internals. MVC is also said to be an
action-based design pattern. Actions in a web environment mean HTTP requests and
responses. MVC doesn’t really hide the internals of the HTTP communication like other
frameworks do.
MVC does not introduce two-way data bindings like other frameworks do. With two-way
data bindings, a change in a frontend input field immediately reflects in the model value
changes. Instead, in a MVC controller, you have to explicitly implement the update of
model values.
Pros:
Since it’s closer to the HTTP communication internals compared to other frameworks,
despite introducing some complexity, this introduces less invasive memory
management. If you look at JSF, a complete component tree (and component data tree)
is built with each browser request. In contrast, a MVC application can be tailored with
an extremely small memory footprint.
Java MVC is part of the Java EE/Jakarta EE 8 specification. This helps to more reliably
handle maintenance.
If you are used to Struts or similar frontend frameworks, switching to Java MVC feels
more natural compared to switching to other products with other frontend design
patterns.

Where Is Hello World?


In many software-related development instruction books, you find a really simple ”Hello
World” example in one of the first chapters. For Jakarta EE, this means we must provide a
shortcut way to do the following:
Write a short program that does something simple, like output the string "Hello
World".
Build a deployable artifact from the string (for example, a .war file).
Run a Jakarta EE server.
Deploy the application (the .war file) on the server.
Connect a client (for example, a browser) to the server.
Observe the output.
This is a lot of stuff, so instead of building a quick-and-dirty setup to run such an
example, I prefer to first talk about Java/Jakarta Enterprise Edition (Java/Jakarta EE) in
general, then discuss the development workflow, and only after that, introduce a simple
first project. This way, we can make sure your first Java MVC application is developed and
runs correctly.
If you think a quick-and-dirty Hello World example will help you, the following
paragraphs show you how to create one. Note that we won’t use the development
processes shown here in the rest of the book—this is simply a simplistic and fast, and
maybe not-so-clean, approach. You can also skip this section safely, because we create a
proper Hello World project in Chapter 4.
1. First make sure OpenJDK 8 is installed on your PC. Go to
https://jdk.java.net/java-se-ri/8-MR3 to download it. In the rest of this
section, we call the OpenJDK 8 folder OPENJDK8_DIR.

2. Download and install GlassFish 5.1 from


https://projects.eclipse.org/projects/ee4j.glassfish/downloads
(choose the ”Full Profile” variant). In the rest of this section, we call the GlassFish
installation folder GLASSFISH_INST_DIR.

3. Inside the GLASSFISH_INST_DIR/glassfish/config/asenv.conf (Linux) or


GLASSFISH_INST_DIR/glassfish/config/asenv.bat (Windows) file, add the
following lines:

REM Windows:
REM Note, if the OPENJDK8_DIR contains spaces, wrap it
REM inside "..."
set AS_JAVA=OPENJDK8_DIR

# Linux:
AS_JAVA="OPENJDK8_DIR"
You must replace OPENJDK8_DIR with the installation folder of the OpenJDK 8
installation.
4. Start the GlassFish server:

REM Windows:
chdir GLASSFISH_INST_DIR
bin\asadmin start-domain

# Linux:
cd GLASSFISH_INST_DIR
bin/asadmin start-domain

You must replace GLASSFISH_INST_DIR with the installation folder of GlassFish.


5. Create a folder called hello_world anywhere on your file system. Its contents have
to be (instructions follow):

build
|- <empty>
src
|- java
| |- book
| |- javamvc
| |- helloworld
| |- App.java
| |- RootRedirector.java
| |- HelloWorldController.java
|- webapp
| |- META-INF
| | |- MANIFEST.MF
| |- WEB-INF
| |- lib
| | |- activation-1.1.jar
| | |- javaee-api-8.0.jar
| | |- javax.mail-1.6.0.jar
| | |- javax.mvc-api-1.0.0.jar
| | |- jstl-1.2.jar
| | |- krazo-core-1.1.0-M1.jar
| | |- krazo-jersey-1.1.0-M1.jar
| |- views
| | |- greeting.jsp
| | |- index.jsp
| |- beans.xml
| |- glassfish-web.xml
make.bat
make.sh

6. Get the JARs for the lib folder from https://mvnrepository.com. Enter each
name without the version and the .jar extension in the search field, select the
version, and then get the JAR file.

7. The Java code reads as follows:

// App.java:
package book.javamvc.helloworld;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/mvc")
public class App extends Application {
}

// RootRedirector.java
package book.javamvc.helloworld;

import javax.servlet.FilterChain;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* Redirecting http://localhost:8080/HelloWorld/
* This way we don't need a <welcome-file-list> in
web.xml
*/
@WebFilter(urlPatterns = "/")
public class RootRedirector extends HttpFilter {
@Override
protected void doFilter(HttpServletRequest req,
HttpServletResponse res,
FilterChain chain) throws IOException {
res.sendRedirect("mvc/hello");
}
}

// HelloWorldController.java
package book.javamvc.helloworld;

import javax.inject.Inject;
import javax.mvc.Controller;
import javax.mvc.Models;
import javax.mvc.binding.MvcBinding;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

@Path("/hello")
@Controller
public class HelloWorldController {
@Inject
private Models models;

@GET
public String showIndex() {
return "index.jsp";
}

@POST
@Path("/greet")
public Response greeting(@MvcBinding
@FormParam("name")
String name) {
models.put("name", name);

return Response.ok("greeting.jsp").build();
}
}

8. As MANIFEST.MF, write the following:

Manifest-Version: 1.0

9. The view files read as follows:

<%-- index.jsp --%>


<%@ page contentType="text/html;charset=UTF-8"
language="java" %>
<%@ taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World</title>
</head>
<body>
<form method="post"
action="${mvc.uriBuilder('HelloWorldController#
greeting').build()}">
Enter your name: <input type="text" name="name"/>
<input type="submit" value="Submit" />
</form>
</body>
</html>

<%-- greeting.jsp --%>


<%@ page contentType="text/html;charset=UTF-8"
language="java" %>
<%@ taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World</title>
</head>
<body>
Hello ${name}
</body>
</html>
(Remove the line break and the spaces after HelloWorldController#.)
10. As beans.xml, create an empty file (the file must exist, though!).

11. The contents of glassfish-web.xml reads as follows:

<?xml version="1.0" encoding="UTF-8"?>


<glassfish-web-app error-url="">
<class-loader delegate="true"/>
</glassfish-web-app>

12. The Linux build file called make.sh reads as follows:

#!/bin/bash
JAVA_HOME=/path/to/your/openjdk-8

rm -rf build/*
cp -a src/webapp/* build
mkdir build/WEB-INF/classes

$JAVA_HOME/bin/javac \
-cp src/webapp/WEB-INF/lib/javaee-api-8.0.jar:
src/webapp/WEB-INF/lib/javax.mvc-api-1.0.0.jar
\
-d build/WEB-INF/classes \
src/java/book/javamvc/helloworld/*

cd build
$JAVA_HOME/bin/jar cf ../HelloWorld.war *
cd ..
(Remove the line break and spaces after the :.)
13. The Windows build file make.bat reads as follows:

set JAVA_HOME=C:\dev\java-se-8u41-ri

mkdir build
CD build && RMDIR /S /Q .
CD ..
rmdir build

xcopy src\webapp build /s /e /i


mkdir build\WEB-INF\classes

%JAVA_HOME%\bin\javac ^
-cp src\webapp\WEB-INF\lib\javaee-api-8.0.jar;
src\webapp\WEB-INF\lib\javax.mvc-api-1.0.0.jar
^
-d build\WEB-INF\classes ^

src\java\book\javamvc\helloworld/*

cd build
%JAVA_HOME%\bin\jar cf ..\HelloWorld.war *
cd ..

(Remove the line break and spaces after the ;.)


To build the application from inside the console, move into the hello_world folder
and start the script:

# Linux
cd hello_world
./make.sh

rem Windows
chdir hello_world
make
Apart from some error messages for the Windows build script that you can safely
ignore, you will end up with the HelloWorld.war web application in the main folder.
From there, you can deploy the application via the following:

# Linux
GLASSFISH_INST_DIR/bin/asadmin deploy --force=true \
HelloWorld.war

rem Windows
GLASSFISH_INST_DIR\bin\asadmin deploy --force=true ^
HelloWorld.war

For GLASSFISH_INST_DIR, you must substitute the GlassFish installation folder.


To see it running, enter the following URL in the address line of your browser:

http://localhost:8080/HelloWorld

See Figures 1-2 and 1-3.

Figure 1-2 Hello World start page


Discovering Diverse Content Through
Random Scribd Documents
APPENDIX.
Copies of Testimonials, etc., Received from Members of Captain
Hayes’ Classes.
“Bombay, 2nd February, 1887.
“To “Captain M. H. HAYES, “Great Western Hotel.
“Dear Sir,—I am happy to inform you that the mare you broke for me to riding in
September, 1885, still goes quietly. She has not given me any trouble at all since that day.
Even when she had not had a saddle on for months, she gave no trouble. As she could not
be made to move an inch under the saddle by whip, or spur, or coaxing, before you tried
your hand on her, and as you spent only twenty minutes’ time on her, I think she is a good
proof of the value of your system.
“Yours truly,
“Geo. A. Kittredge.

“Managing Director, Bombay Tramways Company.”

Copy of Testimonial from Captain Hayes’ Trimulgherry Class.


Trimulgherry, Deccan, 8th November, 1885.
“We, the undersigned, having on several occasions witnessed Captain Hayes’ method of
breaking all sorts of horses, have much pleasure in recording our appreciation of its
merits. This system of breaking the most nervous or vicious animals is, in our opinion,
except with those suffering from some form of disease, invariably efficacious. In addition
to the breaking in, Captain Hayes has shewn us many new and very useful points
connected with the management of horses. The system is very cheap at the money:—

“C. F. Morton, Colonel, 14th Hussars.


A. J. English, Captain, 14th Hussars.
A. H. Waddel, V. S., 14th Hussars.
T. Graham, Riding Master, 14th Hussars.
G. Hamilton, Captain, 14th Hussars.
C. E. Skyring Hemery, Lieut., 14th Hussars.
Stuart Robertson, Lieut., 14th Hussars.
R. Garth, Major, 14th Hussars.
L. J. Richardson, Lieut., 14th Hussars.
F. J. Norman, Lieut., 14th Hussars.
H. W. Mitchell, Lieut., 14th Hussars.
A. C. King, Captain, 14th Hussars.
Geo. H. Gough, BT., Lt.-Col., 14th Hussars.
T. Miller, Lieutenant, 14th Hussars.
Loftus Thackwell, Capt., R. Fs., 14th Hussars.
F. Mugford, Q. M., 14th Hussars.
Geo. H. Arbuthnot, Lieut., 3rd M. L. C.
F. C. Logan-Home, Lieut., 3rd M. L. C.
J. Vans Agnew, Lieut., 3rd M. L. C.
C. J. O. Fitzgerald, Lt.-Col., 3rd Cavalry, H. C.
A. J. Garrett, A. A. G., H. C.
E. Nicolls, Lieut., R. A.”
The “Pioneer,” 18th November, 1885.
CAPTAIN HAYES’ HORSE-BREAKING.
To the Editor of the “Pioneer”.
Sir,—Captain Hayes is shortly going from this to the Bengal Presidency,
and as during his stay he has taught his system of breaking in all sorts of
nervous and vicious horses to a large number of people (and horses) here, I
shall be much obliged if you can find room in the Pioneer for this (and I am
but endorsing the opinion of many) my testimony to the excellence of his
system. It is most easily acquired, and has only to be seen to be appreciated.
His simple method of compelling a refractory horse to enter a railway-box
is, in my opinion, alone worth all the money asked for the whole system.
Deccan.
C. F. Morton, Colonel.
14th Hussars.

Copy of Testimonial from Members of Captain Hayes’ Calcutta Class.


We, the undersigned, having attended a series of lectures conducted by
Captain Hayes on the theory and practice of horse-breaking, hereby certify
that Captain Hayes has completely succeeded in all that he promised to
effect. We have seen him cure confirmed buck-jumpers and jibbers, so that
they were quietly ridden and driven round the school; also savage or
nervous horses have speedily been reduced to quietness and obedience. All
this had been effected without violence or cruelty. His system appears to us
admirable:—

“F. B. Peacock, C. S., }


Charles H. Moore, } Stewards, Calcutta Turf Club.
W. F. McDonnell, V. C.,}
J. J. J. Keswick, }
H. S. Cunningham, High Court, Calcutta.
J. Lambert, Deputy Commissioner of Police.
F. W. Perman.
S. W. Anderson.
H. B. Beames.
Francis J. E. Spring.
A. Milton.
T. Palmer.
W. D. Kilburn.
P. L. Richards.
H. K. Gordon.
Thos. Brae.
R. John Charlton.
F. Hilton.
J. Lauter, V. S.
J. G. Apcar.
F. Aithison.
J. Posford, C. S.
C. Graf.
J. D. Edwards, A. V. D.
S. A. Apcar.
F. J. Rowe.
Wm. Macklin.
A. Willson.
Gopee Nauth Roy.
Thos. R. Pratt.
L. P. D. Broughton, Barrister-at-Law.
Alex. Campbell.
Wm. Duff Bruce.
A. T. Rawlinson.
Latham Hamilton.
J. J. Reid, M. D.
Frank Whitney.
J. Hard.
H. St. A. Goodrich.
S. Keith Douglas.
J. G. Dickson.
Geo. Evans Gordon.
Geo. Cheetham.
A. J. S. Douglas.
Chas. L. Johnstone.
J. D. West.
H. Paget.
Arthur J. C. Forbes.
Kil. Euler.
Robert Philip Heilgers.
J. A. Anderson.
G. Wense.
Charles Brock.
A. R. MacIntosh.
C. Deas.
H. R. McInnes.
J. R. Maples, Manager, Calcutta Tramways Co.
John Croft.
R. A. Turnbull, M.R.C.V.S.
R. Hardie.
J. A. Bourdillon, C. S.
W. H. Egerton.
H. Melvill, Bo. S. C.
W. M. Beresford.
R. E. S. Thomas.
Wm. Charles Fox.
Thomas A. Apcar.
C. B. Jourdain.
J. Leppoc Cappel, C. S.
A. L. McDonell.
T. A. St. Quinton, Major, 10th Hussars.
O. Dignum.
R. C. Onslow, 10th B. Lancers.
A. A. Apcar.
F. C. Barnes.
Cecil Rawlinson, Captain, L. R.
F. de C. H. Helbert, R. W., Fusiliers.
E. V. Westamacott, C. S.”

“Indian Planters’ Gazette,” 9th March, 1886.


“Regarding a most determined jibber cured by Captain Hayes at
Mozufferpore, Mr. Tom Barclay of Bhicanpore writes us as follows:—‘I
have driven him daily, or rather Colonel Fergus Graham, who has been
staying here, has driven him daily for miles, stopping at different places,
and starting again, and we have never had any trouble. He trots nicely, and
in fact goes as kindly as the most perfect trap horse ever foaled. Captain
Hayes may congratulate himself on curing the most vicious, inveterate
jibber in India. I tried to sell him in Calcutta for Rs.500, and no one would
look at him. Now I would not take Rs.1,500, for he is as fine a trapper as
there is in the country.’ ”

Copy of Testimonial from Captain Hayes’ Lucknow Class.


“We, the undersigned, wish to place on record our appreciation of
Captain M. H. Hayes’ methods of breaking horses of all kinds. The methods
are various, and are applicable to all sorts of unbroken or refractory horses;
most simple in application, and thoroughly efficacious. Some of the
subjects submitted to Captain Hayes to test his methods, were as follows:—
“A chestnut waler of E-A., R. H. A., would not allow itself to be mounted, being most
violent if mounting it were attempted, in a short time allowed any one to mount and
dismount.
“An unbroken remount and bad buck-jumper of 17th Lancers, in the course of two hours,
became quiet to ride and perfectly tractable. Ample proof was afforded of the complete
control that could be quickly gained over any horse. A stubborn refuser of the 8th B. C.
very soon took a delight in jumping; and a confirmed jibber of the 17th Lancers was glad
in a short time to move in any direction asked. These few instances we consider
convincing proof of the great power of Captain Hayes’ system:—
“T. A. Cooke, Lt.-Col., 17th Lancers.
B. P. Portal, 17th Lancers.
H. C. Jenkins, Capt., 17th Lancers.
C. D’Aguilar, 17th Lancers.
H. McGee, Capt., 17th Lancers.
S. M. Benson, Major, 17th Lancers.
C. Coventry, 17th Lancers.
A. Porter, Capt., B. S. C.
J. Cook, Bt. Lt.-Col., A. A. G.
Barnard Smith, Lt.-Col.
F. G. Pollock, 8th B. C.
R. K. Ridgeway, Capt., B. S. C.
W. P. Harrison, Major, G. L. I.
G. L. Evans, C. S.
G. R. Gambier, Major, R. H. A.
H. Archdale, Capt., R. W. Fus.
H. Chapman, Col., 8th B. C.
J. L. Aberigh-Mackay, Capt., 8th B. C.
R. D. Loudon, Capt., R. A.
S. D. Brown, Lieut., R. H. A.
G. W. Biddulph, Lieut., R. H. A.
A. H. Hewat, Capt., R. H. A.
P. C. B. Pemberton, Col., R. E.
H. Stevenson, H. L. I.
Charsley Thomas, Lt.-Col.”

Copy of Report by the Director, Army Remount Operations for India.


“Captain Hayes visited the Saharanpore Army Reserve Remount Depôt on the 16th and
17th of April, 1886, and gave some lectures on horse-breaking, as well as proving by
practical demonstration his power of curing horses of nervousness, and rendering them
easy to handle. He first of all operated on a bay waler gelding that had only recently
arrived from Australia in February last, and would not allow himself to be handled or
approached for treatment in hospital.
“In five hours after making him over to him, he was saddled and bridled, and ridden round
the school by a Depôt Riding-boy.
“A brown waler mare, which had been five months in the Depôt and would not allow
herself to be snaffled or handled in any way, was then taken in hand, and in five hours
was able to be saddled, bridled, and ridden about by Captain Hayes’ Assistant ‘Ted.’
“I am of opinion, and so were those who witnessed his mode of breaking a horse of
obstinacy, nervousness, vice, &c., that the treatment he showed us will be a valuable
adjunct to those who have executive work to do in Remount Depôts.
“Ben. Williams, Colonel.
“Director, Army Remount Operations for India.”
Saharanpore, 20th April, 1886.

Copy of Testimonial from Colonel Truman and Officers, 7th Dragoon


Guards.
“Mhow, Central India, 21st January, 1887.
“Having attended one of Captain Hayes’ Classes of Instruction in horse-breaking here, we
have much pleasure in testifying to the excellence of the system adopted by him:—

W. R. Truman, Lt.-Col., 7th Dragoon Guards.


J. H. Banks, Major, 7th Dragoon Guards.
U. G. C. de Burgh, Capt., 7th Dragoon Guards.
D. MacDougal, Capt., 7th Dragoon Guards.
C. W. Thompson, Lieut., 7th Dragoon Guards.
L. A. Brooks, Lieut., 7th Dragoon Guards.
H. S. Follet, Lieut., 7th Dragoon Guards.
B. R. Dietz, Lieut., 7th Dragoon Guards.
W. E. Danby, Lieut., 7th Dragoon Guards.
R. Cooper, Lieut., 7th Dragoon Guards.
W. D. Daunt, Lieut., 7th Dragoon Guards.”

The Calcutta “Englishman,” February 19, 1886.


“To the Editor.
“Sir,—In the interests of humanity and in justice to Captain Hayes, who has so
successfully introduced his system of taming vicious horses in Calcutta, I hope you will
give publicity to the following case of the complete cure of a terribly vicious horse
belonging to this company. The horse in question is a roan Kabulee, which has been in
our possession, and worked well in a car for over two years, but was so savage that no
European could approach him either in or out of his stall. Any attempt to go near him was
always met by vigorous striking with his fore feet and biting, generally followed by a
rush at the person nearest to him, and an endeavour to get his fore legs over the man’s
head. He was always dangerous, on one occasion having savaged off a syce’s hand, and
at another time he took off a man’s finger in one vicious snap. On Tuesday afternoon last
I took him to Captain Hayes, who, in about an hour, completely cured him, and this
without punishment or cruelty of any kind. Two simple, but ingenious contrivances were
used, which, without hurting him in any way, prevented him from doing any mischief to
those approaching him, and after a few minutes, handling by Captain Hayes, he was
pronounced cured, and I was agreeably surprised to find that, on the removal of his gear,
he was not only quiet but safe. I must confess to some scepticism at first, as to the
performance of the cure, but both yesterday and to-day he is perfectly quiet and tame,
and will not only allow Europeans to approach and handle him, but will follow them
about the yard when loose. Captain Hayes has clearly demonstrated that jibbers, kickers,
buck-jumpers, and extremely nervous horses, can all be cured without even being
touched by the whip.
“Jno. R. Maples.
“Managing Agent, Calcutta Tramways Company.”

Copy of Testimonial from class held in the Royal Artillery Riding School,
Woolwich.
“Woolwich, August, 1887.
“We, the undersigned, having been through a course of Practical Instruction in Lectures
given by Captain Hayes on his system of Breaking, Mouthing Horses, and curing them of
bad habits, &c., have great pleasure in certifying that we have gained much valuable
practical knowledge. Captain Hayes gives such excellent reasons for all he does, that he
infuses confidence into those he instructs. With practice any one may use his various
methods with the probability of arriving at as great success as himself in the management
of horses:—

“S. Parr Lynes, Col. Supt. Riding Estab., R.A.


H. H. Crookenden, Major, R.A.
H. B. Jeffreys, Capt. R.H.A.
C. H. Vores, Lieut. R.H.A.
H. McLaughlin, Capt. R.A
H. Rouse, Lieut. R.A.
H. L. Powell, Lieut. R.A.
Charles D. Guinness, Lieut. R.H.A.
J. St. L. Wheble, Capt. R.A.
G. McMicking, Lieut. R.H.A.
Hector Corbyn, Lieut. R.A.”
INDEX.
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, Y.
Aggressiveness, 242
Association of ideas, 12

Ball, Difficult to, 223


Banham, Mr., 86
Banks and ditches, 187
Bars of the mouth, 46, 65
Baucher, 56
Bearing-reins, 55
Begging, 259
Bending the neck to the rein, 49
Biting, 242
Blew, Mr., 74
Blindfolding, 107
Boring, 216
Bowing, 260
Boy, 10
Bridle, difficult to, 112, 223
Bridle, suitability of horse to the, 46
Bridle twitch, 118
Bridling horse for first time, 171
Buck-jumpers, 203, 222
’Bus horse, 12

Capped Knee, 101


Carrying head and neck, 44
Cart horses, 12
Catch, difficult to, 251
Causes of faults, 2
Chance of doing wrong, 23
“Chancing” fences, 230
Chucking up the head, 217
Circling, 172, 260
Coercion, 23
Collar, 42
Comanche bridle, 262, 263
Coming up to call, 261
Control, horse, 77
Cowkicking, 105
Cruiser, 17
Crupper leading-rein, 148
Curbs, 68

Defeats, 20
Defence, 60
Deliberate vice, 3
Difficult to ball, 223
” ” bridle, 112
” ” catch, 251
” ” dismount from, 223
” ” drench, 223
” ” handle, 223
” ” harness, 233
” ” mount, 10, 12, 223
” ” put into train, 225
” ” shoe, 225
Difficult to unharness, 235
Direction of pull of the reins, 50
Dismount from, difficult to, 223
Docile, rendering horses, 147
Dogs, 28
Doing wrong, not getting a chance of, 23
Double hitch Buonaparte bridle, 114
Double sheet-bend, 136
Drench, difficult to, 223
Driving newly-broken horse, 247
Driving pad, 166
Dumb jockeys, 69
“Dwelling” on his stride, 51
Elastic reins, 69
Esa, Mr., 118
Expedition in breaking, 33

Fatigue, 25
Fanchion, 114, 151
Fence, riding at a, 59
Fences, running out at, 231
” , rushing at, 232
Field, the, 256
Fighting the horse, 37
Finish of a race, 51
Fire, unsteady under, 226
First step, 32
Fixing hind quarters, 60
Following, 261
Foreleg, holding up, 96
” , lifting up, 93, 94, 96
” , taking up, 88
” , tying up, 99, 102
Frasier, Mr., 113

Gagging a horse, 143


Gag, wooden, 145
Gateacre, Colonel, 143
“Game,” nervous horses not, 6
Gear, improvised, 272
Gentling hind leg, 135
Gentling neck, 81, 88
Gentling the horse, 151
Going level, 51
Good hands, 65
Good mouth chief requirement, 30
Groom, 28, 29
Ground, keeping horse on the, 157
Haltering, Pratt’s Method of, 86
Halter, rope, 78
Halter twitch, 108
Haltering loose horse, 80
Hamilton, 153
Hands, good, 65
Handle, difficult to, 223
Hanging against the pole, 236
” on the headstall, 251
Handkerchief, picking up a, 268
Hard pulling, 66
Harness, breaking to, 212
” , difficult to, 233
” , faults in, 233
” , lying down in, 240
” , plunging when starting in, 241
Head and neck, carrying the, 44
Head and tail, tying the, 197, 206
Head, chucking up the, 217
” , position of the, 66
Headstall, hanging on the, 251
Headstall twitch, 117, 118
Hickman, Colonel, 74, 249
Hind-leg, gentling, 135
” “ , lifting up, 126, 135
Hind-quarters, fixing, 60
Hippo-lasso, 119
Hobble, improvising a, 143
Holding horse down, 165
Holding up fore-leg, 96
Horse-breaking, object of, 1
” ” , scope of, 14
” ” , value of, 14
Horse-control, 77
How it is done, 32

Idiocy, 21
Improvised gear, 272
Instinct, 7
Intelligence of the horse, 9

Jibbing, 18, 19, 60, 227, 236


Jump, teaching to, 188
Jumping faults, 230
Jumping over another horse, 261
Jumping too slowly, 230

Keeping a horse on the ground, 157


Kemp, Mr., 217
Kicker, touching a, 7
Kicking, 238, 244, 252
Kicking at night, 252
Kicking from nervousness, 4
Kindness, 36
Kissing, 265

Ladies’ horses, breaking, 209


Laughing, 265
Leach, Mr., 96
Leading-rein, crupper, 148
Leg, outward, 56
Leg strap, Rarey’s, 99
” ” , stirrup leather, 105
Lie down, making a horse, 153
Lifting up fore-leg, 93, 94, 96
” “ hind-leg, 126
Linguist, 10
Litter, pawing back the, 256
Log for jumping, 188
Loose horse, haltering, 80
Lunging, 64
Lying down, 265
Lying down in harness, 240
Magner, 151, 218
Making horse lie down, 153
Manners, testing, 271
Martingale, running, 52
” , standing, 70
Mathematician, 10
Memory of the horse, 9
Mental qualities of the horse, 7
Methods of breaking, various, 29
Military exigencies, 34
” riding, 52
Mitchell, Mr., 239
Moore, Mr. J. H., 174, 190, 249
Mount, difficult to, 12, 223
Mounting, Australian method, 204
” horse for first time, 197
Mouth, 30
” , faults of, 216
” , testing, 271
Mouthing gear, 166
” , on foot, 172
” , principles of, 41
Mouth-piece, action of, 47
Muscles of the neck, 44, 45
Mutton fist, 67

Neck, gentling, 81, 88


Neck muscles, 44, 45
Neck, scratching the, 81
Nervousness, 3, 18, 226
Newmarket, 65, 179
Night, kicking at, 252
” , pawing at, 256
“No!”, 266
Noosing fore-leg, 93
Nose-bands, 76
Obeying the rein, 41
Obeying without reins, 265
Obey, making horse, 37
Object of horse-breaking, 1
Ordinary method of breaking, 35
Outward leg, 56

Pad, driving, 166


Pallin, Mr., 224, 256
Pawing at night, 256
Pawing back the litter, 256
Peat, General, 146
Permanency of breaking, 31, 35
Personal influence, 28
Petting horses, 10
Plunging when starting in harness, 241
Pole, gentling with the, 81, 88, 93
” , hanging against the, 236
” , pulling away from the, 241
Polo, savaging at, 245
” , shying off the ball at, 220
Possibility of overcoming any vice, 16
Pratt, Mr., 113, 151, 218
Pratt’s method of haltering, 86
” twitch, 113
Principle of rendering horses docile, 38
Pulling, 66, 218
Pulling away from the pole, 241
” successfully, 42
Punishment, 24

Quick breaking, 33
Quiet to ride, 37

Raabe and Lunel, 119


Racing snaffle, thin, 69
Ranks, refusing to quit the, 229
Rarey, 15, 17
Rareyfying, 24
Rarey’s leg strap, 99
Rawlins, Colonel, 93
Rearing, 60, 219
Reasoning, 8, 17
Refusing, 231
Rein-bearers, 171
Rein, getting tail over the, 235
Reining back, 63
Rein, obeying the, 41
Reins, 171
Reins, pull of the, 50
Rideable and driveable, 22
Riding newly-broken horse, 247
River, 13
Rockwell, Mr., 151, 267
Rope-halter, 78
Rope-twitch, 113
” ” , advantages of, 112
Rough and ready method, 37
Rubbing the tail, 256
Running martingale, 52
Running out at fences, 231
Running reins, 55
Rushing at fences, 232

Saddling horse for first time, 171


Salkeld, Colonel, 266
Sample, Professor, 19, 22, 190, 208, 267
Saunders, Mr., 102
Savage, young, 39
Savaging, 244
Savaging at polo, 245
Saving the mouth, 49, 50, 67, 68
Scope of breaking, 14
Scratching horse’s neck, 81
See-sawing on a plank, 269
Self-preservation, 10
Shaking hands, 269
Shaking the head, 270
Sheet bend, double, 136
Shoe, difficult to, 225
Short tail, tying rope to, 143
Shying, 220
Shying off the ball at polo, 220
Side reins, 55
Sleeping standing, 258
Snaffles, 68
Spoiled horses, 34, 36
Sprinter bar, tying tail to, 240
Stable vices, 251
Standing behind breaker, 78
Standing martingale, 70
Stand still, making horse, 86
Stargazing, 53, 220
“Steady!”, 111
Stirrup leather for leg strap, 105
Strait jacket, 118
” ” , throwing with the, 152
Striking out in front, 246
Stubbornness, 18
Suitability of horse to bridle, 47
Sulking, 158
Sulky horse, 24
Sword, unsteady with a, 220

Tail over the rein, getting the, 235


Tail, rubbing the, 256
Tail, short, 143
” to sprinter bar, tying 240
” with tape, tying, 257
Taking up fore-leg, 88
” “ hind-leg, 126
Tape, tying tail with, 257
Teaching horses tricks, 10, 259
Temper, testing, 271
Tender mouthed, 220
Testing manners, 271
” mouth, 271
” temper, 271
Then and there, 36
Thin racing snaffle, 69
Throwing with strait jacket, 152
Tiring in the gallop, 51
Touched, nervous of being, 226
Touching a kicker, 7
Train, difficult to put into, 225
Turn, difficult to, 221
” , teaching to, 56
Turning, 59
Twitch, bridle, 118
” , headstall, 117, 118
” , ordinary, 112, 113
” , Pratt’s, 113
Twitch, rope, 113
Tying up fore-leg, 99, 102

Unharness, difficult to, 235

Value of breaking, 14
Various methods, 29
Vice, deliberate, 3
Vice in the horse, 3
Vices, 20
” , stable, 251
Voice, 27

Waltzing, 270
Wardrop, Colonel, 74, 182
Whip, undue fear of, 241
” , unsteady with the, 226
White’s Veterinary Art, 54
Without reins, obeying, 267

“Yawing,” 221
“Yes,” 270
Yield, making the horse, 11
Young horses, 43
” savage, 39

LONDON: PRINTED BY WILLIAM CLOWES AND SONS, LIMITED,


STAMFORD STREET AND CHARING CROSS.

Capt. Hayes’
Books on Horses.

Capt. Hayes’
Books on Horses.

New Edition.
VETERINARY HINTS FOR HORSE-OWNERS.
A Handbook of Veterinary Medicine and Surgery, written in popular
language. Fourth Edition, Revised and Enlarged, with Additional
Illustrations. Crown 8vo. 10s. 6d.
[In the press.
“Of the many popular veterinary books which have come under our notice,
this is certainly one of the most scientific and reliable. Some notice is
accorded to nearly all the diseases which are common to horses in this
country, and the writer takes advantage of his Indian experience to touch
upon several maladies of horses in that country, where veterinary surgeons
are few and far between.”—The Field.
“The work is written in a clear and practical way.”—Saturday Review.
“The book leaves nothing to be desired on the score of lucidity and
comprehensiveness.”—Veterinary Journal.
“The present edition is nearly double the size of the first one, and the
additional articles are well and clearly written, and much increase the value
of the work. We do not think that horse-owners in general are likely to find
a more reliable and useful book for guidance in an emergency.”—The Field.

RIDING: on the Flat and Across Country.


A Guide to Practical Horsemanship. Illustrated by Sturgess. Third Edition,
Revised and Enlarged. Imperial 16mo. 10s. 6d. [In the press.
“The book is one that no man who has ever sat in a saddle can fail to read
with interest.”—Illustrated Sporting and Dramatic News.
“A master of his subject.”—Standard.
“An excellent book on riding.”—Truth.
“It has, however, been reserved for Captain Hayes to write what in our
opinion will be generally accepted as the most comprehensive, enlightened,
and ‘all round’ work on riding; bringing to bear, as he does, not only his
own great experience, but the advice and practice of many of the best
recognized horsemen of the period.”—The Sporting Life.
“An eminently practical teacher, whose theories are the outcome of
experience, learned not in the study, but on the road, in the hunting-field,
and on the racecourse.”—Baily’s Magazine.

Cap. Hayes’ Books on Horses.


HORSE TRAINING AND MANAGEMENT IN INDIA.
Fourth Edition, Revised. Crown 8vo. 8s. 6d.
“We entertain a very high opinion of Captain Hayes’ book on Horse Training
and Management in India, and are of opinion that no better guide could be
placed in the hands of either amateur horseman or veterinary surgeon newly
arrived in that important division of our empire.”—The Veterinary Journal.
“A useful guide in regard to horses anywhere ... Concise, practical, and
portable.”—Saturday Review.
“We have always been able to commend Captain Hayes’ books as being
essentially practical, and written in understandable language. As trainer,
owner, and rider of horses on the flat and over country, the author has had a
wide experience, and when to this is added competent veterinary
knowledge, it is clear that Captain Hayes is entitled to attention when he
speaks.”—The Field.

ILLUSTRATED HORSE BREAKING IN THEORY AND


PRACTICE.
With 52 Plates by J. H. Oswald Brown. Uniform with
“Riding.” 21s.

SOUNDNESS AND AGE OF HORSES.


A Veterinary and Legal Guide to the Examination of Horses for Soundness.
By Capt. M. H. Hayes. With upwards of 100 Illustrations. Crown 8vo. 8s.
6d.
“ ‘Soundness and Age of Horses’ is more technical, and shows that Captain
Hayes has not confined his experiences of horses to the mere riding of
them. All who have horses to buy, sell, or keep, will find plenty to interest
them in this manual, which is full of illustrations, and still fuller of hints
and ‘wrinkles.’ ”—The Referee.
“Captain Hayes’ work is evidently the result of much careful research, and
the horseman, as well as the veterinarian, will find in it much that is
interesting and instructive.”—The Field.

Capt. Hayes’ Books on Horses.

INDIAN RACING REMINISCENCES.


Being Anecdotes of Men, Horses, and Sport. Illustrated with Twenty-two
Portraits and a number of smaller Engravings. Imperial 16mo. 8s. 6d.
“All sportsmen who can appreciate a book on racing, written in a chatty style
and full of anecdote, will like Captain Hayes’ latest work. In this book, as in
his others, Captain Hayes shows himself a thorough master of his subject,
and has so skilfully interwoven technicalities, history, and anecdote, that the
last page comes all too soon.”—The Field.
“No racing reminiscences have ever been recorded so graphically, with such
a loving lingering over the days that were, and with such a wide personal
acquaintance with the horses, the men, and the times, as Captain Hayes has
done in his new book.”—The Indian Planter’s Gazette.

A MANUAL OF PRACTICAL TACTICS.


Crown 8vo. 6s.
“Captain Hayes’ book deals exclusively with tactics, and is a well-considered
treatise on that branch of the art of war, giving not merely rules, but also
principles and reasons. We would particularly draw attention to the chapter
on the defensive, which subject is treated with more fulness than is usually
found in English books.... A valuable chapter on machine-guns winds up the
work.”—The Times.

IN PREPARATION.
THE HORSEWOMAN. A Practical Guide for Ladies in the Art of Riding.
Illustrated. By M. H. and A. M. Hayes. Imperial 16mo.
THE POINTS OF THE HORSE. A Familiar Treatise on Equine
Conformation. Describing the Points in which the perfection of each class
of Horses consists. Illustrated by numerous Drawings from Photographs
and exact measurements of Living Typical Animals. Illustrated by J. H.
Oswald Brown. Oblong 4to.

Thacker, Spink and Co.,

CALCUTTA.

Illustrated Catalogue.

LONDON:

W. Thacker and Co.,


87 NEWGATE STREET.
January, 1889.

THACKER, SPINK & CO., CALCUTTA.

In Imperial 16mo. Uniform with Hayes’ “Riding: on the Flat and


Across Country,” “Hindu Mythology,” &c.
Handsomely bound. Rs. 10. (12s. 6d.)

RIDING FOR LADIES.


With Hints on the Stable.
By MRS. POWER O’DONOGHUE.
AUTHOR OF “LADIES ON HORSEBACK,” “A BEGGAR ON HORSEBACK,”
&c.
With 91 Illustrations drawn expressly for the Work by A.
Chantrey Corbould.
HIS able and beautiful volume will form a Standard on the
Subject, and is one which no lady can dispense with. The scope
of the work will be understood by the following:
CONTENTS.
I. Ought Children to Ride?
II. “For Mothers & Children.”
III. First Hints to a Learner.
IV. Selecting a Mount.
V., VI. The Lady’s Dress.
VII. Bitting.
VIII Saddling.
IX. How to Sit, Canter, &c.
X. Reins, Voice, and Whip.
XI. Riding on the Road.
XII. Paces, Vices, and Faults.
XIII. A Lesson in Leaping.
XIV. Managing Refusers.
XV. Falling.
XVI. Hunting Outfit Considered.
XVII. Economy in Riding Dress.
XVIII. Hacks and Hunters.
XIX. In the Hunting Field.
XX. Shoeing. XXI. Feeding.
XXII. Stabling. XXIII. Doctoring.
XXIV. Breeding. XXV. “Tips.”
“When there may arise differences of opinion as to some of the
suggestions contained in this volume, the reader, especially if a woman, may
feel assured she will not go far astray in accepting what is said by one of her
own sex, who has the distinction of three times beating the Empress of
Austria in the hunting field, from whom she ‘took the brush.’ ‘Riding for
Ladies’ is certain to become a classic.”
—New York Sportsman.

W. THACKER & CO., LONDON.


RIDING FOR LADIES.
By MRS. POWER O’DONOGHUE.

NINETY-ONE ILLUSTRATIONS BY A. CHANTREY


CORBOULD.
Handsomely Bound. Rs. 10. Cash Rs. 9. (12s. 6d.)
“Mrs. Power O’Donoghue (more power to her—not that she wants it)
shows no sign of ‘falling off.’ Indeed, she shows her readers how to become
riders, and to stick on gracefully. She sketches her pupils ‘in their habits as
they ride,’ and gives them a bit of her mind about bits, and tells them about
spurs on the spur of a moment.”—Punch.
“Mrs. O’Donoghue is great on the subject of a lady’s riding-dress, and
lays down some useful information which should not be forgotten.... From
first to last she never errs on the side of anything approaching to bad taste,
which is more than can be said for some equestriennes.”—Field.
“It is a characteristic of her book, as of all books of any value, that it has a
distinctive character. Sound common sense, and a thoroughly practical way
of communicating instruction, are its leading traits.”—Daily News.
“We venture to think that any clever girl reading what Mrs. O’Donoghue
has to say on the subject will learn more than a dozen riding lessons can
teach her.
—Illustrated London News.

THACKER, SPINK & CO., CALCUTTA.

New Work by the Author of “The Tribes on my Frontier.”

Behind the Bungalow


By EHA.
With Very Many Clever Sketches
By the Illustrator of “The Tribes.”

CHAPTERS
I. —Engaging a Boy. XI. —The Ayah-Ma.
II. —The Boy at Home. XII. —R. R. The Pundit.
III. —Dogboys. XIII. —Hurree, the Dirzee.
IV. —The Ghorawalla or Syce. XIV. —The Malee.
V. —Bootlair Sahib, Anglice—The XV. —The Bheestie.
Butler.
VI. —Domingo, the Cook. XVI. —Tom, the Barber.
VII. —The Man of Lamps. XVII. —Our Nowkers—The March
Past.
VIII. —The Hamal. Postscript.
IX. —The Body Guard. The Doodwallah.
X. —That Dhobie. The Miscellaneous Wallas.

THACKER, SPINK & CO., CALCUTTA.


Third Edition. In Imperial 16mo, uniform with “Lays of Ind,”
“Riding,” “Hindu Mythology,” &c. Rs. 6. (8s. 6d.)

THE TRIBES ON MY FRONTIER:


An Indian Naturalist’s Foreign Policy.
By EHA.
With Fifty Illustrations by F. C. Macrae.

N this remarkably clever work there are most graphically and


humorously described the surroundings of a Mofussil bungalow.
The twenty chapters embrace a year’s experiences, and provide
endless sources of amusement and suggestion. The numerous
able illustrations add very greatly to the interest of the volume,
which will find a place on every table.
THE CHAPTERS ARE—
—The Butterfly: Contemplating
I. —A Durbar. XI.
Him.
II. —The Rats. XII. —The Frogs.
III. —The Mosquitos. XIII. —The Bugs.
IV. —The Lizards. XIV. —The Birds of the Garden.
V. —The Ants. XV. —The Birds at the Mango Tope.
VI. —The Crows. XVI. —The Birds at the Tank.
VII. —The Bats. XVII. —The Poultry Yard.
—Bees, Wasps, et hoc
VIII. XVIII. —The White Ants.
genus omne.
—The
IX. —The Spiders. XIX.
Hypodermatikosyringophoroi.
—The Butterfly: Hunting
X. XX. —Etcetera.
Him.

W. THACKER & CO., LONDON.

THE TRIBES ON MY FRONTIER.


Third Edition. Rs. 6. (8s. 6d.)
“It is a very clever record of a year’s observations round the bungalow in
‘Dustypore.’ ... It is by no means a mere travesty.... The writer is always
amusing, and never dull.”—Field.
“The book is cleverly illustrated by Mr. F. C. Macrae. We have only to
thank our Anglo-Indian naturalist for the delightful book which he has sent
home to his countrymen in Britain. May he live to give us another such.”—
Chambers’ Journal.

“A most charming series of sprightly and entertaining essays on what may be


termed the fauna of the Indian bungalow.... We have no doubt that this
amusing book will find its way into every Anglo-Indian’s library.”—Allen’s
Indian Mail.
“This is a delightful book, irresistibly funny in description and illustration,
but full of genuine science too.... There is not a dull or uninstructive page in
the whole book.”—Knowledge.
“It is a pleasantly-written book about the insects and other torments of India
which make Anglo-Indian life unpleasant, and which can be read with
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like