我尝试使用带有Struts 2的tile 2.2.2。我在项目中包含了所有必需的jar(与tile,Struts2和Struts2 tiles插件相关)。
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>
当我尝试运行该项目时,我遇到了异常。
java.lang.ClassCastException:org.apache.tiles.jsp.taglib.InsertAttributeTag无法强制转换为javax.servlet.jsp.tagext.Tag
请帮我解决这个问题。
答案 0 :(得分:5)
我遇到了完全相同的问题,我的问题是JSP没有重新编译,Tomcat在work
目录中重复使用相同的副本。清理work
目录并重新部署为我解决了问题。希望它有所帮助!
答案 1 :(得分:3)
问题已经解决。问题是tiles.xml中的DTD。我将DTD更改为<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN" "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
并且工作正常。
答案 2 :(得分:0)
Tiles 2.2.2 insertAttribute
不再接受诸如&#39; ignore =&#34; true&#34;之类的论点。删除参数或使用insertTemplate:http://tiles.apache.org/2.2/framework/tiles-jsp/tlddoc/tiles/insertTemplate.html