Why would I use a templating engine? jsp include and jstl vs tiles, freemarker, velocity, sitemesh

后端 未结 7 1419
慢半拍i
慢半拍i 2020-12-12 10:31

I\'m about to choose to way to organize my view (with spring-mvc, but that shouldn\'t matter much)

There are 6 options as far as I see (though they are not mutually

相关标签:
7条回答
  • 2020-12-12 11:01

    I realize that this comes off as a smart ass answer, but the truth of it is, if you don't see any advantage to using templating over code in your current project, it's probably because in your current project, there isn't one.

    Part of it is about scale. You might think that includes are every bit as powerful as let's say sitemesh, and that's certainly true, at least for a small number of pages (I'd say probably about 100), but if you have several thousands it starts becoming unmanageable. (So for eBay it's not necessary, for Salesforce it probably is)

    Also, as has been mentioned before, freemarker and velocity are not servlet specific. you can use them for anything (mail templates, offline documentation, etc.). You do not need a Servlet container to use freemarker or velocity.

    Lastly your point 5 is only partially true. It is compiled every time it is accessed if it has not been so already. This mean that whenever you change something you need to remember to delete your servlet containers "work" directory, so that it recompiles the JSP. This is unnecessary with a templating engine.

    TL;DR Templaing engines were written to address some (perceived or real) shortcomings of JSP + JSTL. Whether you should use them or not depends entirely on your requirements and the scale of your project.

    0 讨论(0)
提交回复
热议问题