Spring Boot Web MVC: JSP Form with ModelAttribute and error handling

Опубликовано: 22 Октябрь 2024
на канале: Xavier Dupont
262
0

In this video, we create a JSP form using the ModelAttribute annotation and some error handling, sending back the form with the supplied values when the form has errors.
There are a couple tricks in this video.
One trick is that HTML forms have a special handling for checkboxes. When the checkbox is not checked, the form is not checked. Spring does not handled that, but here the value is correctly false in this case because we use boolean. If we used Boolean instead, we would have to manually set it to false.
If the checkbox is checked, it sends "on", and Spring converts this to true for booleans.
Second trick is that we want to send back the form, if the form is not in WEB-INF, then it's not reachable from Spring, but if it is in WEB-INF, then it is not public. So we redirect GET request to /signup to the signup.jsp using the signup view.