Answer the question
In order to leave comments, you need to log in
Freemarker: what are your opinions?
We are faced with the choice of a template engine. There are people recommending freemarker. I had experience with him and I didn’t really like him because of his small similarity to xml and non-obvious syntactic sugar.
Can anyone point out the obvious cons/pros compared to jsp/taglibs?
Answer the question
In order to leave comments, you need to log in
We worked with a freemarker. He solved all our problems that arose. However, that was 3-4 years ago.
The freemarker could be used outside of the servlet container. JSP 3-4 years ago looked more cumbersome.
The advantage of the freemarker is that it is easier to write a tag library and use closures (functions and macros) in some form.
Grails did not look? grails.org/doc/latest/guide/theWebLayer.html#viewsAndTemplates
The last time I worked with JSP versions 2.0, so maybe I missed some important things from JPS2.1 / 2.2 - I only dealt with them briefly. But in general, so that absolutely radically like nothing has changed.
JSP problems:
1. Spaghetti code
Scriptlets = guaranteed spaghetti code. It is often impossible to do without them.
2. Cumbersome Syntax
For example, if/then/else in JSP is usually written in JSTL c:choose/c:when/c:otherwise. It's very verbose and cumbersome.
3. Problematic creation of reusable code It is possible to declare
methods directly in a JSP page, but you cannot call them from another JSP page. Writing taglibs in 2.0 was a separate complex task that can not be compared with writing a macro in Velocity, where this is an elementary task.
Maybe JSP2.1 .tag files solve this, I don't know.
4. Tie to request/response and all sorts of contexts.
What is the problem? For example, you have a JSP page that is used as a template for rendering a report on the execution of some task. As long as this is done by clicking the button in the browser by the user, everything is fine.
But now the task arose to execute the same task regularly using the scheduler, and send the same report to the user by email. What to do? There will be no problems with Velocity / Freemarker / Jelly - the same template will be reused.
JSP will have to redo everything.
5. Complexities of the specification - JSP2.2 appeared already in 2009, and added method calls with arguments to EL - what was 100500 years ago in templating environments.
I was agitated here that method calls with arguments are a sign of bad design, but I strongly disagree.
But a sign of what design is the presence of SQL tags in JSTL, for example? Obviously not good.
More here:
stackoverflow.com/questions/4812755/difference-between-jsp-el-jsf-el-and-unified-el
adamgent.com/post/6091183966/jsp-el-2-1-versus-el-2- 2
As for me, jsp with includes + tiles is the best. I tried both Freemaker and Velocity - it’s not that ... I won’t point out obvious disadvantages, but after using the latter, there was a sediment. And ideally, I would like something like Django templates - but nothing like this could be found for java.
I didn't like the messages it generates in the freemarker when there are errors in the template, and I didn't like the IDE support. And the syntax is somehow complicated, although this is probably because I did not communicate with it for a long time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question