如何在应用程序中构建可重用的 JSP 片段
我想为我正在构建的应用程序构建可重用的 JSP 组件。有多种方法可以解决这个问题。我所知道的包括构建 JSPFragments,然后将页面缝合在一起。但这并不是一种优雅的做法。
我还尝试了解 JSP 标记库,以便能够为 JSP 构建可重用的组件。我在多个地方读到标签库正在迅速失宠。还有其他框架,例如 JSF 和 Freemarker 模板,我可以通过它们构建可重用的组件。我用什么来构建这些组件。有我可以遵循的首选且现代的方法吗?
I want to build reusable JSP components for an application that I am building. There are multiple ways to go around this. The ones that I know of include building JSPFragments and then stitching the page the together. But that is not an elegant way of doing it.
I am also trying to get mt head around JSP tag libraries to be able to build reusable components for JSP. I read in multiple places that tag libraries are falling out of favour fast. There are other frameworks like JSF and Freemarker templates by which I can build re-usable components. What do I use to build these components. Is there a preferred and contemporary approach I can follow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定这是否能解决您的问题。但无论如何,我开始使用FreeMarker,这是一个非常好的模板引擎。它严格遵循 MVC 原则。这些功能可能会帮助您确定 FreeMarker 是否适合您的需求:
请注意,FreeMarker 只是一个模板引擎。您不能像 jsp 那样将 java 代码包含到 html 中。
I am not sure if this solve your problem. But anyway, I started to use FreeMarker, which is a really good template engine. It follows strict the MVC principal. These feature might help you to decide whether FreeMarker is good for your needs:
Note that FreeMarker is just a template engine. You can not include java code into html like with jsp.
如果组件很简单,您可以使用 .tag 文件。它们很容易写。如果比较复杂,可以使用标签库。这是一个多次使用的可行解决方案。
If the component is simple you can use .tag files. They are easy to write. If it is more complex, use a tag library. It is a working solution used many times.