Spring的基于JSP的模板化 [英] JSP-based Templating with Spring

查看:80
本文介绍了Spring的基于JSP的模板化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Spring的MVC与JSP视图一起使用.每个JSP页面都有类似的结构-页眉,内容,页脚,也许还有侧边栏等.人们在寻找最佳做法"时似乎会包含"页脚和页眉,但这意味着每个JSP页面都包含这些"include"语句,给出固定格式.在我看来,更好的解决方案将涉及嵌套视图,在该视图中扩展了基本模板,并提供了适合所讨论页面的信息.这种方法的优点之一是,您可以在基本模板中采用默认值,而无需在其他地方重复这些默认值.另一个优点是,您可以在包含大量文本的页面(例如帮助页面)中进一步分离结构和内容("header"和"footer"是结构性的,因此属于基本模板)数据库,但是为什么要打扰呢,特别是因为使用Spring可以通过语言环境解析为不同的视图?).

I'm using Spring's MVC with JSP views. Every JSP page has similar structure - headers, content, footers, perhaps a sidebar, etc. Looking around for "best practices" people seem to "include" footers and headers, but that means that every JSP page includes these "include" statements, giving a fixed format. To my eye a better solution would involve nested views, where a base template is extended with information appropriate to the page in question. One advantage of this approach is that you can have default values assumed in the base template without repeating them elsewhere. Another advantage is that you can further separate structure and content ("header" and "footer" being structural, and so belonging in the base template) in pages which contain a lot of text (think of help pages - you could put all that in the database, but why bother, especially since with Spring you can resolve to different views via the locale?).

Spring在MVC级别似乎对此没有任何支持,但是可以使用自定义标签在JSP中实现它,并且确实有一个笨拙的尝试

There doesn't seem to be any support for this at the MVC level in Spring, but it could be implemented in JSP using custom tags and, indeed, there's a rather clunky attempt here (that might explain what I want better than this question, although I think you could make it less intrusive).

无论如何,我的问题是-它已经作为(流行/标准)标签库存在了吗?我很高兴编写自定义标签,但是我对这些东西(生成网站)的印象是,已经有各种各样的解决方案,大多数工作都在选择正确的工具(例如Spring)上.谢谢.

Anyway, my question is - does this already exist as a (popular/standard) tag library? I'm happy writing custom tags, but my impression of this stuff (generating web sites) is that there's a huge range of solutions already out there, with most work going into choosing the correct tools (eg Spring). Thanks.

推荐答案

我建议 SiteMesh .在Spring上很好用.

I'd recommend SiteMesh. It works well with Spring.

这篇关于Spring的基于JSP的模板化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