gpt4 book ai didi

java - apache tiles 2 JSPException 包括路径

转载 作者:行者123 更新时间:2023-11-28 21:54:32 26 4
gpt4 key购买 nike

我使用 Hibernate 框架创建了一个 Java Web 应用程序。在WEB-INF中,我新建了一个文件: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="Page" template="/share/layout.jsp">
<put-attribute name="title" value="Page" />
<put-attribute name="header" value="/share/header.jsp" />
</definition>
<definition name="Index" extends="Page">
<put-attribute name="title" value="Vnmart" />
<put-attribute name="main" value="/home/IndexContent.jsp"/>
</definition>
</tiles-definitions>

在 web.xml 中,我添加了一些行:

<context-param>
<param-name>
org.apache.tiles.definition.DefinitionsFactory.DEFINITIONS_CONFIG
</param-name>
<param-value>
/WEB-INF/tiles-defs.xml
</param-value>
</context-param>
<listener>
<listener-class>org.apache.tiles.web.startup.TilesListener</listener-class>
</listener>

在网页文件夹中,我创建了主文件夹以包含 2 个 jsp 文件:Index.jsp 和 IndexContent.jsp。索引.jsp:

<%@taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<tiles:insertDefinition name="Index"/>

和 IndexContent.jsp:

<div>Home</div>

之后,我创建了一个 Controller 包,并添加了新的 Home servlet:

String view = "home/Index.jsp";
RequestDispatcher rd = request.getRequestDispatcher(view);
rd.forward(request, response);

但是当我运行时,apache 说:'HTTP Status 404 -/Project2/'(Project2 是项目名称)。然后,我检查了 Apache Tomcat 日志,发现错误:

'SEVERE: Servlet.service() for servlet [Home] in context with path [/Project2] threw exception [org.apache.tiles.impl.CannotRenderException: JSPException including path '/layouts/layoutfront.jsp'.] with root cause javax.servlet.ServletException: File "/home/IndexContent.jsp" not found'

我对此一无所知,我遵循了一些如何使用图 block 的教程,但我仍然卡住了。

最佳答案

这个问题是一年前提出的,但如果有人遇到同样的问题,我是如何解决的。如果定义标签的名称参数和添加属性标签的值参数相同,我认为它会抛出一条 stackoverflow 错误消息。当我更改这些名称时,对我来说效果很好。

<definition name="Page" template="/share/layout.jsp"><put-attribute name="title" value="Page xyz" />

关于java - apache tiles 2 JSPException 包括路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12523523/

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