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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值