Spring Web MVC Tiles 扩展自同一定义

Spring Web MVC Tiles extends from the same definition

我正在尝试使用图块创建 Spring MVC 程序。

tiles.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
    <definition name="base.definition" template="/template/mainTemplate.jsp">
        <put-attribute name="title" value="Piranha"></put-attribute>
        <put-attribute name="header" value="/template/header.jsp"></put-attribute>
        <put-attribute name="content" value=""></put-attribute>
        <put-attribute name="footer" value="/template/footer.jsp"></put-attribute>
    </definition>

    <definition name="index" extends="base.defnition">
        <put-attribute name="content" value="/view/index.jsp"></put-attribute>
    </definition>
    <definition name="searched" extends="base.definition">
        <put-attribute name="content" value="/view/searched.jsp"></put-attribute>
    </definition>
</tiles-definitions>

当我访问此 url http://localhost:8080/myProject/search 时,出现此错误

错误

message Could not resolve view with name 'searched' in servlet with name 'welcome'

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

exception

javax.servlet.ServletException: Could not resolve view with name 'searched' in servlet with name 'welcome'
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1227)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

当我从 tiles.xml 中删除此代码时,它可以正常工作

<definition name="index" extends="base.defnition">
      <put-attribute name="content" value="/view/index.jsp"></put-attribute>
</definition>

tiles.xml 文件有什么问题?

知道了

这是一个简单的错字

你写了base.defnition

将其更改为 base.definition

下面更正的代码。

<definition name="index" extends="base.definition">
      <put-attribute name="content" value="/view/index.jsp"></put-attribute>
</definition>