100% found this document useful (7 votes)
66 views

Download ebooks file Beginning Java MVC 1.0: Model View Controller Development to Build Web, Cloud, and Microservices Applications Peter Späth all chapters

Peter

Uploaded by

smetszugerq9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (7 votes)
66 views

Download ebooks file Beginning Java MVC 1.0: Model View Controller Development to Build Web, Cloud, and Microservices Applications Peter Späth all chapters

Peter

Uploaded by

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

Download the Full Version of textbook for Fast Typing at textbookfull.

com

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/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

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/
textboxfull.com

Biota Grow 2C gather 2C cook Loucas

https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-loucas/

textboxfull.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/
textboxfull.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/

textboxfull.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/

textboxfull.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/

textboxfull.com

Practical Microservices Architectural Patterns: Event-


Based Java Microservices with Spring Boot and Spring Cloud
Christudas
https://textbookfull.com/product/practical-microservices-
architectural-patterns-event-based-java-microservices-with-spring-
boot-and-spring-cloud-christudas/
textboxfull.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/
textboxfull.com

Beginning Java and Flex Migrating Java Spring Hibernate


and Maven Developers to Adobe Flex Expert s Voice in Web
Development Di Pisa Filippo
https://textbookfull.com/product/beginning-java-and-flex-migrating-
java-spring-hibernate-and-maven-developers-to-adobe-flex-expert-s-
voice-in-web-development-di-pisa-filippo/
textboxfull.com
Beginning
Java MVC 1.0
Model View Controller Development
to Build Web, Cloud, and Microservices
Applications

Peter Späth
Beginning Java MVC 1.0
Model View Controller Development
to Build Web, Cloud, and
Microservices Applications

Peter Späth
Beginning Java MVC 1.0: Model View Controller Development to Build Web, Cloud,
and Microservices Applications
Peter Späth
Leipzig, Sachsen, Germany

ISBN-13 (pbk): 978-1-4842-6279-5 ISBN-13 (electronic): 978-1-4842-6280-1


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

Copyright © 2021 by Peter Späth


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.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Steve Anglin
Development Editor: Matthew Moodie
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image by Janko Ferlic on Unsplash (www.unsplash.com)
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.
For information on translations, please e-mail [email protected]; for reprint,
paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
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.
Printed on acid-free paper
To Nicole
Table of Contents
About the Author��������������������������������������������������������������������������������������������������� xiii

About the Technical Reviewer���������������������������������������������������������������������������������xv


Introduction�����������������������������������������������������������������������������������������������������������xvii

Chapter 1: About MVC: Model, View, Controller�������������������������������������������������������� 1


The History of MVC������������������������������������������������������������������������������������������������������������������������ 3
MVC in Web Applications��������������������������������������������������������������������������������������������������������������� 4
MVC for Java��������������������������������������������������������������������������������������������������������������������������������� 6
Finally, Java MVC (JSR-371)��������������������������������������������������������������������������������������������������������� 6
Why MVC��������������������������������������������������������������������������������������������������������������������������������������� 7
Where Is Hello World?������������������������������������������������������������������������������������������������������������������� 8
Exercises������������������������������������������������������������������������������������������������������������������������������������� 17
Summary������������������������������������������������������������������������������������������������������������������������������������ 18

Chapter 2: Prerequisite: Jakarta EE/Java EE���������������������������������������������������������� 19


The Nature of Java for Enterprise Applications��������������������������������������������������������������������������� 19
GlassFish, a Free Java Server����������������������������������������������������������������������������������������������������� 25
Getting GlassFish������������������������������������������������������������������������������������������������������������������� 26
GlassFish Shell Administration���������������������������������������������������������������������������������������������� 28
GlassFish GUI Administration������������������������������������������������������������������������������������������������� 32
GlassFish REST Interface Administration������������������������������������������������������������������������������ 33
Using a Preinstalled Java Server������������������������������������������������������������������������������������������������ 36
Learning Java for Enterprise Applications���������������������������������������������������������������������������������� 36
RESTful Services������������������������������������������������������������������������������������������������������������������������� 37
Exercises������������������������������������������������������������������������������������������������������������������������������������� 41
Summary������������������������������������������������������������������������������������������������������������������������������������ 41

v
Table of Contents

Chapter 3: Development Workflow������������������������������������������������������������������������� 45


Using Gradle as a Build Framework�������������������������������������������������������������������������������������������� 45
Using Eclipse as an IDE��������������������������������������������������������������������������������������������������������������� 46
Installing Eclipse������������������������������������������������������������������������������������������������������������������� 46
Configuring Eclipse���������������������������������������������������������������������������������������������������������������� 48
Adding Java Runtimes����������������������������������������������������������������������������������������������������������� 49
Adding Plugins����������������������������������������������������������������������������������������������������������������������� 49
Eclipse Everyday Usage��������������������������������������������������������������������������������������������������������� 50
More About Gradle���������������������������������������������������������������������������������������������������������������������� 51
A Basic Gradle Project����������������������������������������������������������������������������������������������������������� 51
Gradle Main Concepts����������������������������������������������������������������������������������������������������������� 53
Standard Gradle Project Layout��������������������������������������������������������������������������������������������� 54
The Central Gradle Build File������������������������������������������������������������������������������������������������� 55
Running Gradle Tasks������������������������������������������������������������������������������������������������������������ 57
Gradle Tasks Explained���������������������������������������������������������������������������������������������������������� 61
Gradle Plugins����������������������������������������������������������������������������������������������������������������������� 63
More About Repositories������������������������������������������������������������������������������������������������������� 64
More About Dependencies����������������������������������������������������������������������������������������������������� 66
Changing the Project Structure��������������������������������������������������������������������������������������������� 69
The Gradle Build File Is a Groovy Script�������������������������������������������������������������������������������� 70
Script Variables��������������������������������������������������������������������������������������������������������������������� 72
Custom Tasks������������������������������������������������������������������������������������������������������������������������ 73
The Gradle Wrapper��������������������������������������������������������������������������������������������������������������� 74
Multi-Project Builds��������������������������������������������������������������������������������������������������������������� 75
Adding a Deploy Task������������������������������������������������������������������������������������������������������������ 79
Developing Using the Console���������������������������������������������������������������������������������������������������� 81
Installing MVC����������������������������������������������������������������������������������������������������������������������������� 84
Exercises������������������������������������������������������������������������������������������������������������������������������������� 85
Summary������������������������������������������������������������������������������������������������������������������������������������ 86

