
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %> <%@ page contentType="text/html; charset=UTF-8" %> <!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> <tiles:getAsString name="title"/> </title> </head> <body> <table border="1" cellpadding="2" cellspacing="2" align="center"> <tr> <td height="30" colspan="2"> <tiles:insertAttribute name="header"/> </td> </tr> <tr> <td height="350"> <tiles:insertAttribute name="body"/> </td> <td width="250"> <tiles:insertAttribute name="menu"/> </td> </tr> <tr> <td height="30" colspan="2"> <tiles:insertAttribute name="footer"/> </td> </tr> </table> </body> </html> |
1 |
<h4>Header</h4> |
1 2 3 4 5 6 7 8 |
<%@ taglib prefix="s" uri="/struts-tags" %> <h4>Menu</h4> <ul> <li><a href="<s:url action="LayoutSatu"/>">Template Satu</a></li> <li><a href="<s:url action="LayoutDua"/>">Template Dua</a></li> <li><a href="<s:url action="LayoutTiga"/>">Template Tiga</a></li> </ul> |
1 |
<h4>Body</h4> |
1 |
<h4>Footer</h4> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name>Belajar Struts2</display-name> <listener> <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class> </listener> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>jspSupportServlet</servlet-name> <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class> <load-on-startup>5</load-on-startup> </servlet> <welcome-file-list> <welcome-file>/index.html</welcome-file> </welcome-file-list> </web-app> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://localhost:8080/tiles-struts2/dtds/tiles-config_3_0.dtd"> <tiles-definitions> <definition name="layoutSatu" template="/layout/LayoutSatu.jsp"> <put-attribute name="title" value="Template Satu" cascade="true"/> <put-attribute name="header" value="/pages/Header.jsp"/> <put-attribute name="menu" value="/pages/Menu.jsp"/> <put-attribute name="body" value="/pages/Body.jsp"/> <put-attribute name="footer" value="/pages/Footer.jsp"/> </definition> <definition name="layoutDua" template="/layout/LayoutDua.jsp"> <put-attribute name="title" value="Template Dua" cascade="true"/> <put-attribute name="header" value="/pages/Header.jsp"/> <put-attribute name="menu" value="/pages/Menu.jsp"/> <put-attribute name="body" value="/pages/Body.jsp"/> <put-attribute name="footer" value="/pages/Footer.jsp"/> </definition> <definition name="layoutTiga" template="/layout/LayoutTiga.jsp"> <put-attribute name="title" value="Template Tiga" cascade="true"/> <put-attribute name="header" value="/pages/Header.jsp"/> <put-attribute name="menu" value="/pages/Menu.jsp"/> <put-attribute name="body" value="/pages/Body.jsp"/> <put-attribute name="footer" value="/pages/Footer.jsp"/> </definition> </tiles-definitions> |
*catatan url “http://localhost:8080/tiles-struts2/dtds/tiles-config_3_0.dtd” bisa diganti “http://tiles.apache.org/dtds/tiles-config_3_0.dtd” dengan catatan harus ada koneksi ke internet.
Selamat mencoba,
salam berbagi,
wijaksana