开发者

using sitemesh with struts2

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 a开发者_如何转开发ctions and other links in the pages be so as to have the entire site with same interface.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