vi
Table of Contents

Chapter 4: Hello World for Java MVC���������������������������������������������������������������������� 95


Starting the Hello World Project�������������������������������������������������������������������������������������������������� 95
The Hello World Model�������������������������������������������������������������������������������������������������������������� 102
The Hello World View���������������������������������������������������������������������������������������������������������������� 104
The Hello World Controller�������������������������������������������������������������������������������������������������������� 107
Using Gradle to Build Hello World��������������������������������������������������������������������������������������������� 108
Starting a Jakarta EE Server����������������������������������������������������������������������������������������������������� 111
Deploying and Testing Hello World�������������������������������������������������������������������������������������������� 111
Exercises����������������������������������������������������������������������������������������������������������������������������������� 114
Summary���������������������������������������������������������������������������������������������������������������������������������� 115

Chapter 5: Start Working with Java MVC������������������������������������������������������������� 117


Handling User Input from Forms����������������������������������������������������������������������������������������������� 117
Exception Handling in Java MVC����������������������������������������������������������������������������������������������� 120
Non-String POST Parameters���������������������������������������������������������������������������������������������������� 124
Handling Query Parameters������������������������������������������������������������������������������������������������������ 126
Exercises����������������������������������������������������������������������������������������������������������������������������������� 130
Summary���������������������������������������������������������������������������������������������������������������������������������� 130

Chapter 6: In-Depth Java MVC������������������������������������������������������������������������������ 133


The Model��������������������������������������������������������������������������������������������������������������������������������� 133
CDI in Java MVC������������������������������������������������������������������������������������������������������������������ 134
Model Object Scopes����������������������������������������������������������������������������������������������������������� 137
The Simplified Model Data Container���������������������������������������������������������������������������������� 139
The View: JSPs�������������������������������������������������������������������������������������������������������������������������� 140
JSP Basics��������������������������������������������������������������������������������������������������������������������������� 141
Directives����������������������������������������������������������������������������������������������������������������������������� 141
Static Content���������������������������������������������������������������������������������������������������������������������� 143
Java Scriptlets and Java Expressions��������������������������������������������������������������������������������� 144
Implicit Objects�������������������������������������������������������������������������������������������������������������������� 145
JavaBeans Components������������������������������������������������������������������������������������������������������ 145
Expression Languages��������������������������������������������������������������������������������������������������������� 146

vii
Table of Contents

Output���������������������������������������������������������������������������������������������������������������������������������� 148
Variables������������������������������������������������������������������������������������������������������������������������������ 149
Loops����������������������������������������������������������������������������������������������������������������������������������� 150
Conditional Branching��������������������������������������������������������������������������������������������������������� 152
Cookies�������������������������������������������������������������������������������������������������������������������������������� 153
The View: Facelets�������������������������������������������������������������������������������������������������������������������� 154
Facelets Files���������������������������������������������������������������������������������������������������������������������� 155
Facelets Configuration��������������������������������������������������������������������������������������������������������� 155
Templating via Facelets������������������������������������������������������������������������������������������������������� 157
The <ui:decorate> Tag�������������������������������������������������������������������������������������������������������� 161
An Example Facelets Project����������������������������������������������������������������������������������������������� 164
Mixing Facelets and JSTL���������������������������������������������������������������������������������������������������� 177
Unified Expressions������������������������������������������������������������������������������������������������������������� 178
The Controller��������������������������������������������������������������������������������������������������������������������������� 179
Controller Basics����������������������������������������������������������������������������������������������������������������� 179
Getting Pages���������������������������������������������������������������������������������������������������������������������� 180
Preparing the Model������������������������������������������������������������������������������������������������������������ 182
Posting Data into Controllers����������������������������������������������������������������������������������������������� 183
Exercises����������������������������������������������������������������������������������������������������������������������������������� 187
Summary���������������������������������������������������������������������������������������������������������������������������������� 187

Chapter 7: In-Depth Java MVC: Part II������������������������������������������������������������������ 193


Adding Bean Validation������������������������������������������������������������������������������������������������������������� 193
Injectable Context��������������������������������������������������������������������������������������������������������������������� 203
Persisting State������������������������������������������������������������������������������������������������������������������������� 205
Dealing with Page Fragments��������������������������������������������������������������������������������������������������� 207
Observers���������������������������������������������������������������������������������������������������������������������������������� 212
Configuration���������������������������������������������������������������������������������������������������������������������������� 215
Exercises����������������������������������������������������������������������������������������������������������������������������������� 218
Summary���������������������������������������������������������������������������������������������������������������������������������� 218

viii
Table of Contents

Chapter 8: Internationalization����������������������������������������������������������������������������� 223


Language Resources����������������������������������������������������������������������������������������������������������������� 223
Adding Localized Messages to the Session������������������������������������������������������������������������������ 225
Formatting Data in the View������������������������������������������������������������������������������������������������������ 229
Using JSF for Formatting���������������������������������������������������������������������������������������������������������� 234
Localized Data Conversion�������������������������������������������������������������������������������������������������������� 236
Exercises����������������������������������������������������������������������������������������������������������������������������������� 238
Summary���������������������������������������������������������������������������������������������������������������������������������� 238

Chapter 9: Java MVC and EJBs����������������������������������������������������������������������������� 241


