有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaSpringWebMVC互动程序从相同的定义扩展而来

我正在尝试使用tiles创建一个springmvc程序

瓷砖。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>

当我访问这个urlhttp://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)

当我从平铺中删除此代码时。xml,那么它就可以正常工作了

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

tiles.xml文件有什么问题


共 (1) 个答案

  1. # 1 楼答案

    明白了

    这是一个简单的打字错误

    你写了base.defnition

    将其更改为base.definition

    下面是更正后的代码

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