Java, Spring, Apache Tiles error : Could not resolve view with name 'index' in servlet with name 'dispatcher'

前端 未结 6 1455
不知归路
不知归路 2021-01-13 06:57

I\'m new to Tiles and Spring MVC (I looked through several similar issues but found no solution for \'my problem\')

controller:

@Controller
public cl         


        
相关标签:
6条回答
  • 2021-01-13 07:07

    The problem is extremely simple. Replace your web.xml with

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
      <display-name>my-first-app</display-name>
    
    
      <servlet>
            <servlet-name>dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>dispatcher</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    </web-app>
    

    I also added a jstl dependency to the pom

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    

    After these changes, a request to localhost:8080/index correctly renders the appropriate response

    0 讨论(0)
  • 2021-01-13 07:08

    The problem lies in the project location.

    A combination of jetty, apache tiles and spring's view resolver does not work when there is a space in the location.

    For ex : a project location - D:\folder whitespace\your_project will throw the above error -Could not resolve view with name 'index' in servlet with name 'dispatcher'

    Solution - Please change your project location to a path with no space in it.

    0 讨论(0)
  • 2021-01-13 07:08

    There's probably a whitespace in your project's path:

    https://www.youtube.com/watch?v=JAYjZnykalg

    0 讨论(0)
  • 2021-01-13 07:13

    I've had the same issue . Try using correct version of DTD in tiles configuration file.

    https://stackoverflow.com/a/28854479

    Also in your tiles definition file general.xml use tile:insertAttribute instead of tile:addAttribute

    <tile:insertAttribute name="body"/>
         <br />
    <tile:insertAttribute name="footer" />
    
    0 讨论(0)
  • 2021-01-13 07:15

    Try to change the return value of IndexController.index() from "/WEB-INF/jsp/index.jsp" to "index". This works for me:

    @RequestMapping("/index")
    public String index() {
        return "index";
    }
    
    0 讨论(0)
  • 2021-01-13 07:18

    I've had the same issue today. I am also new at Spring so I didn't know where to start. After a long day I managed to find the answer:

    My default.xml file was wrong. I had done some manual refactoring and that caused all the trouble. This is an example of what was wrong:

    <definition name="tos.base" template="/WEB-INF/templates/default.jsp">
    <put-attribute name="includes" value="" ></put-attribute>
    <put-attribute name="title" value="Title" ></put-attribute>
    <put-attribute name="header" value="/WEB-INF/tiles/header.jsp"></put-attribute>
    <put-attribute name="content" value="/WEB-INF/tiles/content.jsp"></put-attribute>
    <put-attribute name="footer" value="/WEB-INF/tiles/footer.jsp"></put-attribute>
    </definition>
    
    <definition name="home" extends="tos.base">
    <put-attribute name="title" value="Homepage" ></put-attribute>
    <put-attribute name="content" value="/WEB-INF/tiles/home.jsp"></put-attribute>
    </definition>
    
    <definition name="current" extends="to.base">
    <put-attribute name="title" value="Current" ></put-attribute>
    <put-attribute name="content" value="/WEB-INF/tiles/current.jsp"></put-attribute>
    </definition>
    

    As you can see I had the wrong value in the last definition "extends" value. I discovered this downgrading from tiles3.TilesViewResolver to tiles2.TilesViewResolver and that provided a more helpful error message.

    0 讨论(0)
提交回复
热议问题