About Session EJBs������������������������������������������������������������������������������������������������������������������ 241
Defining EJBs���������������������������������������������������������������������������������������������������������������������������� 242
Accessing EJBs������������������������������������������������������������������������������������������������������������������������� 246
EJB Projects������������������������������������������������������������������������������������������������������������������������������ 248
EJBs with Dependencies���������������������������������������������������������������������������������������������������������� 250
Asynchronous EJB Invocation��������������������������������������������������������������������������������������������������� 252
Timer EJBs�������������������������������������������������������������������������������������������������������������������������������� 253
Exercises����������������������������������������������������������������������������������������������������������������������������������� 256
Summary���������������������������������������������������������������������������������������������������������������������������������� 257

Chapter 10: Connecting Java MVC to a Database������������������������������������������������� 261


Abstracting Away Database Access with JPA��������������������������������������������������������������������������� 261
Setting Up a SQL Database������������������������������������������������������������������������������������������������������� 262
Creating a Datasource�������������������������������������������������������������������������������������������������������������� 264
Preparing the Member Registration Application����������������������������������������������������������������������� 266
Adding EclipseLink as ORM������������������������������������������������������������������������������������������������������ 274
Controllers��������������������������������������������������������������������������������������������������������������������������������� 275
Adding Data Access Objects����������������������������������������������������������������������������������������������������� 279
Updating the View��������������������������������������������������������������������������������������������������������������������� 281
Adding Entities�������������������������������������������������������������������������������������������������������������������������� 283

ix
Table of Contents

Adding Relations����������������������������������������������������������������������������������������������������������������������� 285


Exercises����������������������������������������������������������������������������������������������������������������������������������� 289
Summary���������������������������������������������������������������������������������������������������������������������������������� 291

Chapter 11: Logging Java MVC Applications�������������������������������������������������������� 295


System Streams������������������������������������������������������������������������������������������������������������������������ 295
JDK Logging in GlassFish���������������������������������������������������������������������������������������������������������� 296
GlassFish Log Files�������������������������������������������������������������������������������������������������������������� 297
Adding Logging Output to the Console�������������������������������������������������������������������������������� 297
Using the Standard Logging API for Your Own Projects������������������������������������������������������� 298
Logging Levels��������������������������������������������������������������������������������������������������������������������� 299
The Logger Hierarchy and Thresholds��������������������������������������������������������������������������������� 299
The Logging Configuration�������������������������������������������������������������������������������������������������� 301
The Logging Format������������������������������������������������������������������������������������������������������������ 303
Using JDK Standard Logging for Other Servers������������������������������������������������������������������������ 303
Adding Log4j Logging to Your Application��������������������������������������������������������������������������������� 304
Adding Log4j Server-Wide��������������������������������������������������������������������������������������������������� 305
Changing the Logging Format��������������������������������������������������������������������������������������������� 308
Adding Log4j to Jakarta EE Web Applications��������������������������������������������������������������������� 310
Using Log4j in the Coding���������������������������������������������������������������������������������������������������� 312
Exercises����������������������������������������������������������������������������������������������������������������������������������� 313
Summary���������������������������������������������������������������������������������������������������������������������������������� 314

Chapter 12: A Java MVC Example Application����������������������������������������������������� 321


The BooKlubb Database������������������������������������������������������������������������������������������������������������ 321
The BooKlubb Eclipse Project��������������������������������������������������������������������������������������������������� 323
The BooKlubb Infrastructure Classes���������������������������������������������������������������������������������������� 326
Configuring BooKlubb Database Access����������������������������������������������������������������������������������� 328
The BooKlubb Internationalization�������������������������������������������������������������������������������������������� 328
The BooKlubb Entity Classes����������������������������������������������������������������������������������������������������� 333
BooKlubb Database Access via DAOs��������������������������������������������������������������������������������������� 340
The BooKlubb Model����������������������������������������������������������������������������������������������������������������� 347

x
Table of Contents

The BooKlubb Controller����������������������������������������������������������������������������������������������������������� 354


The BooKlubb View������������������������������������������������������������������������������������������������������������������� 364
Fragment Files��������������������������������������������������������������������������������������������������������������������� 365
Landing Page����������������������������������������������������������������������������������������������������������������������� 367
Member-Related View Files������������������������������������������������������������������������������������������������� 368
Book-Related View Files������������������������������������������������������������������������������������������������������ 381
Deploying and Testing BooKlubb����������������������������������������������������������������������������������������������� 390
Summary���������������������������������������������������������������������������������������������������������������������������������� 391

Appendix:�������������������������������������������������������������������������������������������������������������� 393
Solutions to the Exercises��������������������������������������������������������������������������������������������������������� 393
Chapter 1 Exercises������������������������������������������������������������������������������������������������������������� 393
Chapter 2 Exercises������������������������������������������������������������������������������������������������������������� 394
Chapter 3 Exercises������������������������������������������������������������������������������������������������������������� 394
Chapter 4 Exercises������������������������������������������������������������������������������������������������������������� 396
Chapter 5 Exercises������������������������������������������������������������������������������������������������������������� 399
Chapter 6 Exercises������������������������������������������������������������������������������������������������������������� 403
Chapter 7 Exercises������������������������������������������������������������������������������������������������������������� 405
Chapter 8 Exercises������������������������������������������������������������������������������������������������������������� 413
Chapter 9 Exercises������������������������������������������������������������������������������������������������������������� 423
Chapter 10 Exercises����������������������������������������������������������������������������������������������������������� 428
Chapter 11 Exercises����������������������������������������������������������������������������������������������������������� 433

Index��������������������������������������������������������������������������������������������������������������������� 437

xi
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.

xiii
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.

xv
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,

xvii
Introduction

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.

S
 ources
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.

xviii
CHAPTER 1

About MVC: Model,


View, Controller
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.

1
© Peter Späth 2021
P. Späth, Beginning Java MVC 1.0, https://doi.org/10.1007/978-1-4842-6280-1_1
Chapter 1 About MVC: Model, View, Controller

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.

2
Chapter 1 About MVC: Model, View, Controller

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.

3
Chapter 1 About MVC: Model, View, Controller

• 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.

4
Chapter 1 About MVC: Model, View, Controller

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.

5
Chapter 1 About MVC: Model, View, Controller

