简体   繁体   English

是否有一个基于Java的Web模板引擎之类的JSP,可以从持久性存储中加载页面模板?

[英]Is there a JSP like Java based Web template engine that can load page templates from persistent storage?

I would like to provide users to write plugins to my application, the initial design and implementaion involve a Velocity (VTL) template engine to allow 我想为用户提供向我的应用程序编写插件的方法,初始设计和实现涉及Velocity (VTL)模板引擎,以允许

  • Secure : uesrs can't call internall Java code (without hacking using reflection) 安全 :用户无法调用内部Java代码(无需使用反射进行黑客攻击)
  • Simple : Limited and confined API, I can write my own domain specific language 简单 :有限且受限的API,我可以编写自己的域特定语言
  • Portable : I can store VTL templates in a JAR, in the database or anywhere I like 可移植性 :我可以将VTL模板存储在JAR,数据库或任何我喜欢的位置
  • Decoupled : template context and logic / controller is not coupled to the web / HTML 解耦 :模板上下文和逻辑/控制器未耦合到Web / HTML

Then with the limitations of VTL (no tag library support as first) we looked at Freemarker 然后,由于VTL的局限性 (首先不支持标签库),我们研究了Freemarker

It has all the advantages, but I wonder if this is as good as it gets 它具有所有优点,但是我想知道它是否还好

The other alternatives are eclipse JET, and I don't know of anything else at the moment 其他选择是Eclipse JET,目前我还不知道

I would like a solution that can have Java content assist (like JSP) but that can be saved in the database 我想要一个可以支持Java内容 (例如JSP)但可以保存在数据库中的解决方案

Is there something like this out there? 那里有这样的东西吗? (Besides JET, and JBoss's Freemarker buggy plugin) (除了JET和JBoss的Freemarker越野车插件)

Check out Thymeleaf . 看看Thymeleaf

I haven't used it.. YET! 我还没有用过。

It appears the developer designed it to address the shortcomings of Velocity and FreeMaker. 似乎开发人员设计了它来解决Velocity和FreeMaker的缺点。

I have successfully used FreeMarker on several projects. 我已经在几个项目上成功使用了FreeMarker。

To address your concerns: 要解决您的问题:

  • Processing a template - even one written by a user - is secure if you don't expose any unsafe method in your model. 如果您在模型中没有暴露任何不安全的方法, 处理模板(甚至是用户编写的模板)都是安全的。 In general, the model should only contain immutable objects (eg Strings, numbers) and collections of those (eg List, Map), and not be related in any way to the control layer of your MVC application. 通常,模型应仅包含不可变的对象(例如,字符串,数字)和这些对象的集合(例如,列表,映射),并且不以任何方式与MVC应用程序的控制层相关。
  • FreeMarker is simple enough for programmers, but not necessarily for web designers or editors. FreeMarker对程序员来说足够简单,但对网页设计师或编辑者则不一定。
  • FreeMarker templates can be stored anywhere you like, since the template loader can be anything you can imagine. FreeMarker模板可以存储在您喜欢的任何位置,因为模板加载器可以是您可以想象的任何东西。 Have a look at the API documentation. 看一下API文档。
  • FreeMarker templates are confined to the view layer of your MVC application, as long as you don't publish any sensible method in your model (see first point). FreeMarker模板仅限于MVC应用程序的视图层, 只要您不在模型中发布任何明智的方法即可 (请参见第一点)。 Unlike JSP, they are completely unaware of the Servlet API. 与JSP不同,它们完全不了解Servlet API。

As for content assist, most major IDE's (IntelliJ, Eclipse, probably NetBeans) have support for the FreeMarker syntax and should provide auto-completion for the keywords. 至于内容辅助,大多数主要的IDE(IntelliJ,Eclipse,可能是NetBeans)都支持FreeMarker语法,并应为关键字提供自动完成功能。 If you want a JavaScript-based editor for FreeMarker, I'm not as affirmative since I know of none. 如果您想要FreeMarker的基于JavaScript的编辑器,那么我就不那么肯定了,因为我什至没有。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM