开发者

JSP vs FreeMarker [closed]

开发者 https://www.devze.com 2023-02-22 02:38 出处:网络
As it currently stands, this question is not a good fit for our Q&开发者_StackOverflow中文版A format. We expect answers to be supported by facts, references,or expertise, but this question wil
As it currently stands, this question is not a good fit for our Q&开发者_StackOverflow中文版A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 9 years ago.

Does JSP provide more flexibility then FreeMarker or is it other way around? My back-end involves Servlets. Which one is used under what circumstances?


JSP is going to let you do more things in the view layer, so you might say that makes it more flexible. Things you probably shouldn't be doing though, which one could argue as a benefit for FreeMarker. It would afford you more control over what the view layer can do and force a better separation of concerns.

There's not really any right answer here. You can technically accomplish just about anything with either for your UI. Without more details about your project it's hard to make a recommendation. About the only thing I can say is that you should probably use the MVC pattern. It can be accomplished with either.


My answer would be definitely to go with Freemarker. Reason is flexibility in a term of usage.

  1. It does not require servlet container, so you can also render e-mails or anything text based.

  2. In a web application it makes possible to create web-modules as jar. Freemarker templates can easily be loaded from classpath (also, spring makes possible to load css/js - static content - from classpath with mvc:resources tag and scan for controllers). So a web module can contain its own templates, static data and controllers.

  3. Freemarker is more powerful in terms of creating custom tags, jsp makes it just a pain. Also, custom tags allow calling back to body parameterized which you will not really be able to do in JSP very easily.

  4. From Freemarker you can still use every JSP tag library available without problem :)


There are several libraries that have been around JSP like JSTL, DisplayTag, etc. that you can use if you choose to go with JSP. With Freemarker, there are not as many of them.

JSP is tailor made for Web pages, FTL is a more generic templating language - it can be used to generate html, plain text, emails, etc.

To pick one, you must consider what kind of tools you have. All good Java IDEs have excellent JSP support. FTL support may/may not be as good.


I believe that you already went for one or the other option by now. Anyway, comment might still be useful for others. As WhiteFang wrote, using MVC is the only highly recommended suggestion.

If your application is a web based one, JSP would most likely be a better option as it is better known and one can write quite clean presentation code using JSTL (just make sure you don't mix in scriptlets ... all data should be prepared in servlets and passed on to JSPs as attributes). Choosing JSP you bring value to the project by enabling managers to plug-in easily other developers when needed to deliver faster etc.

Anyway, since you already have it on FreeMarker, if the template looks ok already, I wouldn't change it. Rather wait for when you have a business reason to switch. Whatever well designed an application might be, it will eventually need to be partially or even fully rearchitected. As long as you do modular programming, and keep your transformation in an isolated module, you will be able at any time to easily switch to whatever technology you'll see fit (potentially a new one, better than FreeMarker or JSP :) ).

I am usually using FreeMarker for non web applications. Or even in web applications, when I need to generate notification emails for example, which don't need to be web enabled. Otherwise JSP works great so far.

Stef.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号