Learn Java for Web Development.pdf

(17649 KB) Pobierz
www.it-ebooks.info
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
www.it-ebooks.info
Contents at a Glance
About the Author �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½
xv
About the Technical Reviewer �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½
xvii
Introduction �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½
xix
Chapter 1: Introducing Java Web Development�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½1
Chapter 2: Building Web Applications Using Servlets and JSP �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½43
Chapter 3: Best Practices in Java EE Web Development �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½105
Chapter 4: Building a Web Application Using Struts 2 �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½161
Chapter 5: Building Java Web Applications with Spring Web MVC �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½203
Chapter 6: Component-Based Web Development Using JSF 2 �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½263
Chapter 7: Rapid Web Development with Grails �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½299
Chapter 8: Play with Java and Scala �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½355
Appendix A: Introduction to Java �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½383
Appendix B: Introduction to Groovy�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½399
Appendix C: Introduction to Scala �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½423
Index �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½435
v
www.it-ebooks.info
Introduction
This book is for a large cross section of modern Java web developers, with various levels of
experience.
Learning the Java programming language is a noble cause, but learning merely the Java language
is not enough in the real world. Java developers have to learn Java EE, a collection of related
server-side technologies, to put their Java skills to any real use.
But learning Java EE is not enough either. The Java language along with Java EE may suffice to
develop web applications for projects in the same organization, as a means to reusability, but the
diverse landscape of Java on the Web is permeated with several web frameworks, such as Spring
Web MVC, that make development much easier; thus, a Java web developer has to have the
knowledge of these web frameworks.
But this is not enough still. In the very first line of this introduction, I mentioned that this book is for
a modern Java web developer. Modern Java is more than just a language; it is now a fully optimized
platform because several other languages such as Groovy and Scala, called the
JVM languages,
now run on the Java Virtual Machine (JVM). All such JVM languages, especially Groovy, have a close
association with Java, and you will come across web applications before long where Java and these
other JVM languages work in tandem. The most ambitious projects will require you to build web
applications using these JVM languages.
This book addresses all the needs of a modern Java web developer. It is designed for beginners up
to intermediate developers and explains the specifics of Java on the Web. For example, this book is
perfect for developers who are aware of technologies like MVC but do not yet understand how and
why they have changed the way web applications are built.
This book is also for developers who want to learn frameworks other than JSF 2 (which is bundled
with Java EE). This book covers four types of web frameworks: request based, component based,
rapid, and reactive. Among these four types, the book covers five proven web frameworks: Struts 2,
Spring Web MVC, JSF 2, Grails 2, and Play 2.
In addition, this book is for developers who have no experience in the Java, Groovy, and Scala
programming languages but who yearn to create web applications. This book provides the essentials
of these three languages in the appendixes.
xix
www.it-ebooks.info
xx
Introduction
Instead of simply pronouncing one web framework the best,
Learn Java for Web Development
shows the strengths of the most popular web frameworks by means of a real-world bookstore
application. Developing a complete real application necessitates a seamless collaboration of
dynamic functionalities, and the code for building such components is contrived and too involved.
Instead of focusing on developing such moving parts, this book confines its attention on leveraging
the strengths of each web framework.
How the Book Is Structured
The book consists of eight chapters, which I’ll describe next, plus the three previously mentioned
appendixes that introduce the Java, Groovy, and Scala languages.
Chapter 1: Introducing Java Web Development
Chapter 1 explains the main objective that shapes this book and highlights what appears in the
subsequent chapters. This chapter begins with a discussion of a significant change in the Java
landscape, its implication, and what Java exactly means today. The chapter then discusses the three
key players that join forces in building modern Java web applications: the JVM languages, Java EE,
and the Java web frameworks.
This chapter introduces the key features of a modern Java web application such as Ajax and REST,
WebSocket for real-time web application, the Typesafe stack for a reactive web application, and
client-side MVC frameworks for responsive and single-page web applications. Finally, the chapter
introduces some important aspects of modern web development that are beyond the scope of this
book, such as Java information retrieval on the Web, and briefly introduces the central component of
Web 3.0, which is still an open subject of research, the Semantic Web.
Chapter 2: Building Web Applications Using Servlets and JSP
Chapter 2 begins with a discussion of the evolution and architecture of web applications. The
chapter then highlights how to use the standard web API. The first pass at the sample application
uses only servlets and JSP. Then the chapter shows you how to build the same application as a
Model 2 application.
Chapter 3: Best Practices in Java EE Web Development
Chapter 3 examines the chain of causality that leads to the need for following best practices.
The chapter explains the need to evolve projects and introduces Expression Language and JSTL.
The chapter then discusses the Java EE web tier patterns.
Chapter 4: Building a Web Application Using Struts 2
In Chapter 4, you’ll learn about Struts 2. Not as popular as it used to be, Struts 2 is introduced in
this book for developers who have to maintain legacy applications. This chapter first introduces
the key architectural components of Struts 2. Then you will learn to develop your first application
using Struts 2 and Maven 4. Moving forward, you will learn to develop the bookstore application and
integrate with Tiles 3.
www.it-ebooks.info
Zgłoś jeśli naruszono regulamin