Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Tiles issue - org.apache.tiles.jsp.taglib.InsertAttributeTag cannot be cast to javax.servlet.jsp.tagext.Tag

I tried to use tiles 2.2.2 with Struts 2. I included all the necessary jars(related to tiles, Struts2 and Struts2 tiles plugin) in the project.

commons-beanutils-1.8.0.jar
commons-collections-3.1.jar
commons-digester-2.0.jar
commons-fileupload-1.3.jar
commons-io-2.0.1.jar
commons-lang-2.4.jar
commons-lang3-3.1.jar
commons-logging-1.1.3.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.6.jar
slf4j-api-1.5.8.jar
slf4j-jdk14-1.5.8.jar
struts2-core-2.3.15.jar
struts2-tiles-plugin-2.3.15.jar
tiles-api-2.2.2.jar
tiles-compat-2.2.2.jar
tiles-core-2.2.2.jar
tiles-jsp-2.2.2.jar
tiles-servlet-2.2.2.jar
tiles-template-2.2.2.jar
xwork-core-2.3.15.jar

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="" />
    <put-attribute name="header" value="/Header.jsp" />
    <put-attribute name="menu" value="/Menu.jsp" />
    <put-attribute name="body" value="" />
    <put-attribute name="footer" value="/Footer.jsp" />
</definition>

<definition name="/welcome.tiles" extends="baseLayout">
    <put-attribute name="title" value="Welcome" />
    <put-attribute name="body" value="/Welcome.jsp" />
</definition>

<definition name="/employee.tiles" extends="baseLayout">
    <put-attribute name="title" value="Employee Form" />
    <put-attribute name="body" value="/Employee.jsp" />
</definition>
<definition name="/employee.success.tiles" extends="baseLayout">
    <put-attribute name="title" value="Employee Added" />
    <put-attribute name="body" value="/SuccessEmployee.jsp" />
</definition>

</tiles-definitions>

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/j2ee" xmlns:javaee="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/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_9" version="2.4">
  <javaee:display-name>Apache Tiles framework</javaee:display-name>
  <listener>
    <listener-class>
            org.apache.struts2.tiles.StrutsTilesListener
        </listener-class>
  </listener>
  <context-param>
    <param-name>tilesDefinitions</param-name>
    <param-value>/WEB-INF/tiles.xml</param-value>
  </context-param>
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
        </filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <welcome-file-list>
    <welcome-file>Login.jsp</welcome-file>
  </welcome-file-list>
</web-app>

Struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.enable.DynamicMethodInvocation"
        value="false" />
    <constant name="struts.devMode" value="false" />
    <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" 
            class="com.teg.tiles.LoginAction">
            <result name="success" type="tiles">/welcome.tiles</result>
            <result name="error">Login.jsp</result>
        </action>
        <action name="employee" 
            class="com.teg.tiles.EmployeeAction">
            <result name="success" type="tiles">/employee.success.tiles</result>
            <result name="input" type="tiles">/employee.tiles</result>
        </action>
        <action name="employee-form">
            <result name="success" type="tiles">/employee.tiles</result>
        </action>
    </package>
</struts>

When I try to run the project I got following exception.

java.lang.ClassCastException: org.apache.tiles.jsp.taglib.InsertAttributeTag cannot be cast to javax.servlet.jsp.tagext.Tag

Please help me out to resolve the issue.

like image 801
Manoj Kumar Avatar asked Feb 16 '23 18:02

Manoj Kumar


2 Answers

I was facing the exact same problem, the issue in my case was that JSP wasn't recompiling and Tomcat was re-using the same copy in the work directory. Cleaning the work directory and re-deploying solved the problem for me. Hope it helps!

like image 165
aygavras Avatar answered Apr 26 '23 16:04

aygavras


The issue has been resolved. Problem was DTD in tiles.xml. I changed the DTD to <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN" "http://tiles.apache.org/dtds/tiles-config_2_1.dtd"> and its working fine.

like image 26
Manoj Kumar Avatar answered Apr 26 '23 14:04

Manoj Kumar