gpt4 book ai didi

java - 没有 Struts 和 Maven 的 JSP Tiles

转载 作者:太空宇宙 更新时间:2023-11-04 07:40:20 25 4
gpt4 key购买 nike

您可以在屏幕截图中看到异常和配置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>

tiles-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

exception enter image description here

最佳答案

关于Configuring Tiles in your web application ,它提到如下:-

1 必需的库

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

2 启动 Tiles 引擎

通过在 web.xml 文件中使用适当的监听器来加载图 block 容器。

<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,我们应该配置监听器和/或Tiles Dispatch Servlet来启动Tiles引擎。请通过以下链接查看更多信息:-

  1. Apache Tiles: Tutorial
  2. Apache Tiles: Getting Start
  3. Apache Tiles: Configuration Reference

希望这会有所帮助。

关于java - 没有 Struts 和 Maven 的 JSP Tiles,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16156835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com