Struts フレームワークは、MVC スタイルのアプリケーションにコントローラー・コンポーネントを提供します。
コントローラーは、org.apache.struts.action.ActionServlet.class と呼ばれるサーブレットです。
アプリケーションの web.xml ファイルで、この Struts ActionServlet サーブレット用に
*.do のサーブレット・マッピングが追加されるため、
.do で終わる Web アドレスのすべての要求が処理されます。ActionServlet サーブレットは、
struts-config.xml ファイル内の情報を使用して、どの
Struts アクション・クラスが指定されたリソースの要求を実行するかを決定します。
前のバージョンの WebSphere Application Server を使用するキャッシュ・ポリシー
前のバージョンの
WebSphere Application Server では、サーブレットごとに 1 つのキャッシュ・ポリシーのみが
サポートされていました。ただし、Struts を使用している場合、
.do で終わるすべての要求は同じ ActionServlet サーブレットにマップします。
Struts 応答をキャッシュするには、サーブレット・パスに基づいて、ActionServlet サーブレットの
キャッシュ・ポリシーを書き込みます。
例えば、
/HelloParam.do と
/HelloAttr.do という 2 つの Struts アクションを考慮します。
ID 要求パラメーターおよび arg 要求属性に基づいてそれぞれ応答をキャッシュするには、
以下のキャッシュ・ポリシーを使用します。
<cache-entry>
<class>servlet</class>
<name>org.apache.struts.action.ActionServlet.class</name>
<cache-id>
<component id="" type="servletpath">
<value>/HelloParm.do</value>
</component>
</cache-id>
<cache-id>
<component id="" type="servletpath">
<value>/HelloAttr.do</value>
</component>
<component id="arg" type="attribute">
<required>true</required>
</component>
</cache-id>
</cache-entry>
WebSphere Application
Server バージョン 6.0 以降を使用したキャッシュ・ポリシー
現行バージョンの WebSphere
Application Server を使用して、単一サーブレットに対して複数のキャッシュ・ポリシーをマップすることができます。
以下の例に示すように、前のキャッシュ・ポリシーを書き直すことができます。
<cache-entry>
<class>servlet>
<name>/HelloParam.do</name>
<cache-id>
<component id="id" type="parameter">
<required>true</required>
</component>
</cache-entry><cache-entry>
<class>servlet</class>
<name>/HelloAttr.do</name>
<cache-id>
<component id="arg" type="attribute">
<required>true</required>
</component>
</cache-id>
</cache-entry>
Tiles フレームワークは jsp:include タグ上にビルドされているため、
JSP キャッシングに適用されることはすべて Tiles にも適用されます。フラグメントが適切にキャッシュされるように、
tiles:insert タグを使用して含まれるフラグメントで、フラッシュ属性を true に設定する必要があります。
JSP キャッシングでの tiles キャッシングの追加フィーチャーは、
tiles 属性に基づいています。例えば、以下のような
layout.jsp テンプレートを作成できます。<html>
<%String categoryId = request.getParameter("categoryId")+"test"; %>
<tiles:insert attribute="header">
<tiles:put name="categoryId" value="<%= categoryId %>" />
</tile:insert>
<table>
<tr>
<td width="70%" valign="top"><tiles:insert attribute="body" /> </td>
</tr>
<tr>
<td colspan="2"><tiles:insert attribute="footer" /></td>
</tr>
</table>
</body>
</html>
ネストされた tiles:put タグは、挿入されるタイルの属性を指定します。
layout.jsp テンプレートで、categoryId 属性が定義され、
ヘッダーのプレースホルダーに挿入されるタイルに渡されます。
次の例で、layout.jsp ファイルは別の
JSP ファイルに挿入されます。<html>
<body>
<tiles:insert page="layout.jsp?categoryId=1002" flush="true">
<tiles:put name="header" value="/header.jsp" />
<tiles:put name="body" value="/body.jsp" />
<tiles:put name="footer" value="/footer.jsp" />
</tiles:insert>
</body>
</html>
categoryId タイル属性は、header.jsp ファイルに渡されます。
header.jsp ファイルは、<tiles:useAttribute> タグを使用して、
categoryId の値を取得することができます。categoryId 属性の値に基づいて header.jsp ファイルをキャッシュするには、
以下のキャッシュ・ポリシーを使用することができます。<cache-entry>
<class>servlet</class>
<name>/header.jsp</name>
<cache-id>
<component id="categoryId" type="tiles_attribute">
<required>true</required>
</component>
</cache-id>
</cache-entry>