Chapter 3. File Upload and Error Handling

In this chapter, we will enable our user to upload a profile picture. We will also see how to handle errors in Spring MVC.

Uploading a file

We will now make it possible for our user to upload a profile picture. This will be available from the profile page later on, but for now, we will simplify things and create a new page in the templates directory under profile/uploadPage.html:

<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="layout/default"> <head lang="en"> <title>Profile Picture Upload</title> </head> <body> <div class="row" layout:fragment="content"> <h2 class="indigo-text center">Upload</h2> <form th:action="@{/upload}" ...

Get Spring MVC: Designing Real-World Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.