1

Below are my resources.

a) web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>ezviewocean</display-name>
  <description>EZ-View Ocean</description>
        <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>
    <filter>
        <filter-name>struts-prepare</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts-prepare</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>
</web-app>

b) tiles.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="baseLayout" template="/baseLayout.jsp">
      <put-attribute name="title"  value="Template"/>
      <put-attribute name="header" value="/header.jsp"/>
      <put-attribute name="leftmenu"   value="/leftmenu.jsp"/>
      <put-attribute name="body"   value="/body.jsp"/>
      <put-attribute name="footer"   value="/footer.jsp"/>
   </definition>

   <definition name="view" extends="baseLayout">
      <put-attribute name="title"  value="View"/>
      <put-attribute name="body"   value="/viewBody.jsp"/>      
   </definition>

   <definition name="assign" extends="baseLayout">
      <put-attribute name="title"  value="Assign"/>
      <put-attribute name="body"   value="/assignBody.jsp"/>      
   </definition>

</tiles-definitions>

c) struts.xml

    <?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true"/>
    <constant name="struts.custom.i18n.resources" value="ApplicationResources"/>


    <package name="default" extends="struts-default" namespace="/">
        <result-types>
         <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
        </result-types>
        <action name="login" method="execute"
            class="com.schenker.ocean.actions.LoginAction">
            <result name="success" type="tiles">baseLayout</result>
            <result name="input">/login.jsp</result>
            <result name="fail">/login.jsp</result>
        </action>
    </package>
</struts>

I have tiles-api-2.2.2.jar, tiles-core-2.2.2.jar, tiles-jsp-2.2.2.jar, tiles-servlet-2.2.2.jar, tiles-compact-2.2.2.jar, struts2-tiles-plugin-2.2.16.3.jar

and some other jars in my web-inf/lib folder.

Also, below is the baseLayout.jsp

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><tiles:insertAttribute name="title" ignore="true" />
</title>
</head>

<body>
   <tiles:insertAttribute name="header" /><br/>
   <hr/>
   <tiles:insertAttribute name="leftMenu" /><br/>
   <hr/>
   <tiles:insertAttribute name="body" /><br/>
   <hr/>
   <tiles:insertAttribute name="footer" /><br/>
</body>
</html>

I can post other pages or screenshots if needed. Below is the error i get when i try to run this application.

Struts has detected an unhandled exception:

Messages:   
org.apache.tiles.template.AttributeResolver
org/apache/tiles/template/AttributeResolver
java.lang.NoClassDefFoundError: org/apache/tiles/template/AttributeResolver
File:   org/apache/catalina/loader/WebappClassLoader.java
Line number:    1,680

Answer: in my case using the tilesServelet worked. Check the comments below.

DJR
  • 454
  • 2
  • 8
  • 29
  • 1
    Still w/o `TilesServlet` in web.xml. – Aleksandr M Oct 01 '14 at 21:08
  • @AleksandrM none of the tutorials i see online mention the tiles servlet. could you be more explicit please.. struts 2 prepareandexecute filter should invoke the servlet when u use struts 2 , tiles 2.2 and struts-tiles-plugin.. this is what i came to know from the online guides. could u point me to a resource where the tiles servlet configuration is mentioned please. – DJR Oct 02 '14 at 13:26
  • 1
    I've already said to you that `StrutsPrepareAndExecuteFilter` knows nothing about tiles. The `StrutsTilesListener` knows, but it is better to check with tiles servlet instead of S2 listener. As for the link: http://tiles.apache.org/2.1/framework/tutorial/configuration.html – Aleksandr M Oct 02 '14 at 13:43
  • As for the `NoClassDefFoundError` exception, try with tiles version that comes with `struts2-tiles-plugin`. – Aleksandr M Oct 02 '14 at 13:49
  • @AleksandrM I tried to use TilesServlet as u mentioned. I get a different error now when the BasicTilesContainerClass executes render(attributeContext.getTemplateAttribute(), request); statement. – DJR Oct 02 '14 at 14:26
  • @AleksandrM I also observed that when i mention just baseLayout as the result in Struts.xml, it throws an exception saying /baseLayout.jsp cannot be found. I even tried changing it to /baseLayout and baselayout.tiles. – DJR Oct 02 '14 at 14:30
  • 1
    The problem is not with the result configuration (it should be `baseLayout`), but because tiles cannot find your jsp. So where is `/baseLayout.jsp`? – Aleksandr M Oct 02 '14 at 14:34
  • @AleksandrM baseLayout.jsp is in Webcontent/ folder. They are already created so i tried to correct the path by declaring the path to baseLayout.jsp as "baseLayout.jsp", /baseLayout.jsp, "/WebContent/baseLayout.jsp" .. none of the three iterations worked. But when i tried "baseLayout.jsp" i atleast didnt get an exception. I got a page with the names of the JSPs in the definition listed. – DJR Oct 02 '14 at 14:53
  • Now your other jsp are not resolved. – Aleksandr M Oct 02 '14 at 15:00
  • 2
    @AleksandrM Thanks man. Greatly appreciate your patience and help. I still have some problems but i will resolve them myself.. u helped me clear the main one. – DJR Oct 02 '14 at 16:14
  • You are welcome. BTW it is better to keep jsp-s under `WEB-INF` folder, in that way they cannot be accessed directly. – Aleksandr M Oct 02 '14 at 20:41
  • @AleksandrM are you online today? can we have a chat? – DJR Oct 03 '14 at 19:49

0 Answers0