Spring (as well as Struts, Apache Wicket and other frameworks) is based on servlets. When you're using Spring for web, you're using servlet as an underlying technology. JSP is really a little bit outdated. And there are some inconveniences in it. For example, JSP is a real headache for web designers. Designers cannot just open a JSP file, make some changes, and check the result in the browser, because the JSP file contains tags that are invalid for HTML. The only way to see how the page will look like in the browser is to deploy the application and let the server render it. Another inconvenience in JSP is that you can't externalize common layout into a dedicated file. All you can do is import one page into another with <jsp:include> . And if you have hundreds of files, you have to repeat the same <jsp:include> in all of them to copy common parts. There are template engines that are more suitable for big projects when you have hundreds of complex dynamical pages. One popular template engine is Thymeleaf . Thymeleaf's templates contain just valid HTML. That means designers and programmers can work in parallel. Also it has a good layout system. Moreover, Thymeleaf has much more readable and elegant syntax in contrast to JSP. Here is an example of the code for generating a simple table in Thymeleaf:
There are many other additional features like build-in support of internationalization, passing parameters to fragments and so on. You can find more details on the comparison of Thymeleaf and JSP here and here .
1条答案
按热度按时间0x6upsns1#
Spring (as well as Struts, Apache Wicket and other frameworks) is based on servlets. When you're using Spring for web, you're using servlet as an underlying technology.
JSP is really a little bit outdated. And there are some inconveniences in it. For example, JSP is a real headache for web designers. Designers cannot just open a JSP file, make some changes, and check the result in the browser, because the JSP file contains tags that are invalid for HTML. The only way to see how the page will look like in the browser is to deploy the application and let the server render it.
Another inconvenience in JSP is that you can't externalize common layout into a dedicated file. All you can do is import one page into another with
<jsp:include>
. And if you have hundreds of files, you have to repeat the same<jsp:include>
in all of them to copy common parts.There are template engines that are more suitable for big projects when you have hundreds of complex dynamical pages. One popular template engine is Thymeleaf .
Thymeleaf's templates contain just valid HTML. That means designers and programmers can work in parallel. Also it has a good layout system. Moreover, Thymeleaf has much more readable and elegant syntax in contrast to JSP. Here is an example of the code for generating a simple table in Thymeleaf:
There are many other additional features like build-in support of internationalization, passing parameters to fragments and so on.
You can find more details on the comparison of Thymeleaf and JSP here and here .