Spring MVC Beginner’s Guide

Book description

Unleash the power of the latest Spring MVC 4.x to develop a complete application

About This Book

  • Work through carefully crafted exercises with detailed explanations for each step will help you understand the concepts with ease
  • You will gain a clear understanding of the end-to-end request/response life cycle, and each logical component’s responsibility
  • This book is packed with tips and tricks that demonstrate industry best practices on developing a Spring-MVC-based application

Who This Book Is For

The book is for Java developers who want to exploit Spring MVC and its features to build web applications. Some familiarity with basic servlet programming concepts would be a plus, but is not a prerequisite.

What You Will Learn

  • Familiarize yourself with the anatomy of the Spring 4.X development environment
  • Understand web application architecture and the Spring MVC request flow
  • Integrate bean validation and custom validation
  • Use error handling and exception resolving
  • Get to grips with REST-based web service development and Ajax
  • Test your web application

In Detail

Spring MVC helps you build flexible and loosely coupled web applications. The Spring MVC Framework is architected and designed in such a way that every piece of logic and functionality is highly configurable. Also, Spring can integrate effortlessly with other popular web frameworks such as Struts, WebWork, Java Server Faces, and Tapestry.

The book progressively teaches you to configure the Spring development environment, architecture, controllers, libraries, and more before moving on to developing a full web application. It begins with an introduction to the Spring development environment and architecture so you're familiar with the know-hows. From here, we move on to controllers, views, validations, Spring Tag libraries, and more. Finally, we integrate it all together to develop a web application. You'll also get to grips with testing applications for reliability.

Style and approach

This book takes a pragmatic step-by-step approach to web application development using Spring MVC, with informative screenshots and concise explanation.

