Struts1 tiles施用示例
Struts1 tiles应用示例
前提物质条件: 1.Struts Framework; 2.struts-tiles.tld
一. web.xml配置
<servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-confg.xml</param-value> </init-param> <init-param> <param-name>definitions-config</param-name> <param-value>/WEB-INF/tiles-defs.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> ... <taglib> <taglib-uri>/tags/struts-tiles</taglib-uri> <taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location> </taglib>
二. struts-confg.xml配置
<plug-in className="org.apache.struts.tiles.TilesPlugin"> <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"/> </plug-in>
三. tiles-defs.xml内容
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd"> <tiles-definitions> <definition name="site.mainLayout" path="/mainlayout.jsp"> <put name="header" value="/header.html"/> <put name="body" value="/logon.jsp"/> <put name="footer" value="/footer.html"/> </definition> </tiles-definitions>
四. mainlayout.jsp内容
<%@ page contentType="text/html; charset=UTF-8"%> <%@ taglib uri="/tags/struts-tiles" prefix="tiles" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>tiles</title> </head> <body> <tiles:insert attribute="header" /> <tiles:insert attribute="body" /> <tiles:insert attribute="footer" /> </body> </html>
五.tiles的调用
index.jsp内容
index.jsp内容
<%@ page contentType="text/html; charset=UTF-8"%> <%@ taglib uri="/tags/struts-tiles" prefix="tiles" %> <tiles:insert definition="site.mainLayout" flush="true" />或者(无需tiles-defs.xml)
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %> <tiles:insert template="mainlayout.jsp"> <tiles:put name="title" value="This is the title." /> <tiles:put name="header" value="header.jsp" /> <tiles:put name="body" value="body.jsp" /> </tiles:insert>调用index.jsp时就会引用mainlayout.jsp来显示。
本文出自 “Java学习博客” 博客,请务必保留此出处http://icansoft.blog.51cto.com/268543/118611