Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between spring JSP MVC and Thymeleaf MVC

What is the difference between spring JSP MVC and Thymeleaf MVC? Which one is best way for spring web design ?

like image 922
Zafer Yilmaz Avatar asked Dec 07 '16 13:12

Zafer Yilmaz


People also ask

Can we use Thymeleaf with JSP?

Both solutions work but have some contraints. You have to specify one way or another whether you want to resolve with JSP or Thymeleaf.

Is Thymeleaf faster than JSP?

From what I read, Thymeleaf is pretty slow compared to other templating languages, while JSP is very fast, with FreeMarker and Velocity coming close. However, Thymeleaf supports natural templates (templates that will render nicely in your browser even if you don't run them through the template engine).

Can we use Thymeleaf with JSP in Spring Boot?

if you are starting new project why jsp. Go with thymeleaf. Spring boot discourage using jsp with embedded tomcat. But if you want2learn check github.com/spring-projects/spring-boot/tree/v2.0.5.RELEASE/…

Is Thymeleaf supported by Spring MVC?

Thymeleaf offers a set of Spring integrations that allow you to use it as a fully-featured substitute for JSP in Spring MVC applications.


1 Answers

Both of them are view layers of Spring MVC. Firstly, the very basic difference is the file extensions. (.jsp & .html)

Branislav in the comments is right, JSP is not a template engine. It's compiled to the servlet and then the servlet is serving web content. On the other hand, Thymeleaf is a template engine which takes the HTML file, parses it and then produces web content which is being served.

  • Thymeleaf is more like an HTML-ish view when you compare it with JSP views.

  • We can use prototype code in thymeleaf : http://www.dineshonjava.com/2015/01/thymeleaf-vs-jsp-spring-mvc-view-layer.html#.WEkLzLKLTig

  • Since it is more HTML-ish code, thymeleaf codes are more readable (of course you can disrupt it and create unreadable codes, but at the end, it will be more readable when you compare it with .jsp files)

  • Standard Dialect (The expression language) is much more powerful than JSP Expression Language

  • If we put all this to an edge, thymeleaf is the slow one here.

I would suggest you to take a look at this doc : http://www.thymeleaf.org/doc/articles/thvsjsp.html

like image 165
Prometheus Avatar answered Oct 18 '22 16:10

Prometheus