tiles求教,求大侠指导

二号铺 发布于 2013/03/20 19:51
阅读 354
收藏 0
最近想接触一下tiles框架,因为这种页面布局机制肯定会在以后的项目中用到,但是一下午下来真的没有成功,在网上差了很多的资料,按照他们说的做了,但是没有成功。

我是想让struts2和tiles结合起来,我总结出来有这么几个地方需要注意:
1、jar包  这个是一个问题,我在网上看的例子是用的tiles 2.0.3,但是我用2.2的就不行,这个不会向前兼容?真头痛!
2、在web.xml中加入
<context-param>
       <param-name>org.apache.tiles.CONTAINER_FACTORY</param-name>
       <param-value>
           org.apache.struts2.tiles.StrutsTilesContainerFactory
        </param-value>
    </context-param>   
    <context-param>
       <param-name>
         org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
       </param-name>
       <param-value>/WEB-INF/tiles.xml</param-value>
    </context-param>
    <listener>
       <listener-class>
           org.apache.struts2.tiles.StrutsTilesListener
       </listener-class>
    </listener>
3、设置struts.xml 里的action
    <action name="go" class="com.action.MyAction">
           <result name="success" type="tiles">myapp.homepage</result>
    </action>
4、配置tiles.xml文件
   我用的是网上现成的例子
< ?xml version="1.0" encoding="GB2312" ?>
< !DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
       "http://jakarta.apache.org/struts/dtds/tiles-config.dtd">
  <tiles-definitions>
    <definition name="myapp.homepage" template="layout.jsp">
       <put name="title" value="Tiles tutorial homepage" />
       <put name="header" value="/tiles/header.jsp" />
       <put name="menu" value="/tiles/menu.jsp" />
       <put name="body" value="/tiles/cBody.jsp" />
       <put name="footer" value="/tiles/footer.jsp" />
    </definition>
   </tiles-definitions>
5、配置 layout.jsp header.jsp menu.jsp等。
6、最后启动tomcat时始终不成功!老是报错:

Exception sending context initialized event to listener instance of class org.apache.struts2.tiles.StrutsTilesListener
java.lang.NullPointerException
at org.apache.tiles.context.ChainedTilesContextFactory.createApplicationContext(ChainedTilesContextFactory.java:107)
at org.apache.struts2.tiles.StrutsTilesContainerFactory$StrutsTilesContextFactory.createApplicationContext(StrutsTilesContainerFactory.java:98)
at org.apache.struts2.tiles.StrutsTilesContainerFactory.initializeContainer(StrutsTilesContainerFactory.java:68)
at org.apache.tiles.factory.TilesContainerFactory.createTilesContainer(TilesContainerFactory.java:199)
at org.apache.tiles.factory.TilesContainerFactory.createContainer(TilesContainerFactory.java:164)
at org.apache.tiles.listener.TilesListener.createContainer(TilesListener.java:91)
 
加载中
返回顶部
顶部