java - Spring Web MVC Tiles 继承自相同的定义

标签 java spring spring-mvc tiles

我正在尝试使用图 block 创建一个 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>

当我访问此网址 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>

关于java - Spring Web MVC Tiles 继承自相同的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35474897/

相关文章:

java - 为 BigDecimal 使用正确的注释

java - 如何管理数组中的概率?

java - 来自 Java Spring 应用程序的 Windows 身份验证

java - 方法的可见性及其成本

java - Eclipse Maven 2 安装

spring - Spring ExceptionHandler 如何处理运行时异常

java - 将注释对象绑定(bind)到通知主体

java - 表达——表达中还有更多内容

java - import com.fasterxml.jackson.xml 无法解析

database - Spring 数据 : CrudRepository's save method and update