M
 VC 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.

6
Chapter 1 About MVC: Model, View, Controller

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.

W
 hy 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.

7
Chapter 1 About MVC: Model, View, Controller

• 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.

8
Chapter 1 About MVC: Model, View, Controller

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

9
Chapter 1 About MVC: Model, View, Controller

         # 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

10
Chapter 1 About MVC: Model, View, Controller

           |         |- 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,

11
Chapter 1 About MVC: Model, View, Controller

                   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();
             }
         }

12
Chapter 1 About MVC: Model, View, Controller

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>

13
Chapter 1 About MVC: Model, View, Controller

         <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 :.)

14
Another Random Scribd Document
with Unrelated Content
manner of disease and misfortune upon themselves if they
omitted to observe the ancestral rites.
“In the matter of sacrifice, relationship, even though distant,
is of significance, legitimate or illegitimate relationship being
regarded without distinction. A sacrifice is offered by a family,
with its entire relationship, once in two years. Others, even
the inhabitants of other towns, are invited. Such sacrifices are
commonly held in autumn, rarely in winter. As their
connections are large, each Indian will have opportunity to
attend more than one family sacrifice a year. The head of the
family knows the time and he must provide for everything.
When the head of such a family is converted, he gets into
difficulty because his friends will not give him peace until he
has designated some one to take his place in the
arrangement of sacrificial feasts.
“Preparations for such a sacrificial feast extend through
several days. The requisite number of deer and bears is
calculated and the young people are sent into the woods to
procure them together with the leader whose care it is to see
that everything needful is provided. These hunters do not
return until they have secured the amount of booty counted
upon. On their return they fire a volley when near the town,
march in in solemn procession and deposit the flesh in the
house of sacrifice. Meantime the house has been cleared and
prepared. The women have prepared firewood and brought in
long dry reed grass, which has been strewn the entire length
of the house, on both sides, for the guests to sit upon. Such a
feast may continue for three or four nights, the separate
sessions beginning in the afternoon and lasting until the next
morning. Great kettles full of meat are boiled and bread is
baked. These are served to the guests by four servants
especially appointed for this service. The rule is that whatever
is thus brought as a sacrifice must be eaten altogether and
nothing left. A small quantity of melted fat only is poured into
the fire. The bones are burnt, so that the dogs may not get
any of them. After the meal the men and women dance, every
rule of decency being observed. It is not a dance for pleasure
or exercise, as is the ordinary dance engaged in by the
Indians. One singer only performs during the dance, walking
up and down, rattling a small tortoise shell filled with pebbles.
He sings of the dreams the Indians have had, naming all the
animals, elements and plants they hold to be spirits. None of
the spirits of things that are useful to the Indians may be
omitted. By worshipping all the spirits named they consider
themselves to be worshipping God, who has revealed his will
to them in dreams. When the first singer has finished he is
followed by another. Between dances the guests may stop to
eat again. There are four or five kinds of feasts, the
ceremonies of which differ much from one another.
“At these feasts there are never less than four servants, to
each of whom a fathom of wampum is given that they may
care for all necessary things. During the three or four days
they have enough to do by day and by night. They have
leave, also, to secure the best of provisions, such as sugar,
bilberries, molasses, eggs, butter and to sell these things at a
profit to guests and spectators.”

Adams’ Account.—The best and, in fact, the only late account


previous to his own first article[47] the writer has seen of the Annual
Ceremony among the Lenape in Oklahoma, is that written by
Adams,[48] which reads as follows:

“The peculiar steps which they use in this dance have


caused the name ‘stomp’ or ‘stamp’ to be applied to it.
“In regard to the stomp dances of our people, we have
several kinds of dances; the most important one is the
‘worship dance’ which is carried on in a large building called a
temple, which is rectangular and ranges from 60 to 80 feet
long, from 30 to 40 feet wide, and is about 10 feet high. It is
built of wood with 2 doors. The main entrance is at the
eastern door, and it has only a dirt floor.
“On each post is carved a human face. On the center post
or one in the center of the building four faces are carved;
each face is painted one-half red and one-half black. All the
people enter at the east and go out the same way. When they
come in they pass to the right of the fire, and each of the
three clans of the Delawares take seats next to the wall, the
Turtle clan on the south, the Turkey on the west, and the Wolf
on the north. In no case can any one pass between the center
post and east door, but must go around the center post, even
to go to the north side of the temple.
“This dance is held once each year, in the fall, and
generally in October, in the full moon, and lasts not less than
12 days for each part. The tribe is divided into three clans,
and each clan has to go through the same part, so the dance
is sometimes 36 days long, but sometimes the second and
third clans do not dance more than 6 days each.
“The Turtle clan usually lead or begin the dance. A tortoise
shell, dried and beautifully polished and containing several
small pebbles, is placed in the southeast corner near the door
in front of the first person. If he has anything to say he takes
the shell and rattles it, and an answer comes from the south
side of the temple from the singers, who strike on a dried
deer’s hide: then the party who has the tortoise shell makes
an address or talk to the people, and thanks the Great Spirit
for blessings, and then proceeds to dance, going to the right
and around the fire, followed by all who wish to take part, and
finally coming to the center post he stops there; then all the
dancers shake hands and return to their seats. Then the shell
is passed to the next person, who dances or passes it on, as
he chooses.
“On the third day of the dance all men, both married and
single, are required to keep out of the company of women for
3 days at least. They have a doorkeeper, a leader, and 2 or 3
parties who sweep the ground floor with turkey wings, and
who also serve as deacons. The ashes from the fire are
always taken out at the west door, and the dirt is always
swept in the fire. In front of the east door outside is a high
pole on which venison hangs. It is a feast dance and the
deacons distribute food among the people. The officers and
waiters are paid in wampum for their services.
“In no case is a dog allowed to enter the temple, and no
one is allowed to laugh inside it, or in any way be rude. Each
person is allowed to speak and tell his dream or dreams or to
give advice. It is believed by the Delawares that every one
has a guardian spirit which comes in the form of some bird,
animal, or other thing, at times in dreams, and tells them what
to do and what will happen. The guardian spirit is sent from
the Great Spirit.
“Traditions say that 10 years before white men came to this
country (America) a young man told his dream in the temple.
This was on the Atlantic coast. He saw coming across the
great waters a large canoe with pinions (wings) and
containing strange people, and that in 10 years they would in
fact come. He told this dream and predicted the arrival of the
white men each year until they came and were seen by his
people. Many of our people still keep up this dance, but the
temple is not so large as it used to be, and the attendance
now is not more than 100 persons. Any Indian of any tribe can
also take part in the dance, but no white man can.
“When the dance is over all the people go out and stand in
a single line from east to west with their faces to the south.
Then they kneel down and pray, and then go home. We do
not know the origin of the worship dance, but the old Indians
claim that the Great Spirit came many years ago and
instructed it and also gave them the wampum.”

