Quick revision
The short answer
Thymeleaf renders natural HTML templates on the server, integrates with Spring forms and escapes output by default. JSP pages are compiled into servlets by the container, and Spring Boot does not support them in executable jars (and never supported them on Undertow), so JSP needs war packaging and is legacy for new projects. Vaadin Flow is a different model: we build UI components in Java on the server, and a client engine in the browser keeps them in sync, so UI state lives in the server session.
What to remember
In this answer, we saw that Thymeleaf renders natural HTML templates with Spring form integration and escaping by default, which makes it the usual choice for server-rendered Spring Boot pages. JSP is compiled into servlets by the container, needs war packaging on Boot and is legacy for new work. Vaadin Flow keeps Java components on the server and syncs them with a client engine, giving rich UIs without JavaScript at the cost of session memory and sticky sessions. We also saw that th:utext turns escaping off and must only receive sanitised HTML.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Thymeleaf renders natural HTML templates on the server, integrates with Spring forms and escapes output by default. JSP pages are compiled into servlets by the container, and Spring Boot does not support them in executable jars (and never supported them on Undertow), so JSP needs war packaging and is legacy for new projects. Vaadin Flow is a different model: we build UI components in Java on the server, and a client engine in the browser keeps them in sync, so UI state lives in the server session.
Why this question is asked
Most Spring Boot web applications still render some HTML on the server: admin screens, internal tools, simple customer pages. Choosing the view technology affects packaging, security and how much the server must remember about each user. Interviewers ask this to see whether we understand the rendering model behind each option rather than just the syntax. In this answer, we will recap what server-side rendering means, look at Thymeleaf, JSP and Vaadin one at a time, explain the JSP packaging limitation, and finish with a comparison and the XSS follow-up about th:utext.
1A Quick Recap of Server-Side Rendering
In a classic Spring MVC application, a controller puts data into a model, a map of named values, and returns a view name. A view resolver turns that name into a template, and the template engine merges the model into HTML. The browser receives a finished page. Each request is independent: once the HTML is sent, the server forgets the page.
Thymeleaf and JSP both follow this template model. Vaadin does not, and that difference matters more than any syntax detail.
2Thymeleaf: Natural Templates With Spring Integration
A Thymeleaf template is valid HTML with extra attributes in the th namespace. A designer can open it in a browser and see a sensible page with placeholder text, which is why it is called a natural template. Adding spring-boot-starter-thymeleaf is enough: Boot auto-configures the engine and looks for templates in src/main/resources/templates.
Notice the Spring integration: th:field binds an input to a property of the form object and keeps its value after a failed submit, and th:errors shows the validation messages from the BindingResult. Also notice that th:text escapes HTML, so a value containing a script tag is shown as text and not run. That default is a big part of why Thymeleaf is the usual choice for new Spring projects.
3JSP and Why Boot Discourages It With Executable Jars
JSP, now called Jakarta Pages in Jakarta EE, is older. The servlet container translates each .jsp file into a Java servlet and compiles it, usually on first request. That translation is done by a JSP engine such as Jasper in Tomcat, and it expects the pages to sit in the web application's file layout, under WEB-INF or the document root.
An executable Spring Boot jar does not have that layout. The application and its dependencies are packaged as nested jars, and the embedded container cannot find and compile JSP files from there in the normal way. So the Spring Boot documentation lists JSP as a known limitation: it works with Tomcat or Jetty when we package as a war (which can still be run with java -jar or deployed to a container), it does not work from an executable jar, and it was never supported on Undertow. Spring Boot 4 dropped Undertow altogether, so check your version, but the rule for JSP is the same.
JSP also escapes nothing by default: ${name} in a page writes the raw value, and we must remember c:out or fn:escapeXml. Together with the packaging friction, that is why JSP is considered legacy for new Spring work, even though Jakarta Pages is still part of Jakarta EE and existing applications can keep running.
4Vaadin Flow: Components on the Server
Vaadin Flow turns the model around. We do not write templates at all. We write Java classes that create components such as TextField, Grid and Button, and attach listeners to them. The component tree lives on the server, in the user's session.
5 messages in order. Play them, or step through them one at a time.
The server holds the component tree; the browser only renders it and reports events.
In the browser, a small client engine draws the components. When the user types or clicks, the engine sends the event to the server over HTTP, the listener runs in Java, and the server sends back only the changes to the component tree. Optional push uses WebSocket so the server can update the page on its own.
5Comparing the Trade-Offs
Templates are simple. Each request is independent, pages can be cached, any server can answer any request, and memory per user is small. The cost is that rich interaction needs JavaScript or tools like htmx.
Vaadin gives rich components such as editable grids without writing JavaScript, which suits Java teams building internal tools. The cost is server memory for every open UI, often tens to hundreds of kilobytes per user depending on the views, and sticky sessions or session replication so each user's events reach the server that holds their tree.
| Thymeleaf | JSP | Vaadin Flow | |
|---|---|---|---|
| Model | HTML template rendered per request | Compiled to a servlet | Java components kept on server |
| Boot packaging | Executable jar | War only | Executable jar |
| Escaping | On by default with th:text | Off unless c:out | Components escape text |
| Server state | None between requests | None between requests | UI tree in the session |
| Best fit | Most server-rendered pages | Existing legacy apps | Rich internal tools, Java teams |
6Follow-up questions
How does Thymeleaf prevent XSS, and when does th:utext bring it back?
th:text and th:field escape the characters that have meaning in HTML, so a value like <script> is written as <script> and shown as text. th:utext, the unescaped variant, writes the value as raw HTML, so if any part of it came from a user, a stored script runs in every reader's browser. Use th:utext only for HTML we produced and sanitised ourselves, for example with an HTML sanitiser allow-list, and remember that escaping is per context: values inside JavaScript or URLs need th:inline="javascript" or the @{...} URL syntax rather than plain text escaping.
Can Thymeleaf update part of a page without a full reload?
Yes. A controller can return a fragment, for example "orders :: table", and a small library such as htmx swaps that fragment into the page after a click or input. This keeps the server-rendered model while giving some interactivity, and is often enough for internal tools.
Does Vaadin need sticky sessions?
Yes, in practice. The UI state for each user lives in their HTTP session on one server, so the load balancer must send that user's requests to the same node. Session replication is possible but expensive for large UI trees, so most deployments use sticky sessions and accept that a node failure resets the user's view.
7Conclusion
In this answer, we saw that Thymeleaf renders natural HTML templates with Spring form integration and escaping by default, which makes it the usual choice for server-rendered Spring Boot pages. JSP is compiled into servlets by the container, needs war packaging on Boot and is legacy for new work. Vaadin Flow keeps Java components on the server and syncs them with a client engine, giving rich UIs without JavaScript at the cost of session memory and sticky sessions. We also saw that th:utext turns escaping off and must only receive sanitised HTML.
Open with
Thymeleaf and JSP are both template engines: the controller fills a model, the template turns it into HTML, and the server forgets the page after sending it. Thymeleaf is the usual choice today.
Then, if they want more
Its templates are valid HTML, Spring Boot auto-configures it with the starter, it integrates with forms through th:field and th:errors, and th:text escapes output by default, which protects against XSS unless someone uses th:utext with user data. JSP is older.
The container translates each page into a servlet, and that relies on the web app's file layout, which an executable Boot jar doesn't have. So Boot documents JSP as a limitation: you need war packaging with Tomcat or Jetty, and it never worked on Undertow. I'd only keep JSP in existing apps. Vaadin Flow is a different model altogether.
You write UI components in Java, the component tree lives in the user's session on the server, and a client engine in the browser renders it and sends events back over HTTP or WebSocket.
That gives you rich grids and forms without writing JavaScript, which suits Java teams building internal tools, but each user costs server memory and you need sticky sessions. Templates are simpler, stateless and easy to scale.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 4
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Spring Web MVC
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Compare Thymeleaf, JSP and Vaadin for building web UIs in a Spring Boot application. Why...": https://scrivio-interview-library.netlify.app/spring-boot/mvc-architecture/e35e32d2d1/