1

您可以在屏幕截图异常和配置tiles-defs.xml 的web.xml 文件中看到。

但我不明白瓷砖有什么问题?它是错误的 web.xml 瓷砖配置吗?感谢您的关注。

web.xml

<context-param>
    <param-name>
        org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
    <param-value>/WEB-INF/tiles-defs.xml</param-value>
</context-param>

瓷砖-defs.xml

 <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE tiles-definitions PUBLIC
   "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
   "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
  <tiles-definitions>
  <definition name="homepage" template="/view/layouts/home.jsp">
   <put-attribute name="cssPaths" value="/view/tiles/common/cssPaths.jsp"/>
   <put-attribute name="metas" value="/view/tiles/common/metas.jsp"/>
   <put-attribute name="header" value="/view/tiles/common/header.jsp"/>
   <put-attribute name="footer" value="/view/tiles/common/footer.jsp"/>
   <put-attribute name="sliders" value="/view/tiles/common/sliders.jsp"/>
   <put-attribute name="featureditems" value="/view/tiles/common/featureditems.jsp"/>
   <put-attribute name="scripts" value="/view/tiles/common/scripts.jsp"/>
   <put-attribute name="brands" value="/view/tiles/common/brands.jsp"/>
  </definition>
 </tiles-definitions>

pom.xml

     <project xmlns="http://maven.apache.org/POM/4.0.0"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
             <modelVersion>4.0.0</modelVersion>
             <groupId>com</groupId>
            <artifactId>ecommerce</artifactId>
           <packaging>war</packaging>
            <version>0.0.1-SNAPSHOT</version>
           <name>ecommerce Maven Webapp</name>
            <url>http://maven.apache.org</url>
       <dependencies>
        <dependency>
          <groupId>junit</groupId>
           <artifactId>junit</artifactId>
           <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
        <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>taglibs</groupId>
      <artifactId>standard</artifactId>
      <version>1.1.2</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.24</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-extras</artifactId>
        <version>3.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-api</artifactId>
        <version>3.0.1</version>
    </dependency>    
  </dependencies>
  <build>
    <finalName>ecommerce</finalName>
  </build>
</project>

例外

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 14

11: <title>Urunler</title>
12: </head>
13: <body>
14:     <tiles:insertDefinition name="homepage"/>
15: </body>
16: </html>


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause

java.lang.NullPointerException
    org.apache.tiles.access.TilesAccess.getContainer(TilesAccess.java:124)
    org.apache.tiles.access.TilesAccess.getContainer(TilesAccess.java:107)
    org.apache.tiles.access.TilesAccess.getCurrentContainer(TilesAccess.java:174)
    org.apache.tiles.template.InsertDefinitionModel.execute(InsertDefinitionModel.java:95)
    org.apache.tiles.jsp.taglib.InsertDefinitionTag.doTag(InsertDefinitionTag.java:254)
    org.apache.jsp.index_jsp._jspx_meth_tiles_005finsertDefinition_005f0(index_jsp.java:93)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:66)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.

Apache Tomcat/6.0.29

例外 在此处输入图像描述

4

1 回答 1

1

关于在您的 Web 应用程序中配置 Tiles,它提到如下: -

1 所需库

<dependency>
    <groupId>org.apache.tiles</groupId>
    <artefactId>tiles-extras</artefactId>
    <version>3.0.1</version>
</dependency>

2 启动瓷砖引擎

通过在 web.xml 文件中使用适当的侦听器来加载切片容器。

<listener>
    <listener-class>
        org.apache.tiles.extras.complete.CompleteAutoloadTilesListener
    </listener-class>
</listener>

<servlet>
    <servlet-name>Tiles Dispatch Servlet</servlet-name>
    <servlet-class>org.apache.tiles.web.util.TilesDispatchServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Tiles Dispatch Servlet</servlet-name>
    <url-pattern>*.tiles</url-pattern>
</servlet-mapping>

AFAIU,我们应该配置listener和/或Tiles Dispatch Servlet来启动 Tiles 引擎。请在以下链接中查看更多信息:-

  1. Apache Tiles:教程
  2. Apache Tiles:入门
  3. Apache Tiles:配置参考

我希望这可能会有所帮助。

于 2013-04-23T02:17:28.910 回答