In spite of several inaccuracies, such as the statement that the


people face south (instead of east) while praying after the ceremony,
this account is valuable on account of the additional data it furnishes
on several points of interest, especially the tradition concerning the
prophecy of the coming of the whites.
Another Form of the Annual Ceremony
It appears that in former years there was, in addition to the rite just
described, another form of the Annual Ceremony practised by the
Lenape, before their removal to what is now Oklahoma from Kansas,
where the last man to “bring in” such a meeting was John Sarcoxie,
now dead.
The ceremony, which was called Muxhatolʹzing, seems, from the
accounts given the writer by his informants, to have taken place in a
similar building, and to have been similar in ritual to that just
described, except that it was held for only eight days instead of
twelve, and that, after the return of the hunters the skin of one of the
deer they had brought in was stuffed with grass and stood up by the
central post of the Big House, antlers and all, while about its neck
hung a string of wampum—perhaps as a propitiatory offering.
Moreover on the morning of the last day of the ceremony a large
sweathouse was built and stones heated; then about noon the men
who had been reciting their visions went into it, each taking one of
the hot stones with him. This privilege was not confined to the actual
celebrants however, for every one blessed by a guardian spirit even
if they had not sung their visions in the meeting, was entitled to carry
in a stone and join them.
The entrance was then closed and water poured upon the stones;
and while the steam rose and the sweathouse grew hotter and hotter
the perspiring occupants prayed to their guardian spirits and recited
their visions. These finished, with a shout of “There go our prayers to
Those Above,” the cover was suddenly snatched from the
sweathouse so that the steam it had contained rose in a puff. If the
steam cloud went straight up into the air it was thought that the
prayers would be heard and answered, and that all was well, but if it
broke and spread out the people felt that something had gone
wrong, and that their prayers were of no avail.
In endeavoring to explain the presence of such variations of the
Annual Ceremony, it should be remembered that the Lenape now in
Oklahoma whom the writer has called for convenience “Unami,” are
not really pure descendants of this tribe, but probably have a large
proportion of the blood of the Unala'ʹtko or Unalachtigo, whose
dialect, according to Heckewelder, was very similar, and a smaller
proportion of Minsi and even Nanticoke blood. Perhaps then the first
form of Annual Ceremony described may have originally been purely
Unami, and the second Unalachtigo, or Minsi, or vice versa; but later,
when the remnants of these tribes became amalgamated their mixed
descendants inherited both forms.
The second form seems to be a variant of the rite mentioned by
Zeisberger[49] who describes it as follows:

“A fifth kind of festival is held in honor of fire which the


Indians regard as being their grandfather, and call Machtuzin,
meaning ‘to perspire.’ A sweating-oven is built in the midst of
the house of sacrifice, consisting of twelve poles each of a
different species of wood. These twelve poles represent
twelve Manittos, some of these being creatures, others plants.
These they run into the ground, tie together at the top,
bending them toward each other; these are covered entirely
with blankets, joined closely together, each person being very
ready to lend his blanket, so that the whole appears like a
baker’s oven, high enough nearly to admit a man standing
upright. After the meal of sacrifice, fire is made at the
entrance of the oven and twelve large stones, about the size
of human heads, are heated and placed in the oven. Then
twelve Indians creep into it and remain there as long as they
can bear the heat. While they are inside twelve pipes full of
tobacco are thrown, one after another, upon the hot stones,
which occasions a smoke almost powerful enough to
suffocate those confined inside. Some one may also walk
around the stones singing and offering tobacco, for tobacco is
offered to fire. Usually, when the twelve men emerge from the
oven, they fall down in a swoon. During this feast a whole
buckskin with the head and antlers is raised upon a pole,
head and antlers resting on the pole, before which the Indians
sing and pray. They deny that they pay any adoration to the
buck, declaring that God alone is worshipped through this
medium and is so worshipped at his will.”

That this is really the same ceremony is shown not only by the
details as related but by the native name of the rite, the Machtuzin of
Zeisberger corresponding with the Muxhatolʹzing of the present
writer.
CHAPTER VI
Minsi Big House Ceremonies
The following account of the great ceremonies of the Minsi, which
correspond to the annual ceremony of the Unami, was obtained from
Chief James Wolf, now deceased, and his nephew, Chief Nellis
Timothy.

MYTH OF ORIGIN
At first, it appears, the Indians did not know how to worship, so
Kĕ'tanĭtoʹwĕt, the Great Manĭʹto or God, now called Pa'ʹtŭmawas,
came down and told them what to do. After following his instructions,
they watched him when he ascended. He carried twelve sumach
sticks in his hand, and they could see them shine far up in the air.
Every now and then he dropped one, and when he dropped the
twelfth he disappeared, while they heard the heavens crack like
thunder behind him as he went in. After this the Lenape began to
hold these meetings according to the instructions he had given them.

