将 sitemesh 与 struts2 结合使用
谁能告诉我如何使用 Sitemesh。我创建了一个布局页面以及页眉和页脚。页眉和页脚以静态 <%@include > 的形式包含在单独的页面中。现在我希望中间部分的“内容”发生变化,保持页眉和页脚相同。 struts.xml 应该如何以及布局的内容是什么以包含子页面。页面中的操作和其他链接将如何以使整个站点具有相同的界面。
Can anyone tell me how to use Sitemesh. I have created a layout page and header and footer. Header and Footer are included from separate pages as static <%@include >. Now I want the middle part "content" to vary keeping header and footer same. How should be the struts.xml and what will be the contents of Layout to include child pages. How will the actions and other links in the pages be so as to have the entire site with same interface.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个最小的例子。 http://www.benmccann.com/blog/sitemesh-tutorial-with-示例/
在 sitemesh 的哲学中,遵循“装饰器”模式,您的“原始”(未装饰)视图应该不知道它将被“装饰”(此处, “装饰”可以意味着“在 head 中添加一些常见的样式,在 body 中添加一些常见的菜单 div...”)。这种极端的解耦正是 Sitemesh 的美妙之处。
更具体地说,您的 Struts2 视图代码(在您的例子中,输出每个操作结果的 JSP)应该只是一个完整的 html 页面(
...< ;body>...
,但如果没有这些“常见”元素,Sitemesh 将捕获原始 HTML 页面并添加常见片段。由“装饰器”指定(您可以有多个),在您的情况下,它可能是一个 jsp 页面(如示例中所示),并且它本身可能有一些 jsp
<%@include >里面。
Here's a minimal example. http://www.benmccann.com/blog/sitemesh-tutorial-with-examples/
In the philosophy of sitemesh, following the 'decorator' pattern, your 'raw' (undecorated) view should be unaware that it's going to be 'decorated' (here, to be 'decorated' can mean 'to be added some common styles in the head, and some common menu div in the body...'). This extreme decoupling is the beauty of Sitemesh.
More specifically, your Struts2 views code (in your case, the JSP that outputs the result of each action) should be just a full html page (
<html><head>...</head><body>...</body></html>
, but without those 'common' elements.Sitemesh will catch the raw HTML pages and add the common fragments. This is specified by a 'decorator' (you can have more than one), in your case it would probably be a jsp page (as in the example) and it might itself have some jsp
<%@include >
inside.