1

Sitemeshの使い方を教えてもらえますか?レイアウトページとヘッダーとフッターを作成しました。ヘッダーとフッターは、静的<%@include>として別々のページからインクルードされます。ここで、ヘッダーとフッターを同じに保ちながら、中央部分の「コンテンツ」を変更する必要があります。struts.xmlはどのようになり、子ページを含めるためのレイアウトのコンテンツはどうなりますか。サイト全体が同じインターフェイスになるように、ページ内のアクションやその他のリンクはどのようになりますか。

4

1 に答える 1

1

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.

于 2011-05-23T17:03:14.067 に答える