java apache 瓷砖 2 JSPException 包括路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12523523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
apache tiles 2 JSPException including path
提问by DanielAnenia
I create a java web application with using Hibernate framework. In WEB-INF, I created a new file: tiles-defs.xml, the below is the content in it:
我使用 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>
And in web.xml, I added some rows:
在 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>
In web pages folder, I created home folder to contain 2 jsp files: Index.jsp and IndexContent.jsp. Index.jsp:
在网页文件夹中,我创建了主文件夹以包含 2 个 jsp 文件:Index.jsp 和 IndexContent.jsp。索引.jsp:
<%@taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<tiles:insertDefinition name="Index"/>
And IndexContent.jsp:
和 IndexContent.jsp:
<div>Home</div>
After that, I created a controller package, and add new Home servlet:
之后,我创建了一个控制器包,并添加了新的 Home servlet:
String view = "home/Index.jsp";
RequestDispatcher rd = request.getRequestDispatcher(view);
rd.forward(request, response);
But when I ran, apache said: 'HTTP Status 404 - /Project2/' (Project2 is name of project). And then, I checked in Apache Tomcat Log, I found an error:
但是当我运行时,apache 说:'HTTP Status 404 - /Project2/'(Project2 是项目名称)。然后,我检查了Apache Tomcat Log,发现了一个错误:
'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'
'SEVERE: Servlet.service() for servlet [Home] in context with path [/Project2] 抛出异常 [org.apache.tiles.impl.CannotRenderException: JSPException 包括路径 '/layouts/layoutfront.jsp'.] 与根本原因javax.servlet.ServletException:找不到文件“/home/IndexContent.jsp”'
I have no ideas about this, I followed some tutorial how to working with tiles, but I'm still get stuck.
我对此没有任何想法,我遵循了一些如何使用瓷砖的教程,但我仍然被卡住了。
回答by DanielAnenia
This question was asked a year ago, but if anyone runs into the same issue here is how I fixed it. If the definition tag's name parameter and add-attribute tag's value parameter are the same I think it throws a stackoverflow error message. When I change those names, it worked fine for me.
这个问题是在一年前提出的,但如果有人遇到同样的问题,我是如何解决它的。如果定义标签的 name 参数和 add-attribute 标签的 value 参数相同,我认为它会引发 stackoverflow 错误消息。当我更改这些名称时,对我来说效果很好。
<definition name="Page" template="/share/layout.jsp"><put-attribute name="title" value="Page xyz" />