Java 中的安全模板引擎有哪些?
我正在寻找一个 Java 模板引擎,它不允许在模板中执行代码,仅在标签中执行。
在完美的世界中,我会寻找与 Jinja2 (或 Django 模板引擎)。 基于Django,我创建时会使用模板标签,但用户无法创建模板标签(通过执行代码)。
我会在 Play 中实现它!框架。
感谢您的帮助!
I'm looking for a template engine in Java that disallow code execution in template, only tags.
In a perfect world, I would be searching for an equivalent to Jinja2 (or the Django template engine).
Based on Django, template tags will be used when created by me, but a user can't create a template tag (by executing code).
I would implement it in the Play! Framework.
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
StringTemplate 就是您要寻找的。
StringTemplate is what you are looking for.
从您的要求来看,您所需要的似乎只是一个模板引擎,它不允许任何类似于 JSP 的 scriptlet(在 <% 和 %> 之间)的内容,并且仅基于标签和/或属性......
如果是这样,我想向您推荐 Thymeleaf http://www.thymeleaf.org (这里是 与 JSP 的比较),我是其中的作者。但如果我没记错的话,这些要求也可以通过 Velocity http://velocity.apache.org,所以由你来选择!
From your requirements, it looks as if all you required was a template engine that didn't allow anything similar to JSP's scriptlets (between <% and %>) and was only based in tags and/or attributes...
If so, I'd like to suggest you Thymeleaf http://www.thymeleaf.org (here a comparison with JSP), of which I'm the author. But if I'm not wrong these are requirements that could also be fulfilled by Velocity http://velocity.apache.org, so its up to yo to choose!
如果您想提供一种简单的方法来修改模板,而无需了解数百个自定义标签并实现要访问的明确定义的功能,同时可以自由地如何呈现它,那么您应该考虑被动模板。这确保了不会添加恶意代码:) Java 中具有被动模板的强大引擎是 Snippetory。但是,如果您想控制访问,访问控制可能也是一个好主意。
If you want to provide a simple way to modify they templates without much learning about hundreds of custom tags and achieve a clearly defined functionality to be accessed, while being free how to present it, you should think about passive templates. This ensures, no malicious code can be added:) A strong engine with passive templates in java is Snippetory. However if you want to control access, access control might be a good idea, too.