tiles3 + struts2 + spring3配置

1.tiles注入

1.1 采用struts注入,web.xml 配置

<listener>
     <listener-class>
          org.apache.tiles.extras.complete.CompleteAutoloadTilesListener
     </listener-class>
</listener>
        不需要关联tiles-defs.xml文件,从tiles源代码可以看出,只有放在具体的目录下就行:
Collection<ApplicationResource> webINFSet = applicationContext.getResources("/WEB-INF/**/tiles*.xml");
Collection<ApplicationResource> metaINFSet = applicationContext.getResources("classpath*:META-INF/**/tiles*.xml");

1.2 或者采用spring注入applicationContext.xml配置

<bean id="viewResolver"  class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
     <property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"/>
</bean> 
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"> 
     <property name="definitions" value="/WEB-INF/tiles-defs.xml"/>
</bean>

2.struts.xml配置

<result-types>
     <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<action name="windowGoMaintest" class="WindowChange" method="goMain">  
     <result name="success"  type="tiles">test.default</result>
</action>

3.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="template.default" template="/jsp/main/tmain.jsp">
    <put-attribute name="top" value="/jsp/main/top.jsp" />
    <put-attribute name="leftmenu" value="/jsp/main/leftmenu.jsp" />
    <put-attribute name="down" value="/jsp/main/down.jsp" />
  </definition>
  
  <definition name="test.default" extends="template.default">
	<put-attribute name="main" value="/jsp/main/tab.jsp" />
  </definition>
</tiles-definitions>

4.tmain.jsp配置

<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<base href="<%=basePath%>">
<style>
#container {
	margin-left: auto;
	margin-right: auto;
	width: 800px;
}

#top {
	float: left;
	width: 800px;
	height: 150px;
	background: red
}

#leftmenu {
	float: left;
	width: 150px;
	height: 400px;
	background: blue;
	word-wrap: break-word
}

#main {
	float: right;
	width: 642px;
	height: 400px;
	background: green
}

#down {
	float: left;
	width: 800px;
	height: 150px;
	background: yellow
}
</style>
<div id="container" style="height: auto">
	<div id="top">
		<tiles:insertAttribute name="top" />
	</div>

	<div id="leftmenu">
		<tiles:insertAttribute name="leftmenu" />
	</div>

	<div id="main" style="border: none">
		<tiles:insertAttribute name="main" />
	</div>

	<div id="down" style="height: 100px">
		<tiles:insertAttribute name="down" />
	</div>

</div>

注意:velocity-tools-2.0.jar需要高版本。
            struts2-tiles3-plugin-2.3.20.jar需要,struts2-tiles-plugin-2.3.20.jar版本不需要。
            guava-18.0.jar,compiler-0.8.17.jar必须有。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值