Table of contents

  1. Spring MVC Beginner's Guide - Second Edition
    1. Spring MVC Beginner's Guide - Second Edition
    2. Credits
    3. About the Author
    4. About the Reviewer
    5. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why subscribe?
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Sections
        1. Time for action
        2. What just happened?
        3. Pop quiz
        4. Have a go hero
      5. Conventions
      6. Reader feedback
      7. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book 
        3. Errata
        4. Piracy
        5. Questions
    7. 1. Configuring a Spring Development Environment
      1. Setting up Java
        1. Time for action - installing JDK
        2. Time for action - setting up environment variables
      2. Configuring a build tool
        1. Time for action - installing the Maven build tool
      3. Installing a web server
        1. Time for action - installing the Tomcat web server
      4. Configuring a development environment
        1. Time for action - installing Spring Tool Suite
        2. Time for action - configuring Maven on STS
        3. Time for action - configuring Tomcat on STS
      5. Creating our first Spring MVC project
        1. Time for action - creating a Spring MVC project in STS
        2. Time for action - adding Java version properties in pom.xml
        3. What just happened?
      6. Spring MVC dependencies
        1. Time for action - adding Spring jars to the project
        2. What just happened?
      7. A jump-start to MVC
        1. Time for action - adding a welcome page
        2. What just happened?
      8. The Dispatcher servlet
        1. Time for action - configuring the Dispatcher servlet
        2. What just happened?
      9. Deploying our project
        1. Time for action - running the project
      10. Summary
    8. 2. Spring MVC Architecture – Architecting Your Web Store
      1. Dispatcher servlet
        1. Time for action - examining request mapping
        2. What just happened?
        3. Pop quiz – request mapping
      2. Understanding the Dispatcher servlet configuration
        1. Time for action - examining the servlet mapping
        2. What just happened?
      3. Servlet mapping versus request mapping
        1. Pop quiz - servlet mapping
      4. Web application context
      5. View resolvers
        1. Time for action - understanding web application context
        2. What just happened?
      6. Understanding the web application context configuration
        1. Pop quiz - web application context configuration
      7. Model View Controller
      8. Overview of the Spring MVC request flow
      9. The web application architecture
      10. The Domain layer
        1. Time for action - creating a domain object
        2. What just happened?
      11. The Persistence layer
        1. Time for action - creating a repository object
        2. What just happened?
      12. The Service layer
        1. Time for action - creating a service object
        2. What just happened?
        3. Have a go hero - accessing the product domain object via a service
      13. An overview of the web application architecture
        1. Have a go hero - listing all our customers
      14. Summary
    9. 3. Control Your Store with Controllers
      1. The role of a Controller in Spring MVC
      2. Defining a Controller
        1. Time for action - adding class-level request mapping
        2. What just happened?
      3. Default request mapping method
        1. Pop quiz - class level request mapping
      4. Handler mapping
      5. Using URI template patterns
        1. Time for action - showing products based on category
        2. What just happened?
        3. Pop quiz - request path variable
      6. Using matrix variables
        1. Time for action - showing products based on filters
        2. What just happened?
      7. Understanding request parameters
        1. Time for action - adding a product detail page
        2. What just happened?
        3. Pop quiz - the request parameter
        4. Time for action - implementing a master detail View
        5. What just happened?
        6. Have a go hero - adding multiple filters to list products
      8. Summary
    10. 4. Working with Spring Tag Libraries
      1. The JavaServer Pages Standard Tag Library
      2. Serving and processing forms
        1. Time for action - serving and processing forms
        2. What just happened?
        3. Have a go hero - customer registration form
      3. Customizing data binding
        1. Time for action - whitelisting form fields for binding
        2. What just happened?
        3. Pop quiz - data binding
      4. Externalizing text messages
        1. Time for action - externalizing messages
        2. What just happened?
        3. Have a go hero - externalizing all the labels from all the pages
      5. Summary
    11. 5. Working with View Resolver
      1. Resolving Views
      2. RedirectView
        1. Time for action - examining RedirectView
        2. What just happened?
        3. Pop quiz - RedirectView
      3. Flash attribute
      4. Serving static resources
        1. Time for action - serving static resources
        2. What just happened?
        3. Pop quiz - static view
        4. Time for action - adding images to the product detail page
        5. What just happened?
      5. Multipart requests in action
        1. Time for action - adding images to a product
        2. What just happened?
        3. Have a go hero - uploading product user manuals to the server
      6. Using ContentNegotiatingViewResolver
        1. Time for action - configuring ContentNegotiatingViewResolver
        2. What just happened?
      7. Working with HandlerExceptionResolver
        1. Time for action - adding a ResponseStatus exception
        2. What just happened?
        3. Time for action - adding an exception handler
        4. What just happened?
      8. Summary
    12. 6. Internalize Your Store with Interceptor
      1. Working with interceptors
        1. Time for action - configuring an interceptor
        2. What just happened?
        3. Pop quiz - interceptors
      2. LocaleChangeInterceptor - internationalization
        1. Time for action - adding internationalization
        2. What just happened?
        3. Have a go hero - fully internationalize the product details page
      3. Mapped interceptors
        1. Time for action - mapped intercepting offer page requests
        2. What just happened?
      4. Summary
    13. 7. Incorporating Spring Security
      1. Using Spring Security
        1. Time for action - authenticating users based on roles
        2. What just happened?
        3. Pop quiz - Spring Security
        4. Have a go hero - play with Spring Security
      2. Summary
    14. 8. Validate Your Products with a Validator
      1. Bean Validation
        1. Time for action - adding Bean Validation support
        2. What just happened?
        3. Have a go hero - adding more validation in the Add new product page
      2. Custom validation with JSR-303/Bean Validation
        1. Time for action - adding Bean Validation support
        2. What just happened?
        3. Have a go hero - adding custom validation to a category
      3. Spring validation
        1. Time for action - adding Spring validation
        2. What just happened?
        3. Time for action - combining Spring validation and Bean Validation
        4. What just happened?
        5. Have a go hero - adding Spring validation to a product image
      4. Summary
    15. 9. Give REST to Your Application with Ajax
      1. Introduction to REST
        1. Time for action - implementing RESTful web services
        2. What just happened?
        3. Time for action - consuming REST web services
        4. What just happened?
      2. Handling web services in Ajax
        1. Time for action - consuming REST web services via Ajax
      3. What just happened?
      4. Summary
    16. 10. Float Your Application with Web Flow
      1. Working with Spring Web Flow
        1. Time for action - implementing the order processing service
        2. What just happened?
        3. Time for action - implementing the checkout flow
        4. What just happened?
      2. Understanding flow definitions
      3. Understanding checkout flow
        1. Pop quiz - web flow
        2. Time for action - creating Views for every view state
        3. What just happened?
        4. Have a go hero - adding a decision state
      4. Summary
    17. 11. Template with Tiles
      1. Enhancing reusability through Apache Tiles
        1. Time for action - creating Views for every View state
        2. What just happened?
        3. Pop quiz - Apache Tiles
      2. Summary
    18. 12. Testing Your Application
      1. Unit testing
        1. Time for action - unit testing domain objects
        2. What just happened?
        3. Have a go hero - adding tests for Cart
      2. Integration testing with the Spring Test context framework
        1. Time for action - testing product validator
        2. What just happened?
        3. Time for action - testing product Controllers
        4. What just happened?
        5. Time for action - testing REST Controllers
        6. What just happened?
        7. Have a go hero - adding tests for the remaining REST methods
      3. Summary
      4. Thank you readers!
    19. Appendix A. Using the Gradle Build Tool
      1. Installing Gradle
      2. The Gradle build script for your project
      3. Understanding the Gradle script
    20. Appendix B. Pop Quiz Answers
      1. Chapter 2, Spring MVC Architecture - Architecting Your Web Store
      2. Chapter 3, Control Your Store with Controllers
      3. Chapter 4, Working with Spring Tag Libraries
      4. Chapter 5, Working with View Resolver
      5. Chapter 6, Internalize Your Store with Interceptor
      6. Chapter 7, Incorporating Spring Security
      7. Chapter 10, Float Your Application with Web Flow
      8. Chapter 11, Template with Tiles

Product information

  • Title: Spring MVC Beginner’s Guide
  • Author(s): Amuthan Ganeshan
  • Release date: July 2016
  • Publisher(s): Packt Publishing
  • ISBN: 9781785880636