1

下面是我的资源。

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>

我有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。罐子,struts2-tiles-plugin-2.2.16.3.jar

和我的 web-inf/lib 文件夹中的一些其他 jars。

此外,下面是 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>

如果需要,我可以发布其他页面或屏幕截图。以下是我尝试运行此应用程序时遇到的错误。

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

答:在我的情况下,使用 tilesServelet 是有效的。检查下面的评论。

4

0 回答 0