57

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

2 Answers 2

47

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

7
  • @ZaferYilmaz hope this finds you well, please do not hesitate to comment here if you have any orher questions about the answer.
    – Prometheus
    Dec 8, 2016 at 8:01
  • Thymeleaf is a natural templating engine. We can live-preview the changes without having to compile, build and run Feb 26, 2018 at 10:24
  • 1
    The problem with JSP is that it allows you to mix Java code in which HTML, making it hard to read. But, by defining tags, you never really need to do this, and, indeed, to do so is bad practice. A properly written JSP is, in my opinion, much easier to read and understand than a Thymeleaf template.
    – NickJ
    Feb 11, 2019 at 14:38
  • 2
    What about performance? Which one of these two frameworks is faster and how many memory needs each of them? Jun 5, 2019 at 9:11
  • JSP gets compiled to java, and thymeleaf templates are interpreted afaik, hence the performance difference is substantial: github.com/jreijn/spring-comparing-template-engines
    – stephan f
    Nov 1, 2019 at 23:20
11

Thymeleaf is template resolver that process template and produce pure html.

Thymeleaf is way better in my opinion because it have good underlying priciples and exploits natural behaviour of browsers.

Jsp makes html hard to read, it becomes weird mixture of html and java code which makes a lot of problems in comunication between designer - developer.

Thymeleaf preserves html and only adds tags that are intuitive and very expressive. It enables you to work in offline mode and it works great with spring and I definitely recommend it above jsp.

http://www.dineshonjava.com/2015/01/thymeleaf-vs-jsp-spring-mvc-view-layer.html?m=1

6
  • 16
    Incorrect answer and based on personal opinion. 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. It's easy to create unreadable code in Thymeleaf if you put a bunch of logic in it. That goes off too. And not to mention it's one of the slowest template engines. Therefore, the SO has a strict rule to close questions that may produce answers based on personal opinion and experience. Dec 7, 2016 at 14:19
  • 2
    I accept your critic about jsp, it's true, as well as speed of thymeleaf engine. But how can I give answer that isn't based on personal opinion and expirience ?
    – Zildyan
    Dec 7, 2016 at 14:25
  • Still I stand behind my points that it's better especially for iterative development in cooperation with designers
    – Zildyan
    Dec 7, 2016 at 14:32
  • @Zildyan Thank you for answer. Dec 8, 2016 at 7:59
  • @Zildyan Designers never do HTML. So, the point is irrelevant. Dec 23, 2017 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.