Tiles Integration with Struts 2 Annotation

北城以北 提交于 2019-12-06 06:18:12

Try these :

  1. Use type="tiles" instead of type="TilesResult.class"

  2. Use your target tile definition, location="tiles-definition-name", instead of JSP page, location="/jsp/userLogin.jsp", in your result location

  3. Have following in your web.xml:

    <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>

  4. Have following in your struts.xml (If you are using annotations alone and no struts.xml, then you have to create a minimal one for this because there's no annotation available to define a custom result type)

    <struts> <constant name="struts.convention.default.parent.package" value="codeoftheday.blogspot.com"/> <package name="codeoftheday.blogspot.com" extends="struts-default"> <result-types> <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" /> </result-types> </package> </struts>

NOTE: I've written a detailed blog post here on this issue - Maven, Struts2 Annotations and Tiles Integration Example via Convention / Codebehind / Zero Config plugin using Eclipse IDE

  1. "org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG" this definition is not available with Strut 2.5.10.1
  2. I have used following jars in my project.
    • struts2-core-2.5.10.1
    • struts2-convention-plugin-2.5.10.1
    • struts2-tiles-plugin-2.5.10.1
    • javax.servlet-api-3.0.1

Please once you compare your web.xml with following code.

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    <init-param>
        <param-name>actionPackages</param-name>
        <param-value>com.demo.action</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<context-param>
    <!-- <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name> -->
    <param-name>org.apache.tiles.definition.DefinitionsFactory.DEFINITIONS_CONFIG</param-name>
    <param-value>/WEB-INF/config/tiles.xml</param-value>
</context-param>

<listener>
    <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!