You are previewing Spring MVC Beginner’s Guide.
O'Reilly logo
Spring MVC Beginner’s Guide

Book Description

Your ultimate guide to building a complete web application using all the capabilities of Spring MVC

In Detail

The MVC architecture for developing web applications continues to be a powerful concept and the most popular design pattern known by developers. Spring MVC is a model-view-controller framework for Java web applications to simplify the writing and testing of Java web applications, which fully integrates with the Spring dependency injection framework. With the power of annotation-based configuration, Spring MVC makes web application development easy for developers.

This book is a great companion for beginners who want to learn Spring MVC. With the help of real-world examples, you will learn how to create a completely functional web application. You will also get a complete overview of the Spring web development environment and all its key components.

What You Will Learn

  • Familiarize yourself with the anatomy of the Spring development environment
  • Learn about the web application architecture and Spring MVC request flow
  • Integrate bean validation and custom validation
  • Use error handling and exception resolving
  • Discover REST-based web service development and Ajax
  • Test your web application
  • Learn how to use Tiles and Web Flow frameworks in your MVC application
  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. Spring MVC Beginner's Guide
      1. Table of Contents
      2. Spring MVC Beginner's Guide
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Time for action – heading
          1. What just happened?
          2. Pop quiz – heading
          3. Have a go hero – heading
        6. Reader feedback
        7. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Configuring a Spring Development Environment
        1. Setting up Java
        2. Time for action – installing JDK
        3. Time for action – setting up environment variables
        4. Configuring a build tool
        5. Time for action – installing the Maven build tool
        6. Installing a web server
        7. Time for action – installing the Tomcat web server
        8. Configuring a development environment
        9. Time for action – installing Spring Tool Suite
        10. Time for action – configuring Tomcat on STS
          1. What just happened?
        11. Time for action – configuring Maven on STS
        12. Creating our first Spring MVC project
        13. Time for action – creating a Spring MVC project in STS
          1. What just happened?
          2. Spring MVC dependencies
        14. Time for action – adding Spring jars to the project
          1. What just happened?
        15. Time for action – adding Java version properties in pom.xml
          1. A jump-start to MVC
        16. Time for action – adding a welcome page
          1. What just happened?
          2. The dispatcher servlet
        17. Time for action – configuring the dispatcher servlet
          1. What just happened?
          2. Deploying our project
        18. Time for action – running the project
        19. Summary
      9. 2. Spring MVC Architecture – Architecting Your Web Store
        1. The dispatcher servlet
        2. Time for action – examining request mapping
          1. What just happened?
          2. Pop quiz – request mapping
        3. The web application context
        4. Time for action – understanding the web application context
          1. What just happened?
          2. Pop quiz – the web application context
        5. The web application context configuration
          1. Pop quiz – web application context configuration
        6. View resolvers
        7. Time for action – understanding InternalResourceViewResolver
          1. What just happened?
        8. Model View Controller
        9. An overview of the Spring MVC request flow
        10. The web application architecture
        11. The domain layer
        12. Time for action – creating a domain object
          1. What just happened?
        13. The persistence layer
        14. Time for action – creating a repository object
          1. What just happened?
        15. The service layer
        16. Time for action – creating a service object
          1. What just happened?
          2. Have a go hero – accessing the product domain object via a service
        17. An overview of the web application architecture
          1. Have a go hero – listing all our customers
        18. Summary
      10. 3. Control Your Store with Controllers
        1. Defining a controller
        2. Time for action – adding class-level request mapping
          1. What just happened?
          2. Pop quiz – class-level request mapping
        3. The role of a controller in Spring MVC
        4. Handler mapping
        5. Using URI template patterns
        6. Time for action – showing products based on category
          1. What just happened?
          2. Pop quiz – request path variable
        7. Using matrix variables
        8. Time for action – showing the products based on filter
          1. What just happened?
        9. Understanding request parameters
        10. Time for action – adding the product details page
          1. What just happened?
          2. Pop quiz – the request parameter
        11. Time for action – implementing a master detail view
          1. What just happened?
          2. Have a go hero – adding multiple filters to list products
        12. Summary
      11. 4. Working with Spring Tag Libraries
        1. Serving and processing forms
        2. Time for action – serving and processing forms
          1. What just happened?
        3. Customizing data binding
        4. Time for action – whitelisting form fields
          1. What just happened?
        5. Externalizing text messages
        6. Time for action – externalizing messages
          1. What just happened?
        7. Using Spring Security tags
        8. Time for action – adding a login page
          1. What just happened?
        9. Summary
      12. 5. Working with View Resolver
        1. Resolving views
        2. The redirect view
        3. Time for action – examining RedirectView
          1. What just happened?
          2. Pop quiz – redirect view
        4. Serving static resources
        5. Time for action – serving static resources
          1. What just happened?
          2. Pop quiz – static view
        6. Time for action – adding images to the product detail page
          1. What just happened?
        7. The multipart request in action
        8. Time for action – adding images to the product page
          1. What just happened?
          2. Have a go hero – uploading product user manuals to the server
        9. Using ContentNegotiatingViewResolver
        10. Time for action – configuring ContentNegotiatingViewResolver
          1. What just happened?
        11. Working with the handler exception resolver
        12. Time for action – adding the response status exception
          1. What just happened?
        13. Time for action – adding an exception handler
          1. What just happened?
        14. Summary
      13. 6. Intercept Your Store with Interceptor
        1. Working with interceptors
        2. Time for action – configuring an interceptor
          1. What just happened?
          2. Pop quiz – interceptor
        3. Internationalization (i18n)
        4. Time for action – adding internationalization
          1. What just happened?
          2. Have a go hero – fully internationalize the product detail page
        5. Audit logging
        6. Time for action – adding the data audit interceptor
          1. What just happened?
        7. Conditional redirecting
        8. Time for action – intercepting offer page requests
          1. What just happened?
        9. Summary
      14. 7. Validate Your Products with a Validator
        1. Bean validation
        2. Time for action – adding bean validation support
          1. What just happened?
          2. Have a go hero – adding more validation in the add products page
        3. Custom validation with JSR-303 / bean validation
        4. Time for action – adding custom validation support
          1. What just happened?
          2. Have a go hero – adding custom validation to a category
        5. Spring validation
        6. Time for action – adding Spring validation
          1. What just happened?
        7. Time for action – combining Spring and bean validations
          1. What just happened?
          2. Have a go hero – adding Spring validation to the product image
        8. Summary
      15. 8. Give REST to Your Application with Ajax
        1. Introducing REST
        2. Time for action – implementing RESTful web services
          1. What just happened?
        3. Time for action – consuming REST web services
          1. What just happened?
        4. Handling a web service in Ajax
        5. Time for action – consuming REST web services via Ajax
          1. What just happened?
        6. Summary
      16. 9. Apache Tiles and Spring Web Flow in Action
        1. Working with Spring Web Flow
        2. Time for action – implementing the order-processing service
          1. What just happened?
        3. Time for action – implementing the checkout flow
          1. What just happened?
          2. Understanding the flow definition
          3. Understanding the checkout flow
          4. Pop quiz – web flow
        4. Time for action – creating views for every view state
          1. What just happened?
          2. Have a go hero – adding a decision state
        5. Enhancing reusability through Apache Tiles
        6. Time for action – creating views for every view state
          1. What just happened?
          2. Pop quiz – Apache Tiles
        7. Summary
      17. 10. Testing Your Application
        1. Unit testing
        2. Time for action – unit-testing domain objects
          1. What just happened?
          2. Have a go hero – adding tests for cart
        3. Integration testing with the Spring Test Context framework
        4. Time for action – testing the product validator
          1. What just happened?
        5. Time for action – testing the product controller
          1. What just happened?
        6. Time for action – testing REST controllers
          1. What just happened?
          2. Have a go hero – adding tests for the remaining REST methods
        7. Summary
      18. A. Using the Gradle Build Tool
        1. Installing Gradle
        2. The Gradle build script for your project
        3. Understanding the Gradle script
      19. B. Pop Quiz Answers
        1. Chapter 2, Spring MVC Architecture – Architecting Your Web Store
          1. Pop quiz – request mapping
          2. Pop quiz – the web application context
          3. Pop quiz – web application context configuration
        2. Chapter 3, Control Your Store with Controllers
          1. Pop quiz – class-level request mapping
          2. Pop quiz – request path variable
          3. Pop quiz – the request parameter
        3. Chapter 5, Working with View Resolver
          1. Pop quiz – redirect view
          2. Pop quiz – static view
        4. Chapter 6, Intercept Your Store with Interceptor
          1. Pop quiz – interceptor
        5. Chapter 9, Apache Tiles and Spring Web Flow in Action
          1. Pop quiz – web flow
          2. Pop quiz – Apache Tiles
      20. Index