Chapter 6. Rendering web views

 

This chapter covers

  • Rendering model data as HTML
  • Using JSP views
  • Defining view layout with tiles
  • Working with Thymeleaf views

In the previous chapter, we primarily focused on writing the controllers that handle web requests. You also created some simple views to render the model data produced by those controllers, but we didn’t spend too much time discussing the views or what happens between the time a controller finishes handling a request and the time the results are displayed in the user’s web browser. That’s the topic of this chapter.

6.1. Understanding view resolution

None of the methods in the controllers you wrote in chapter 5 directly produce the HTML that is rendered in the browser. Instead, they populate the model with some data and then pass the model off to a view for rendering. Those methods return a String value that is the logical name of the view but that doesn’t directly refer to a specific view implementation. Although you wrote a few simple JavaServer Page (JSP) views, nothing in the controllers is aware of that fact.

6.2. Creating JSP views

6.3. Defining a layout with Apache Tiles views

6.4. Working with Thymeleaf

6.5. Summary