java

位置:IT落伍者 >> java >> 浏览文章

struts2整合tiles及配置


发布日期:2019年02月13日
 
struts2整合tiles及配置

基本包(个)

monsloggingjar

monsfileuploadjar

ognljar

strutscorejar

xworkjar

freemarkerjar

整合tiles必须包(个)

strutstilespluginjar

tilesapijar

tilescorejar

tilesjspjar

monsdigesterjar

monscollectionsjar

monsbeanutilsjar

把tilesjspjar包下的tilesjsptld 拷贝到WEBINF下WEBINF/tilesjsptld

创建tilesxml 放在WEBINF下WEBINF/tilesxml 如下:

<?xml version= encoding=UTF?>

<!DOCTYPE tilesdefinitions PUBLIC //Apache Software Foundation//DTD Tiles Configuration //EN /dtds/tilesconfig__dtd>

<tilesdefinitions>

<definition name=xixihaha template=layoutjsp>

<putattribute name=header value=headjsp />

<putattribute name=sidebar value=sidebarjsp />

<putattribute name=contant value=contantjsp />

<putattribute name=footer value=footjsp />

</definition>

</tilesdefinitions>

在webxml添加如下:

<contextparam>

<paramname>orgapachetilesCONTAINER_FACTORY</paramname>

<paramvalue>orgapachestrutstilesStrutsTilesContainerFactory</paramvalue>

</contextparam>

<contextparam>

<paramname>orgapachetilesimplBasicTilesContainerDEFINITIONS_CONFIG</paramname>

<paramvalue>/WEBINF/tilesxml</paramvalue>

</contextparam>

<listener>

<listenerclass>orgapachestrutstilesStrutsTilesListener</listenerclass>

</listener>

修改strutsxml

<!DOCTYPE struts PUBLIC

//Apache Software Foundation//DTD Struts Configuration //EN

/dtds/strutsdtd>

<struts>

<package name=default extends=tilesdefault >

<action name=XXAction class=comXXAction>

<result name=success type=tiles >xixihaha </result>

</action>

</package>

</struts>

创建layoutjsp注意存放路径要和tilesxml一致

<%@ taglib uri=/WEBINF/tilesjsptld prefix=tiles%>

<table>

<tr><td><tiles:insertAttribute name=header></tiles:insertAttribute></td></tr>

<tr><td><tiles:insertAttribute name=sidebar></tiles:insertAttribute></td></tr>

<tr><td><tiles:insertAttribute name=contant></tiles:insertAttribute></td></tr>

<tr><td><tiles:insertAttribute name=footer></tiles:insertAttribute></td></tr>

</table>

创建headjspsiderbarjspcontantjspfooterjsp

测试创建indexjsp

<form action=XXActiondo method=post>

<input type=submit/>

</form>

上一篇:Spring AOP的一些概念

下一篇:Hibernate O/R映射三大基本定则