NUMBER OF CEREMONIES
There were two of these ceremonies every year, both held in the
Minsi Big House (W'aʹtekan), which was quite similar to that of the
Unami. One of these, performed about June when the wild
strawberries were ripe, lasted only a single night; the other, early in
winter, covered twelve days and nights. This latter corresponds to
the Annual Ceremony of the Unami.
At the June ceremony fresh strawberries were made into a drink
for the people, which reminds one of the Iroquois Strawberry Dance,
or Dance of First Fruits, as it is sometimes called. Strawberries were
dried at this time to make a drink for the Winter Ceremony.

ARRANGEMENT OF THE BIG HOUSE

Fig. 14.—Drum of dried deerskin, Minsi type. E. T. Tefft collection,


American Museum of Natural History. (Length 16.7 in.)
Fig. 15.—a,
Drumstick, Minsi
type; b, Prayerstick.
E. T. Tefft collection,
American Museum
of Natural History.
(Length of a, 19 in.)
Like the Unami Big House, that of the Minsi had a large central
post bearing carved faces; but, unlike that of the Unami, there was a
second short post, near the central one, upon which was hung, for
each ceremony, a raw fresh deerskin with the head and horns at the
top. This feature, however, corresponds with the second form of the
Annual Ceremony noted among the Lenape in Oklahoma and also
recorded by Zeisberger in Pennsylvania. Near this central post the
singers sat, and beat with four carved sticks upon a dry deerhide
folded into a square, in lieu of a drum (fig. 14), differing from the
Unami form, which is a rolled dry deerskin upon which are tied
several slats of wood (fig. 8). The drumsticks are flat, resembling
those of the Unami, as each bears a face carved upon one side, but
differ from them in the form of the forked end, and in width. Some, it
is said, represented women, the breasts being indicated as among
the Unami, but this feature does not appear in the set collected by
the writer at Grand River reserve (fig. 15, a), which the Indians said
were representative of the Minsi type.
There were two poles laid along on each side from end to end of
the Big House to divide the dancing place in the center from the
sitting places on the side, which were covered with a special kind of
leaves. Along these poles twelve little sumach sticks (fig. 15, b),
peeled and painted, were laid for twelve people to hold in their
hands, and tap on the poles in time to the music. There were also
provided a turtle rattle, which was placed at the foot of the central
pole; a fire-drill which Nellis Timothy thinks was worked on the
“pump-drill” principle, like that of the Unami, and a lot of entirely new
and unused bowls and spoons of bark. Unlike the Unami custom,
both doors of the Big House were used, the people always going in
at the east door and coming out at the west, and here also (like the
Unami) the ashes were carried out. “The Sun and everything else
goes toward the west,” say the Minsi, in explanation, “even the dead
when they die.”

PRELIMINARIES
The first act remembered by the informants preparatory to holding
a meeting was to send to each man in the tribe who had been
blessed by a “vision of power,” a little stick which represented an
invitation to the ceremony, the time of which the messenger gave
out, before which date the people leaving their scattered homes
gathered and camped about the Big House. Meanwhile hunters were
sent out, appointed before, not during the meeting as among the
Unami, to bring in for the Winter Ceremony, if possible, exactly
twelve deer, which were cooked by four young men who served as
attendants in a small separate house, built for the purpose.
Fire.—The fire was made with a fire-drill by a group of old men for
use in the Big House, but, as among the Unami, none of it could be
taken outside during the ceremony.
Purification.—When the two fires had been built, but before the
crowd had gathered, the house was purified by the smoke of
hemlock boughs thrown on the flames, and by sweeping the floor
with turkey-wing fans, which cleared away both dirt and evil
influences.

OPENING OF THE CEREMONY


Chief’s Speech.—The next step was for the attendants to call in all
the people from their camps except the women in their menses who
were not allowed to enter. When all were seated, the speaker rose
and addressed those assembled in terms like the following:
“We are now gathered here, our house is purified and clean, and
Pa'ʹtŭmawas is with us, ready to hear our worship. We must thank
Him for all the things that we enjoy, for He made them every one.”
Then he proceeded to tell the people not to drink liquor, nor to do
anything wrong in the Big House or in the camp about it, and advised
them to be always honest and kind and hospitable. He held virtue as
something to be followed, at the same time condemning evil, every
vice that he could think of being mentioned.
The chief then gave thanks for everything he could remember,
from the heavenly bodies to the animals, trees, and herbs of the
earth, not forgetting corn, beans, and squashes; and prayer for
successful hunting and good health for all the people. At the summer
meeting he prayed for good crops also. When he had finished,
bear’s fat was thrown on the two fires, and the smoke rose and filled
the place with its odor.

CEREMONIAL DRINK
At this point it was customary to pass around a vessel of drink
made of crushed wild strawberries, from which each person present
swallowed about a spoonful, a drink made at the Summer Ceremony
of fresh fruit, but in winter necessarily of berries dried for the
purpose.

RECITAL OF VISIONS
The first man to relate his vision (my informant did not remember
whether he was the one who “brought in” the meeting or not) took up
the turtle rattle from its place at the foot of the post and began to
shake it rapidly, while the singers struck the drum of dry hide. He
then recited the story of his vision of power, still keeping the rattle
shaking, following this with his dance song, at the same time dancing
and rattling the turtleshell.
Any one who wished to dance was supposed to give wampum to
the vision-teller for the privilege. Some who were well off would give
him an entire string, others merely a few beads. These the vision-
teller would take, when he had quite a handful, to two officers who
sat in a corner of the building, whose duty it was to count the
wampum, after which it was kept by the chief or leader. Sometimes if
a poor person who had no wampum wished to dance, they would
give him some to pay the vision-teller.
A translated example of a Minsi vision chant and dance song has
already been given. When the dream-teller finished the first verse of
his dance song, he exclaimed, “E-ye-he-ye-ĕ!” whereupon the
singers took up the strain and sang the verse several times, for the
benefit of those who wished to dance, omitting, however, the final
exclamation, but those who had bought the privilege rose and
danced where they stood, instead of circling around, as among the
Unami. Each “set” ended with a whoop, “kwi!”.
When the vision-teller finished dancing, he went around the house
and shook hands with everyone; then the turtle rattle was passed to
another man who had been blessed with a vision, and so on, until all
those qualified, who wished to recite their visions, had done so.

OTHER FEATURES
The Prayer Cry.—From time to time during the night the prayer cry
“Ho-o-o!” was repeated twelve times, and the twelfth cry, they say,
was heard by the Great Manĭʹto.
Feast.—The people were accustomed to eat a light supper before
going into the meeting; then about midnight the four attendants
carried around baskets with boiled meat and corn bread, and in the
morning, before leaving the Big House, a regular feast of venison
was served in new bark bowls and eaten with new bark spoons
especially made for the purpose.
Final Address.—Before the meeting closed, the speaker again
addressed the people, telling them to do right, and prayed that the
hunters about to leave for the winter hunt might be successful, and
that all might live to meet again.

CONCLUSION OF RITES
In the morning after the ceremonies in the Big House were
finished, the people filed out through the west door, circled about the
building, and lined up, facing eastward, to the east of it. Then they
raised their hands and cried “Ho-o-o!” twelve times, and the twelfth
time, it is said, their cry reached Heaven.
In comparing this form of the Annual Ceremony with that of the
Oklahoma Lenape the most noticeable difference is that here no
masked impersonator of Mĭsinghâliʹkŭn was seen in or about the Big
House, the Masks among the Minsi, as with the Iroquois, constituting
a society with its own separate rites.

GRAND RIVER VERSION


Such was the version of the great ceremonies given the writer by
the Minsi of Munceytown, Ontario, which is similar to, but more
detailed in parts than, the account previously obtained from the
Delawares of Grand River reserve, published by the writer in the
American Anthropologist[50] which we will reproduce here. It will be
noticed that this description gives fuller information in some places
where the first is deficient; so that between this and the preceding
account, a good general idea of the Minsi form of the ceremony can
be reconstructed. It reads:
“In the old religious ceremonies of the Delawares at Grand River a
very peculiar drum was used, a dry skin folded in rectangular form
and beaten with four sticks, each bearing a tiny human head carved
in relief (fig. 15, a). I secured the set of four original sticks from
Michael Anthony (Na'nkŭmaʹoxa), and employed him to make me a
reproduction of the drum (fig. 14) as the original had been destroyed.
This he did, and in addition made six painted sticks (fig. 15, b) also
used in the ceremony. The description of how these articles were
used, pieced together from several Indian accounts, may prove of
interest here.
“It appears that the Delawares of Six Nations Reserve formerly
held what was known as a ‘General Thanksgiving’ ceremony called
in Lenape Gitctlaʹkan, twice a year, once in the spring and again in
the fall. At these times it was customary to meet in the Cayuga long-
house, borrowed for the occasion. At a certain point in the
proceedings (I shall not attempt a consecutive description from
hearsay testimony) a man stood up and recited, in a rythmical sing-
song tone, his dream—the vision of power seen by him in his youth.
Na'nkŭmaʹoxa remembered how one old man was accustomed to tell
about a duck, half black and half white, which had appeared to him.
Between the verses of the dream four musicians kneeling at the
drum (pw'awaheʹgŭn) began a plaintive song, beating time with the
carved sticks (pw'awaheʹgŭnŭk). As they sang, the reciter swayed
his body to and fro, while a group of dancers gathered on the floor
behind him danced with a sidewise step. Before the ceremony, poles
were laid lengthwise along both sides of the council house, and
against these, at intervals, three on a side, the painted sticks, called
mkäähiʹgŭn, were laid. If anyone in the crowd felt ‘especially happy’
he was privileged to strike with one of these sticks upon one of the
poles in time to the music. The carved heads on the drumsticks
meant that human beings were giving thanks; the lengthwise
painting of the sticks, half black and half red, implied that men and
women were together in thanksgiving, the black representing the
warriors, the red the women. The fork at the striking end of the sticks
was to give a sharper sound. The dyes for producing the colors were
made by boiling bark, the black being soft maple (sexiʹkiminsi), and
the red, red alder bark (witoʹ'pi).
“In another part of the same ceremony wampum was used in the
form of strings and bunches, both of which were represented in my
collection from the Delawares. At least thirteen of the strings were
used, each one made different by different combinations of the white
and purple beads. These thirteen, it is said, represented respectively
(1) Earth; (2) Plants; (3) Streams and Waters; (4) Corn, Beans, and
Vegetables; (5) Wild Birds and Beasts; (6) Winds; (7) Sun; (8) Moon;
(9) Sky; (10) Stars; (11) Thunder and Rain; (12) Spirits; and (13)
Great Spirit. At the ceremony these strings were laid upon a bench
before a speaker, who picked them up one by one as he made his
address, each string reminding him of one part of his speech. He
began, my informant told me, by explaining that the Great Spirit had
made all things—the earth, plants, streams, and waters—everything.
Having thus enumerated all the things represented by the wampum,
he proceeded to speak to each of the remaining twelve directly,
holding the appropriate string in his hand. Thus he gave thanks to
the Earth for the benefits it gives to man, and prayed that its
blessings might continue; then thanked in the same way the Plants,
the Streams and Waters, the Winds; the Corn, Beans, and
Vegetables—each one in turn. As he finished each string he handed
it to an attendant, who laid it aside. When his long speech or prayer
was finished, he announced, ‘We will now enjoy ourselves,’ and
selected a man to distribute little bunches of wampum, three beads
in each, which served as invitations to join in the dancing that
followed. These bunches were delivered only to a certain number of
those known to be ‘sober and honest’ among the crowd in the long-
house. If any person wishing to dance failed to get invitation
wampum, it was his privilege to ask for one of the bunches, which
was given him if he was considered qualified. The first man receiving
wampum arose first; then the others, until the dancers were all on
the floor. It is said that this dance, which sometimes lasted all night,
did not circle around like most of the Iroquois dances, but each
performer remained in about the same spot.
“I was told that in this dance a small rattle without a handle and
made of turtleshell was used, probably like the box-turtle rattle still
used in the annual Planting Dance by the Seneca and Cayuga.”

WAUBUNO’S VERSION
The only extended account in print, known to the writer, of the
great ceremonies of the Minsi, beside his own, quoted above, is that
furnished by John Wampum, known as Chief Waubuno,[51] which
reads as follows:

“They kept annual feasts:—... a feast of first fruits which


they do not permit themselves to taste until they have made
an offering of them to the manitu-oo-al, or gods; ... There is
one of the greatest sacrifice offerings of our forefathers every
six months for cleansing themselves from sin; they will have
twelve deers to be consumed in one day and night. At the
great feast of the offerings of the first fruits of the earth, which
feast the Delawares or Munceys hold annually, they brought a
little of all that they raised, such as Indian corn, or hweisk-
queem, potatoes, beans, pumpkins, squashes, together with
the deer. The Indian women were busily engaged in cooking
their provisions, previous to the commencement of their
exercises. They invited all strangers into a long pagan temple
prepared for such purposes, there is a door at each end—one
opening to the east, and one opening to the west. On
entering, they with all the Indians were seated on the ground
around two fires; in the center of the temple was a large post,
around which was suspended a number of deer skins, and
wampum is kept buried at the foot of this post. Near the post
sat two Indian singers, each with a large bundle of undressed
deer skins which served as drums. There were two young
men appointed to watch the doors and keep the fires burning,
the doors being closed. Each of the young men brought an
armful of hemlock boughs, which being thrown on the fires
smothered them and caused a great smoke. In order that the
smoke might fill every corner of the temple, each man waved
his blanket over the fire; this was done with the idea of
purifying the temple and driving out the evil spirits. After the
smoke had subsided, the master of ceremonies, an old chief,
rose and began to rattle a turtle shell he had in his hand. He
delivered a speech to the people telling them the object of the
meeting was to thank the great spirit for the growth and
ripening of the corn. When he finished his speech he began to
dance, sing and rattle the shell, the two singers joining in,
beating on their skins. When he took his seat he handed the
shell to the next person, who performed in the same way, thus
it went from one to the other all night. The purport of their
speeches was to recount the mercies of the Great Spirit to
them during the past year, and telling any remarkable dreams
that they had had. In the course of the night a number of them
went out the west door, making a wailing noise to the moon,
and came in again the east door. In the morning the meat and
soup were divided amongst the people.
“These feasts often lasted twelve days and twelve nights,
and the Indians call it nee-shaw-neechk-togho-quanoo-maun,
or ween-da-much-teen. No drinking or improper conduct is
allowed. The utmost solemnity prevails.”
CHAPTER VII
The Mĭsiʹngʷ' or Mask
The Minsi version of the myth explaining the origin of their great
ceremonies has been already related, but not that of the Unami, for
the latter, which concerns itself with the origin of the Unami rites as
now practised, is so intimately interwoven with the story of the
Mĭsiʹngʷ', or mask (fig. 1), that it was thought best to place it in the
chapter devoted to that curious being, with whose position in the
Lenape pantheon, recorded history, and activities in the Annual
Ceremony, we have already become acquainted.
The myth is therefore presented herewith, as related by Chief
Charley Elkhair, the Lenape master of ceremonies, with only such
additions as later questioning brought forth.

ORIGIN OF THE MASK, AND OF THE BIG HOUSE


This is the way the Lenape found out that there is a living
Mĭsinghâliʹkŭn above us. Many years ago, when the Delawares lived
in the East, there were three boys who were not treated very well.
Their relatives did not take care of them, and it seemed as if it made
no difference whether the children died or not. These boys were out
in the woods thinking about their troubles, when they saw the
Mĭsinghâliʹkŭn or Living Solid Face. He came and spoke to them,
and gave them strength so that nothing could hurt them again. To
one of these boys he said, “You come along with me and I will show
you the country I come from.” So he took the boy up in the air to the
place whence he came, which is rocky mountains above us,
reaching out from the north and extending toward the south. It is not
the place where people go when they die, for it is not very far from
this earth. A long time ago people could see this country of
Mĭsinghâliʹkŭn, but none can see it now.
While he was showing the boy his country, the Mĭsinghâliʹkŭn
promised him that he would become stout and strong, and would
have the power to get anything he wished. Then he brought the boy
back.
Afterward, when the boy grew up and went hunting, he used to
see the Mĭsinghâliʹkŭn riding a buck around among the other deer,
herding them together. Thus it happened that there were three men
in the tribe, who knew that there is a Mĭsinghâliʹkŭn, because they
had seen him with their own eyes.
The Delawares had always kept a Big House (xiʹngwikan) to
worship in, but in those days it was built entirely of bark and had no
faces of the Mĭsiʹngʷ' carved upon the posts as it has now. Here they
used to sing about their dreams (visions of power); but some time
after the three boys talked with the Mĭsinghâliʹkŭn, the people gave
up this worship, and for ten years had none. Then there came a
great earthquake, which lasted twelve months and gave great
trouble to the Lenape. It came because they had abandoned the
worship their fathers had taught them. In those times the tribe lived
in towns, not scattered about the country as they are now, and in one
of these towns a chief had a big bark house, and here the people
met to worship, hoping to stop the earthquake, while they were
building a new Big House. When it was finished, they began to
worship there, and sang and prayed all winter for relief. After spring
came, they were holding a meeting one night when they heard the
Mĭsinghâliʹkŭn making a noise, “Hoⁿ-hoⁿ-hoⁿ,” right east of the Big
House. The chief, who did not know what was making the noise,
called for somebody to go and see what it was. Then these three
men offered to go, because, as they said, they knew what was
making the noise and could find out what he wanted. So they went
out and found Mĭsinghâliʹkŭn, and asked him what he wanted. He
answered:
“Go back and tell the others to stop holding meetings and attend to
their crops. Do not meet again until fall, when I will come and live
with you, and help in the Big House. You must take wood and carve
a face (Mĭsiʹngʷ') just like mine, painted half black and half red, as
mine is, and I will put my power in it, so that it will do what you ask.
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