struts2 + tiles2 配置(备忘)

struts 2.0.11  + tiles 2.04 配置(备忘),版本号可以是struts 2.0.x.x  + tiles 2.0.x

 

1 web.xml配置,加入

<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>

 

2 struts.xml 配置。例子:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
	"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
	<package name="system" extends="tiles-default">
    	<action name="LoginAction" class="com.shdv.cms.system.controler.LoginAction">
			<result name="success" type="tiles">base.definition</result> 
			<result name="input" >/login.jsp</result>
    	</action>
	</package>
</struts>

 

3 新增布局定义文件,WEB-INF/tiles.xml。例子:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "http://struts.apache.org/dtds/tiles-config_2_0.dtd"> 
<tiles-definitions> 
    <definition name="base.definition" template="/template.jsp">
        <put-attribute name="title"  value="当前客户起始页面"/>
        <put-attribute name="banner"  value="/top.jsp"/>
        <put-attribute name="menu"  value="/menu.jsp"/>
        <put-attribute name="sidebar"  value="/sidebar.jsp"/>
        <put-attribute name="hintbar"  value="/error.jsp"/>
        <put-attribute name="body"  value="/body.jsp"/>
	</definition>
  	
	<definition name="index.definition" extends="base.definition"> 
		<put-attribute name="body" value="/index.jsp"/> 
	</definition>
	
</tiles-definitions> 

 

4 新增TLD文件,WEB-INF/tiles-jsp.tld。在tiles-jsp-2.0.4.jar包中。

 

5 模板template.jsp文件。例子

<%@ page contentType="text/html;charset=GBK"%>
<%@ taglib uri="WEB-INF/tiles-jsp.tld" prefix="tiles" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<html>
<head>
<title><tiles:insertAttribute name="title"/></title>
</head>

<body leftmargin="0" topmargin="0" background="" >

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <tiles:insertAttribute name="banner"/>
  </tr>
</table>   

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top" width="180" height="23"> 
	<tiles:insertAttribute name="menu"/>
    </td> 
  </tr>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top" width="180" > 
      <tiles:insertAttribute name="sidebar"/>
    </td> 
    <td valign="top" width="819" align="left">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr>
        <td height="20"></td>  
        </tr>
        <tr>
        <td valign="top">
          <tiles:insertAttribute name="hintbar"/>
        </td>  
        </tr>
        <tr>
        <td valign="top" align="center" style="word-break:break-all">
          <tiles:insertAttribute name="body"/>
        </td> 
        </tr>
      </table>  
    </td>
    <td></td> 
  </tr>
     
</table>
    
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    
  </tr>
</table>  

</body>
</html>

 

 

注明:需要struts 2.0.11包,tiles包,commons-digester-1.8.jar

你可能感兴趣的:(apache,jsp,Web,xml,struts)