<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/spring-boot-build-url-shortener-application---part-5-thymeleaf-form-submission-validations-oukhei1id" -->

---
title: Spring Boot: Build URL Shortener Application - Part 5:...
description: This tutorial installment continues a Spring Boot URL shortener series, walking through building a guest-user 'create short URL' feature with Thymeleaf. It...
canonical: https://daily.dev/posts/spring-boot-build-url-shortener-application---part-5-thymeleaf-form-submission-validations-oukhei1id
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Spring Boot: Build URL Shortener Application - Part 5: Thymeleaf Form Submission & Validations | daily.dev
og:description: This tutorial installment continues a Spring Boot URL shortener series, walking through building a guest-user 'create short URL' feature with Thymeleaf. It...
og:url: https://daily.dev/posts/spring-boot-build-url-shortener-application---part-5-thymeleaf-form-submission-validations-oukhei1id
og:image: https://api.daily.dev/og/posts/ouKheI1id.png
og:image:alt: Spring Boot: Build URL Shortener Application - Part 5: Thymeleaf Form Submission & Validations
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Spring Boot: Build URL Shortener Application - Part 5: Thymeleaf Form Submission & Validations

**[SivaLabs \(YouTube\)](https://daily.dev/sources/sivalabs-youtube)** · 38 min read · 0 upvotes · 0 comments

## Summary

This tutorial installment continues a Spring Boot URL shortener series, walking through building a guest-user 'create short URL' feature with Thymeleaf. It covers building a DTO record with Jakarta Bean Validation annotations, binding form fields with th:object and th:field, redisplaying forms with validation errors via BindingResult, using flash attributes for success/error messages with the post-redirect-get pattern, generating unique random short keys with SecureRandom, adding @ConfigurationProperties for base URL and expiry settings, validating original URL reachability, and adding @Transactional to the service layer.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=qaOTW_eZKiw>

## Questions this post answers

### How do I redisplay a Thymeleaf form with validation errors and previously entered values in Spring Boot?

Bind a form-backing object using th:object and th:field attributes, add it as a @ModelAttribute in the controller, and place a BindingResult parameter immediately after the model attribute in the handler method. If bindingResult.hasErrors() is true, return the same template name so Thymeleaf redisplays the form using th:errors and the retained field values.

_Developers wiring up Spring Boot form validation can find related Thymeleaf walkthroughs on daily.dev._

### Why use redirectAttributes.addFlashAttribute instead of a regular model attribute after a successful form submission in Spring MVC?

A regular model attribute does not survive a redirect because the redirect creates a completely new request. Flash attributes stored via redirectAttributes.addFlashAttribute persist across that redirect so a success or error message can be shown on the following page, which supports the post-redirect-get pattern that avoids duplicate form resubmission on browser refresh.

_Teams implementing post-redirect-get flows in Java web apps can track similar patterns on daily.dev._

## Similar posts on daily.dev

- [You're staying on the list](https://daily.dev/posts/you-re-staying-on-the-list-wy90nvyii) · Wim Deblauwe · 0 upvotes · 0 comments
- [Documenting Form Parameters With Spring REST Docs](https://daily.dev/posts/documenting-form-parameters-with-spring-rest-docs-hngqxpmip) · Baeldung · 0 upvotes · 0 comments
- [Writing a Thymeleaf component library - part 4](https://daily.dev/posts/writing-a-thymeleaf-component-library---part-4-2avjyhl6y) · Wim Deblauwe · 2 upvotes · 0 comments

---

Tags: [#java](https://daily.dev/tags/java), [#spring-boot](https://daily.dev/tags/spring-boot)

[View this post on daily.dev](https://daily.dev/posts/spring-boot-build-url-shortener-application---part-5-thymeleaf-form-submission-validations-oukhei1id)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Spring Boot: Build URL Shortener Application - Part 5: Thymeleaf Form Submission \u0026 Validations","url":"https://daily.dev/posts/spring-boot-build-url-shortener-application---part-5-thymeleaf-form-submission-validations-oukhei1id","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/spring-boot-build-url-shortener-application---part-5-thymeleaf-form-submission-validations-oukhei1id"},"datePublished":"2026-09-27T07:26:41.655Z","dateModified":"2026-09-27T07:53:35.663Z","description":"This tutorial installment continues a Spring Boot URL shortener series, walking through building a guest-user 'create short URL' feature with Thymeleaf. It...","image":"https://i.ytimg.com/vi/qaOTW_eZKiw/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/qaOTW_eZKiw/sddefault.jpg","isAccessibleForFree":true,"articleSection":"SivaLabs (YouTube)","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"SivaLabs (YouTube)","logo":"https://media.daily.dev/image/upload/s--8ATVo4an--/f_auto,q_auto/v1790493987/logos/sivalabs-youtube?_a=BAMAMicg0","url":"https://daily.dev/sources/sivalabs-youtube"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/spring-boot-build-url-shortener-application---part-5-thymeleaf-form-submission-validations-oukhei1id","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"java,spring-boot","timeRequired":"PT38M","video":{"@type":"VideoObject","name":"Spring Boot: Build URL Shortener Application - Part 5: Thymeleaf Form Submission \u0026 Validations","description":"This tutorial installment continues a Spring Boot URL shortener series, walking through building a guest-user 'create short URL' feature with Thymeleaf. It...","thumbnailUrl":"https://i.ytimg.com/vi/qaOTW_eZKiw/sddefault.jpg","uploadDate":"2026-09-27T07:26:41.655Z","duration":"PT38M","url":"https://api.daily.dev/r/ouKheI1id","embedUrl":"https://www.youtube.com/embed/qaOTW_eZKiw"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"SivaLabs (YouTube)","item":"https://daily.dev/sources/sivalabs-youtube"},{"@type":"ListItem","position":3,"name":"Spring Boot: Build URL Shortener Application - Part 5: Thymeleaf Form Submission \u0026 Validations"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/spring-boot-build-url-shortener-application---part-5-thymeleaf-form-submission-validations-oukhei1id#faq","mainEntity":[{"@type":"Question","name":"How do I redisplay a Thymeleaf form with validation errors and previously entered values in Spring Boot?","acceptedAnswer":{"@type":"Answer","text":"Bind a form-backing object using th:object and th:field attributes, add it as a @ModelAttribute in the controller, and place a BindingResult parameter immediately after the model attribute in the handler method. If bindingResult.hasErrors() is true, return the same template name so Thymeleaf redisplays the form using th:errors and the retained field values. Developers wiring up Spring Boot form validation can find related Thymeleaf walkthroughs on daily.dev."}},{"@type":"Question","name":"Why use redirectAttributes.addFlashAttribute instead of a regular model attribute after a successful form submission in Spring MVC?","acceptedAnswer":{"@type":"Answer","text":"A regular model attribute does not survive a redirect because the redirect creates a completely new request. Flash attributes stored via redirectAttributes.addFlashAttribute persist across that redirect so a success or error message can be shown on the following page, which supports the post-redirect-get pattern that avoids duplicate form resubmission on browser refresh. Teams implementing post-redirect-get flows in Java web apps can track similar patterns on daily.dev."}}]}
```

