Struts2にtilesを設定する方法

1.JARファイル
(1) tiles-core-version.jar
(2) tiles-api-version.jar
(3) tiles-jsp-version.jar
(4) Jakarta common BeanUtiles
(5) Jakarta common Logging
(6) Jakarta common Digester
(7) Struts2-tiles-plugin-version.jsp

2. tiles Listenerの初期化
/WEB-INF/web.xml
<context-param>
<param-name>
org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
</param-name>
<param-value>
/WEB-INF/tiles-defs.xml,/org/apache/tiles/classpath-defs.xml
</param-value>
</context-param>

3. tilesリスナーの設定
<listener>
<listener-class>org.apache.tiles.web.startup.TilesListener</listener-class>
</listener>

4. tiles-defs.xmlの設定
<?xml version="1.0″ encoding="UTF-8″ ?>
<!DOCTYPE tiles-definitions PUBLIC
“-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
“http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name=".base" template="/layout/layout.jsp">
<put-attribute name="top" value="/include/top.jsp" />
<put-attribute name="left" value="/include/left.jsp" />
<put-attribute name="bottom" value="/include/bottom.jsp" />
</definition>

<definition name=".main_page" extends=".base">
<put-attribute name="body" value="/main/main.jsp"></put-attribute>
</definition>

<definition name=".student_main_page" extends=".base">
<put-attribute name="body" value="/student/main.jsp"></put-attribute>
</definition>
<definition name=".student_add_page" extends=".base">
<put-attribute name="body" value="/student/add.jsp"></put-attribute>
</definition>
<definition name=".product_main_page" extends=".base">
<put-attribute name="body" value="/product/main.jsp"></put-attribute>
</definition>
<definition name=".product_add_page" extends=".base">
<put-attribute name="body" value="/product/add.jsp"></put-attribute>
</definition>
<definition name=".product_modify_page" extends=".base">
<put-attribute name="body" value="/product/modify.jsp"></put-attribute>
</definition>
<definition name=".product_delete_page" extends=".base">
<put-attribute name="body" value="/product/delete.jsp"></put-attribute>
</definition>
<definition name=".product_view_page" extends=".base">
<put-attribute name="body" value="/product/view.jsp"></put-attribute>
</definition>

</tiles-definitions>

5.テンプレートファイル /layout/layout.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8″
pageEncoding="UTF-8″%>
<%@taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN" “http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8″>
<title>Insert title here</title>
</head>
<body>
<table border="1″ width="100%">
<tr>
<td><tiles:insertAttribute name="top"></tiles:insertAttribute> </td>
</tr>
</table>
<table border="1″ width="100%">
<tr>
<td width="20%"><tiles:insertAttribute name="left"></tiles:insertAttribute> </td>
<td width="80%"><tiles:insertAttribute name="body"></tiles:insertAttribute> </td>
</tr>
</table>
<table border="1″ width="100%">
<tr>
<td><tiles:insertAttribute name="bottom"></tiles:insertAttribute> </td>
</tr>
</table>

</body>
</html>

6.tilesファイルの設定
<package name="main_info" namespace="/main" extends="tiles-default" >
<action name="fzMain" class="main_page_action" method="fzMain">
<result name="fzMain" type="tiles">.main_page</result>
</action>
</package>

Java

Posted by arkgame